/* ═══ Panel Overlay ══════════════════════════════════════════════════════════ */

.panel-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.panel {
  width: 560px;
  max-height: 90vh;
  background: var(--surface-container-low);
  display: flex;
  flex-direction: column;
  box-shadow: var(--panel-glow);
  outline: 1px solid var(--panel-outline);
  border-radius: 12px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  flex-shrink: 0;
}

.panel-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--on-surface);
}

.panel-doc-id {
  font-size: 11px;
  font-family: monospace;
  color: var(--on-surface-muted);
  background: var(--surface-container-high);
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: auto;
  margin-right: 8px;
}

.panel-doc-id:hover {
  color: var(--on-surface);
  background: var(--surface-container-highest);
}

.panel-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--on-surface-muted);
  padding: 4px 6px;
  border-radius: var(--radius-md);
  transition: background 0.12s, color 0.12s;
}
.panel-close:hover {
  background: var(--surface-container);
  color: var(--on-surface);
}

.panel-form {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-error {
  background: var(--error-container);
  color: var(--on-error-container);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
}

/* ═══ Fields ═════════════════════════════════════════════════════════════════ */

.field-row { display: flex; flex-direction: column; }
.field-row--title { flex-direction: row; align-items: center; }
.field-row--title input { font-size: 16px; font-weight: 500; flex: 1; }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--on-surface-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-label--wide { grid-column: span 2; }

.field-alerts-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--on-surface-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.12s, color 0.12s;
}

.field-alerts-btn:hover {
  opacity: 1;
  color: var(--on-surface);
}

.field-alerts-btn--off {
  color: var(--on-surface-muted);
  opacity: 0.7;
}

.field-input,
.field-select {
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--surface-container-high);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 6px 8px;
  color: var(--on-surface);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 7px 28px 7px 10px;
  /* SVG chevron stroke #84746a matches --on-surface-muted; can't use CSS vars in data URIs */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2384746a' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

.field-input:focus,
.field-select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--primary-muted) 40%, transparent);
  box-shadow: 0 0 0 3px var(--surface-tint);
}

/* ── Priority pill group ─────────────────────────────────────────────────── */

.pill-group {
  display: flex;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--outline-variant);
}

