/* ══════════════════════════════════════════════════════
   Life App — Reusable Components
   ══════════════════════════════════════════════════════ */

/* ── App Layout ───────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  transition: transform var(--duration-normal) var(--ease-out);
}

.sidebar-header {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  background: var(--gradient-accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  box-shadow: var(--shadow-glow);
}

.sidebar-logo-text {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-3) var(--space-3);
  overflow-y: auto;
}

.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--space-4) var(--space-3) var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: all var(--duration-fast) var(--ease-out);
  cursor: pointer;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item-icon {
  font-size: var(--text-lg);
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  padding: 0 5px;
}

.sidebar-footer {
  padding: var(--space-3) var(--space-3);
  border-top: 1px solid var(--border-subtle);
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.page-container {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: var(--space-12) var(--space-10);
}

.page-header {
  margin-bottom: var(--space-8);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.03em;
  line-height: var(--leading-tight);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

/* ── Card ─────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: all var(--duration-normal) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-glow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.card-section + .card-section {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
}

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  height: 36px;
}

.btn-primary {
  background: var(--gradient-accent);
  color: white;
  box-shadow: var(--shadow-sm), var(--shadow-glow);
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), var(--shadow-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
}

.btn-ghost {
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger-subtle);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-sm {
  height: 30px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}

.btn-lg {
  height: 44px;
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-icon.btn-sm {
  width: 30px;
  height: 30px;
}

/* ── Inputs ───────────────────────────────────────── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.input-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: all var(--duration-fast) var(--ease-out);
}

/* <select>'s closed state picks up the rules above, but the dropdown
   list itself is otherwise drawn with the browser's own (light) native
   colors — in dark mode that left every dropdown showing light text on
   a light popup, unreadable. Chrome/Firefox/Edge all honor colors set
   directly on <option>, so give every select's options the same theme
   colors as the field itself. */
select.input option,
.editorial-select option {
  background: var(--bg-base);
  color: var(--text-primary);
}

/* ── Rich text field (bold/italic/underline/list toolbar) ─────────── */
.rich-text-field {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.rich-text-toolbar {
  display: flex;
  gap: 2px;
  padding: var(--space-1);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.rich-text-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}

.rich-text-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.rich-text-editable {
  width: 100%;
  min-height: 220px;
  padding: var(--space-3);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 16px;
  line-height: var(--leading-relaxed);
  font-family: var(--font-sans);
  overflow-y: auto;
}

.rich-text-editable:focus {
  outline: none;
}

.rich-text-editable:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
}

.rich-text-editable ul {
  /* reset.css strips list-style from every ul/ol app-wide (most lists in
     this app draw their own markers), which left this one with just the
     indent and no visible bullet — put it back only here. */
  list-style: disc;
  padding-left: 1.4em;
  margin: 0.4em 0;
}

/* Textareas sharing .input (content/body fields across notes, tasks,
   journal, quotes, books...) were being squashed to the same fixed 40px
   as single-line inputs, ignoring their `rows` attribute entirely. */
textarea.input {
  height: auto;
  min-height: 220px;
  padding: var(--space-3);
  line-height: var(--leading-relaxed);
  resize: vertical;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.input::placeholder {
  color: var(--text-muted);
}

.input-textarea {
  height: auto;
  min-height: 80px;
  padding: var(--space-3);
  resize: vertical;
}

/* ── Chips / Tags ─────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1;
  height: 22px;
}

.chip-accent {
  background: var(--accent-subtle);
  color: var(--accent);
}

.chip-success {
  background: var(--success-subtle);
  color: var(--success);
}

.chip-warning {
  background: var(--warning-subtle);
  color: var(--warning);
}

.chip-danger {
  background: var(--danger-subtle);
  color: var(--danger);
}

.chip-domain {
  border: 1px solid currentColor;
  background: transparent;
  opacity: 0.85;
}

/* ── Checkbox ─────────────────────────────────────── */
.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast) var(--ease-spring);
  flex-shrink: 0;
}

.checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
  animation: checkPop 0.3s var(--ease-spring);
}

.checkbox.checked::after {
  content: '✓';
  color: white;
  font-size: 12px;
  font-weight: bold;
}

@keyframes checkPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ── Star (Top 3) ─────────────────────────────────── */
.star-btn {
  font-size: var(--text-lg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-spring);
  padding: var(--space-1);
}

.star-btn:hover {
  color: var(--warning);
  transform: scale(1.15);
}

.star-btn.active {
  color: var(--warning);
  animation: starPop 0.4s var(--ease-spring);
}

@keyframes starPop {
  0% { transform: scale(1); }
  30% { transform: scale(1.4) rotate(-10deg); }
  60% { transform: scale(0.9) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* ── Modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-normal) var(--ease-out);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  transform: translateY(-20px) scale(0.97);
  transition: transform var(--duration-normal) var(--ease-spring);
  overflow: hidden;
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: var(--space-5) var(--space-5) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.modal-body {
  padding: var(--space-5);
}

.modal-footer {
  padding: 0 var(--space-5) var(--space-5);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ── Toast ────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-3);
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  min-width: 280px;
  animation: toastIn var(--duration-normal) var(--ease-spring);
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--info); }

.toast-leaving {
  animation: toastOut var(--duration-fast) var(--ease-out) forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to   { opacity: 0; transform: translateX(40px) scale(0.95); }
}

/* ── FABs (Floating Action Buttons) — capture ─────── */
.capture-fabs {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-fab);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.fab {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  transition: all var(--duration-fast) var(--ease-spring);
}

.fab:hover {
  transform: scale(1.08);
}

.fab:active {
  transform: scale(0.95);
}

.fab-pencil {
  width: 44px;
  height: 44px;
  font-size: 18px;
  background: var(--accent);
}

.fab-mic {
  background: var(--danger);
}

.fab-mic.recording {
  animation: fabMicPulse 1.4s ease-in-out infinite;
}

.fab-mic.busy {
  opacity: 0.6;
  pointer-events: none;
}

@keyframes fabMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(185, 28, 28, 0.5); }
  50% { box-shadow: 0 0 0 10px rgba(185, 28, 28, 0); }
}

/* ── Recording banner ─────────────────────────────── */
.recording-banner {
  position: fixed;
  right: var(--space-6);
  bottom: calc(var(--space-6) + 56px + var(--space-3));
  z-index: var(--z-fab);
  display: none;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-inverse);
  color: var(--text-inverse);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.recording-banner.open {
  display: flex;
}

.recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: fabMicPulse 1.2s ease-in-out infinite;
}

.recording-timer {
  font-family: var(--font-mono);
  color: var(--text-inverse);
  opacity: 0.7;
}

/* ── Mobile bottom tab bar ─────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: var(--space-2) var(--space-1);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
}

.bottom-nav-item {
  flex: 1;
  text-align: center;
  font-size: 9px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--space-2) var(--space-1);
  cursor: pointer;
}

.bottom-nav-item.active {
  color: var(--text-primary);
}

/* ── Empty state ──────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state-text {
  font-size: var(--text-sm);
  max-width: 300px;
  margin: 0 auto var(--space-5);
}

/* ── Loading spinner ──────────────────────────────── */
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-sm { width: 16px; height: 16px; }
.spinner-lg { width: 40px; height: 40px; border-width: 3px; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
}

/* ── Skeleton loading ─────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-hover) 25%,
    var(--bg-active) 50%,
    var(--bg-hover) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Section headers ──────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ── Mobile: hide sidebar, show hamburger ─────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-height) + env(safe-area-inset-top));
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) var(--space-4) 0;
  align-items: center;
  justify-content: space-between;
  z-index: var(--z-sticky);
}

.mobile-menu-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
}

.mobile-menu-btn:hover {
  background: var(--bg-hover);
}

.mobile-header-logo {
  height: 22px;
  width: auto;
  display: block;
}

.sidebar-logo-img {
  height: 30px;
  width: auto;
  display: block;
}

.mobile-notif-btn {
  position: relative;
}

.mobile-notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-sticky) - 1);
}

@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding-top: calc(var(--header-height) + env(safe-area-inset-top));
    padding-bottom: calc(56px + env(safe-area-inset-bottom) + var(--space-4));
  }

  .page-container {
    padding: var(--space-5) var(--space-4);
  }

  .bottom-nav {
    display: flex;
  }

  .capture-fabs {
    bottom: calc(56px + env(safe-area-inset-bottom) + var(--space-4));
  }

  .recording-banner {
    bottom: calc(56px + env(safe-area-inset-bottom) + var(--space-4) + 56px + var(--space-3));
  }

  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
    bottom: calc(56px + env(safe-area-inset-bottom) + var(--space-4) + 56px + var(--space-4));
  }

  .toast {
    min-width: unset;
    width: 100%;
  }
}

/* ── Omnibox ──────────────────────────────────────── */
.omnibox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}

.omnibox {
  background: var(--bg-elevated);
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), 0 0 40px rgba(0,0,0,0.5);
  border: 1px solid var(--border-accent);
  overflow: hidden;
  animation: slideDown 0.2s var(--ease-out);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.omnibox-header {
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  height: 64px;
  border-bottom: 1px solid var(--border);
}

.omnibox-icon {
  font-size: 20px;
  color: var(--text-muted);
  margin-right: var(--space-3);
}

.omnibox-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: var(--text-lg);
  outline: none;
}

.omnibox-input::placeholder {
  color: var(--text-muted);
}

.omnibox-shortcut {
  font-size: 11px;
  background: var(--bg-hover);
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  border: 1px solid var(--border-subtle);
}

.omnibox-results {
  max-height: 400px;
  overflow-y: auto;
}

.omnibox-empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.omnibox-row {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.1s;
}

.omnibox-row:last-child {
  border-bottom: none;
}

.omnibox-row:hover {
  background: var(--bg-hover);
}

.omnibox-row-icon {
  font-size: 18px;
  margin-right: var(--space-3);
  width: 24px;
  text-align: center;
}

.omnibox-row-content {
  flex: 1;
}

.omnibox-row-title {
  color: var(--text-primary);
  font-size: var(--text-base);
}

.omnibox-row-badge {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: var(--radius-full);
}

/* ------------------------------------------------------
   LIGHT THEME OVERRIDES (Jerad Style)
   ------------------------------------------------------ */
[data-theme='light'] .page-title, [data-theme='light'] .modal-title {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