.pill {
  flex: 1;
  padding: 5px 0;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--on-surface-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.pill:not(:last-child) {
  border-right: 1px solid var(--outline-variant);
}

.pill:hover {
  background: var(--surface-container-high);
  color: var(--on-surface-variant);
}

.pill--active {
  font-weight: 600;
}

.pill--priority-none.pill--active {
  background: var(--surface-container-high);
  color: var(--on-surface);
}

.pill--priority-low.pill--active {
  background: color-mix(in srgb, var(--priority-low) 15%, transparent);
  color: var(--priority-low);
}

.pill--priority-medium.pill--active {
  background: color-mix(in srgb, var(--priority-medium) 15%, transparent);
  color: var(--priority-medium);
}

.pill--priority-high.pill--active {
  background: color-mix(in srgb, var(--priority-high) 15%, transparent);
  color: var(--priority-high);
}

.field-date-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.field-date-wrapper .field-date {
  flex: 1;
}

.field-date-clear {
  position: absolute;
  right: 30px;
  background: none;
  border: none;
  color: var(--on-surface-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0.5;
  transition: opacity 0.12s, color 0.12s;
}

.field-date-clear:hover {
  opacity: 1;
  color: var(--on-surface);
}

.field-date {
  background: transparent;
  border: 1px solid var(--outline-variant);
  border-radius: 8px;
  padding: 7px 10px;
  /* color-scheme set dynamically by theme — see [data-theme] selectors in tokens.css */
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field-date:focus {
  border-color: var(--primary-muted);
  box-shadow: var(--date-focus-shadow);
}
.field-date::-webkit-calendar-picker-indicator {
  filter: invert(0.6) sepia(0.5) saturate(3) hue-rotate(350deg) brightness(1.1);
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.field-date::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

.field-title {
  font-size: 16px !important;
  font-weight: 600;
  padding: 6px 10px !important;
  background: transparent;
}

/* ═══ Markdown Editor ════════════════════════════════════════════════════════ */

.md-editor { display: flex; flex-direction: column; }

.md-editor-input {
  font-family: 'SFMono-Regular', 'Cascadia Code', Consolas, monospace;
  font-size: 13px;
  background: var(--surface-container-high);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px;
  color: var(--on-surface);
  resize: none;
  min-height: 220px;
  max-height: 220px;
  overflow-y: auto;
  line-height: 1.6;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.md-editor-input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--primary-muted) 40%, transparent);
  box-shadow: 0 0 0 3px var(--surface-tint);
}

.md-editor-preview {
  background: var(--surface-container-high);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px;
  min-height: 220px;
  max-height: 220px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
  color: var(--on-surface);
  cursor: text;
  transition: border-color 0.15s;
}

.md-editor-preview:hover {
  border-color: color-mix(in srgb, var(--outline) 30%, transparent);
}

.md-editor-preview--empty {
  color: var(--on-surface-muted);
  font-style: italic;
}

/* Markdown rendered content */
.md-editor-preview h1,
.md-editor-preview h2,
.md-editor-preview h3 {
  margin: 0.6em 0 0.3em;
  line-height: 1.3;
}
.md-editor-preview h1 { font-size: 1.2em; }
.md-editor-preview h2 { font-size: 1.1em; }
.md-editor-preview h3 { font-size: 1em; }
.md-editor-preview p { margin: 0 0 0.5em; }
.md-editor-preview p:last-child { margin-bottom: 0; }
.md-editor-preview ul,
.md-editor-preview ol { margin: 0 0 0.5em; padding-left: 1.4em; }
.md-editor-preview li { margin-bottom: 0.15em; }
.md-editor-preview code {
  font-family: 'SFMono-Regular', 'Cascadia Code', Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface-container);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
}
.md-editor-preview pre {
  background: var(--surface-container);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  overflow-x: auto;
  margin: 0 0 0.5em;
}
.md-editor-preview pre code {
  background: none;
  padding: 0;
}
.md-editor-preview blockquote {
  margin: 0 0 0.5em;
  padding-left: 10px;
  border-left: 3px solid var(--outline-variant);
  color: var(--on-surface-variant);
}
.md-editor-preview a {
  color: var(--primary-muted);
  text-decoration: underline;
}
.md-editor-preview hr {
  border: none;
  border-top: 1px solid var(--outline-variant);
  margin: 0.6em 0;
}

.md-editor-hint {
  font-size: 11px;
  color: var(--on-surface-muted);
  opacity: 0;
  margin-top: 4px;
  text-align: right;
  padding-right: 2px;
  letter-spacing: 0.01em;
  transition: opacity 0.2s;
}

.md-editor:hover .md-editor-hint,
.md-editor:focus-within .md-editor-hint {
  opacity: 0.5;
}

/* ═══ Sub-items ══════════════════════════════════════════════════════════════ */

.panel-subitems {
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.panel-subitems-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--on-surface-muted);
  padding: 0 2px 4px;
}

.panel-subitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-md);
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--on-surface);
  transition: background 0.1s;
}
.panel-subitem:hover { background: var(--surface-container); }

.panel-subitem-status { font-size: 12px; color: var(--on-surface-muted); flex-shrink: 0; }
.panel-subitem-title { flex: 1; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-subitem-count {
  font-size: 11px;
  color: var(--on-surface-muted);
  background: var(--surface-container);
  border-radius: var(--radius-full);
  padding: 0 6px;
  flex-shrink: 0;
}

/* ═══ Archive Modal ══════════════════════════════════════════════════════════ */

.archive-modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg-light);
  backdrop-filter: blur(var(--frosted-blur));
  -webkit-backdrop-filter: blur(var(--frosted-blur));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.archive-modal {
  background: var(--surface-container-highest);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  width: 320px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.archive-modal-title {
  font-size: 14px;
  font-weight: 600;
}

.archive-modal-desc {
  font-size: 13px;
  color: var(--on-surface-variant);
}

.archive-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

/* Archive confirmation (inline panel) */
.panel-archive-confirm {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--error);
}

.panel-archive-confirm-btns {
  display: flex;
  gap: 6px;
}

/* ═══ Panel Actions ══════════════════════════════════════════════════════════ */

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  margin-top: auto;
}

.panel-actions-right { display: flex; gap: 8px; }

/* ═══ Buttons ════════════════════════════════════════════════════════════════ */

.btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: background 0.12s, opacity 0.12s, box-shadow 0.12s;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary {
  background: var(--primary-muted);
  color: var(--on-primary);
  font-weight: 600;
  opacity: 0.7;
}
.btn--primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn--ghost {
  background: none;
  border: 1px solid color-mix(in srgb, var(--outline) 30%, transparent);
  color: var(--on-surface-variant);
}
.btn--ghost:hover {
  background: var(--surface-container);
  color: var(--on-surface);
}

.btn--danger {
  background: none;
  color: var(--error);
  border: 1px solid color-mix(in srgb, var(--error) 30%, transparent);
}
.btn--danger:hover {
  background: var(--error-container);
}
.btn--sm { font-size: 12px; padding: 4px 10px; }
