/* ============================================================
   LifeHub — macOS-inspired design system
   Vibrancy (translucency + blur), soft depth, restrained colour,
   and system typography. Tailwind handles layout; this file owns
   materials, depth and the components Tailwind can't express.
   ============================================================ */

:root {
  /* Accent — matches macOS "multicolour" blue */
  --accent: #0a84ff;
  --accent-strong: #0071e3;
  --accent-soft: rgba(10, 132, 255, .12);

  /* Semantic */
  --green: #30d158;
  --orange: #ff9f0a;
  --red: #ff453a;
  --purple: #bf5af2;
  --pink: #ff375f;
  --teal: #40c8e0;

  /* Materials — layered translucency, the core of the macOS look */
  --material-thick: rgba(255, 255, 255, .82);
  --material-regular: rgba(255, 255, 255, .68);
  --material-thin: rgba(255, 255, 255, .52);
  --sidebar-material: rgba(246, 246, 248, .72);

  /* Separators are hairlines, never hard borders */
  --separator: rgba(0, 0, 0, .08);
  --separator-strong: rgba(0, 0, 0, .14);

  --text: #1d1d1f;
  --text-secondary: rgba(60, 60, 67, .6);
  --text-tertiary: rgba(60, 60, 67, .35);

  /* Depth: tight contact shadow + wide ambient shadow */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .04), 0 1px 3px rgba(0, 0, 0, .06);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, .06), 0 20px 48px rgba(0, 0, 0, .14);
  --shadow-window: 0 10px 30px rgba(0, 0, 0, .12), 0 30px 90px rgba(0, 0, 0, .18);

  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

/* ---------- Base ---------- */
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Inter", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  letter-spacing: -0.01em;
  /* Desktop-picture wash: the translucent panels need something to pick up */
  background:
    radial-gradient(1200px 700px at 12% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(1000px 800px at 105% 0%, #ede9fe 0%, transparent 50%),
    radial-gradient(900px 700px at 50% 115%, #cffafe 0%, transparent 55%),
    linear-gradient(170deg, #f4f5f7 0%, #eceef2 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

h1, h2, h3, h4 { letter-spacing: -0.022em; }

/* ---------- Materials ---------- */
.mac-panel {
  background: var(--material-thick);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid rgba(255, 255, 255, .6);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-lg);
}

.mac-panel-flat {
  background: var(--material-regular);
  backdrop-filter: saturate(160%) blur(20px);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: var(--radius);
}

.mac-sidebar {
  background: var(--sidebar-material);
  backdrop-filter: saturate(180%) blur(40px);
  -webkit-backdrop-filter: saturate(180%) blur(40px);
  border-right: 1px solid var(--separator);
}

.mac-toolbar {
  /* The toolbar must sit above the scrolling content. Panels in <main> use
     backdrop-filter, which creates a stacking context — without an explicit
     z-index here, later siblings paint over the notification dropdown. */
  position: relative;
  z-index: 60;
  background: rgba(255, 255, 255, .6);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border-bottom: 1px solid var(--separator);
}

.mac-window {
  background: var(--material-thick);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid rgba(255, 255, 255, .55);
  box-shadow: var(--shadow-window);
  border-radius: var(--radius-lg);
}

/* Traffic lights — the unmistakable macOS window control cluster */
.traffic-lights { display: flex; gap: 8px; align-items: center; }
.traffic-light {
  width: 12px; height: 12px; border-radius: 50%;
  border: none; padding: 0; cursor: pointer;
  position: relative; transition: filter .15s ease;
}
.traffic-light.close { background: #ff5f57; }
.traffic-light.minimize { background: #febc2e; }
.traffic-light.zoom { background: #28c840; }
.traffic-lights:hover .traffic-light { filter: brightness(.92); }
.traffic-light::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 50%; box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .12);
}

/* ---------- Controls ---------- */
.mac-btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  padding: 6px 14px;
  transition: background .15s ease, transform .08s ease, box-shadow .15s ease;
  border: 1px solid var(--separator);
  background: linear-gradient(180deg, #fff 0%, #fafafa 100%);
  box-shadow: var(--shadow-sm);
  color: var(--text);
}
.mac-btn:hover { background: linear-gradient(180deg, #fafafa 0%, #f2f2f4 100%); }
.mac-btn:active { transform: scale(.975); }

.mac-btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 113, 227, .35), var(--shadow-sm);
}
.mac-btn-primary:hover { filter: brightness(1.06); }
.mac-btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.mac-input {
  border-radius: 8px;
  border: 1px solid var(--separator-strong);
  background: rgba(255, 255, 255, .85);
  padding: 7px 11px;
  font-size: 13px;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
  color: var(--text);
}
.mac-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-soft);
}
.mac-input::placeholder { color: var(--text-tertiary); }

/* Segmented control — the macOS tab pill */
.mac-segment {
  background: rgba(120, 120, 128, .12);
  border-radius: 9px;
  padding: 2px;
  display: flex;
}
.mac-segment button {
  flex: 1; border-radius: 7px; padding: 5px 12px;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  transition: all .18s ease;
}
.mac-segment button.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04);
}

/* ---------- Sidebar navigation ---------- */
.nav-btn {
  border-radius: 8px;
  transition: background .15s ease, color .15s ease;
  color: var(--text-secondary);
  font-weight: 500;
}
.nav-btn:hover { background: rgba(120, 120, 128, .1); color: var(--text); }
.nav-btn.active {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 113, 227, .4);
}

/* ---------- Presence ---------- */
.presence-dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 .5px rgba(0, 0, 0, .06);
}
.presence-online { background: var(--green); }
.presence-offline { background: #c7c7cc; }

/* ---------- Messenger dock ---------- */
#messengerDock {
  position: fixed; right: 20px; bottom: 20px; z-index: 120;
  display: flex; align-items: flex-end; gap: 12px;
}

.chat-window {
  width: 328px; height: 440px;
  display: flex; flex-direction: column;
  animation: windowIn .22s cubic-bezier(.2, .9, .3, 1.2);
  overflow: hidden;
}
.chat-window.minimized { height: 40px; }
.chat-window.minimized .chat-window-body { display: none; }

@keyframes windowIn {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-bubble-launcher {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 113, 227, .4), var(--shadow-md);
  transition: transform .15s ease;
}
.chat-bubble-launcher:hover { transform: scale(1.06); }
.chat-bubble-launcher:active { transform: scale(.95); }

/* Message bubbles — iMessage geometry */
.msg-row { display: flex; margin-bottom: 2px; }
.msg-bubble {
  max-width: 78%;
  padding: 7px 12px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.35;
  word-break: break-word;
}
.msg-mine {
  background: linear-gradient(180deg, #1e90ff 0%, var(--accent-strong) 100%);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.msg-theirs {
  background: rgba(120, 120, 128, .14);
  color: var(--text);
  border-bottom-left-radius: 5px;
}

/* Typing indicator */
.typing-dots span {
  display: inline-block; width: 6px; height: 6px; margin-right: 3px;
  background: var(--text-tertiary); border-radius: 50%;
  animation: typingBounce 1.3s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .18s; }
.typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Video call ---------- */
#callOverlay { backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); }
#callRemoteVideo { background: #000; }
#callLocalVideo {
  position: absolute; right: 18px; bottom: 18px;
  width: 168px; border-radius: 12px;
  box-shadow: var(--shadow-lg);
  border: 2px solid rgba(255, 255, 255, .18);
  background: #000;
  transform: scaleX(-1); /* mirror self-view, as every video app does */
}
.call-control {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; transition: transform .12s ease, background .15s ease;
  background: rgba(255, 255, 255, .16); color: #fff;
  backdrop-filter: blur(10px);
}
.call-control:hover { background: rgba(255, 255, 255, .26); }
.call-control:active { transform: scale(.92); }
.call-control.danger { background: var(--red); }
.call-control.danger:hover { background: #ff6961; }
.call-control.accept { background: var(--green); }

@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(48, 209, 88, .5); }
  50% { box-shadow: 0 0 0 18px rgba(48, 209, 88, 0); }
}
.ringing { animation: ringPulse 1.6s infinite; }

/* ---------- Dashboard ---------- */
.stat-card {
  background: var(--material-thick);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid rgba(255, 255, 255, .6);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  transition: transform .18s ease, box-shadow .18s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-value { font-size: 26px; font-weight: 600; letter-spacing: -0.03em; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase;
              letter-spacing: .05em; color: var(--text-tertiary); }

.insight-row {
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: transform .15s ease;
  border: 1px solid var(--separator);
}
.insight-row:hover { transform: translateX(2px); }
.insight-high { background: linear-gradient(180deg, rgba(255,69,58,.07), rgba(255,69,58,.03)); border-color: rgba(255,69,58,.2); }
.insight-medium { background: linear-gradient(180deg, rgba(255,159,10,.08), rgba(255,159,10,.03)); border-color: rgba(255,159,10,.22); }
.insight-info { background: rgba(120,120,128,.06); }
.insight-good { background: linear-gradient(180deg, rgba(48,209,88,.09), rgba(48,209,88,.03)); border-color: rgba(48,209,88,.22); }

/* Thin progress meters used in the category breakdown */
.meter { height: 6px; border-radius: 999px; background: rgba(120,120,128,.14); overflow: hidden; }
.meter > div { height: 100%; border-radius: 999px; transition: width .5s cubic-bezier(.2,.8,.3,1); }

/* ---------- Calendar (FullCalendar overrides) ---------- */
.fc { --fc-border-color: var(--separator); --fc-today-bg-color: rgba(10,132,255,.07); }
.fc .fc-toolbar-title { font-size: 17px !important; font-weight: 600; letter-spacing: -.02em; }
.fc .fc-button {
  background: linear-gradient(180deg, #fff, #fafafa) !important;
  border: 1px solid var(--separator) !important;
  color: var(--text) !important;
  box-shadow: var(--shadow-sm);
  border-radius: 8px !important;
  font-size: 12.5px !important;
  font-weight: 500 !important;
  text-transform: none !important;
  padding: 5px 11px !important;
}
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong)) !important;
  border-color: transparent !important;
  color: #fff !important;
}
.fc .fc-daygrid-day-number, .fc .fc-col-header-cell-cushion { font-size: 12px; color: var(--text-secondary); }
.fc-event { border-radius: 6px !important; border: none !important; font-size: 11.5px; padding: 1px 4px; }
.fc-theme-standard td, .fc-theme-standard th { border-color: var(--separator); }

/* ---------- Kanban ---------- */
.kanban-card {
  border-radius: 10px;
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-sm);
  background: rgba(255, 255, 255, .9);
  cursor: pointer;
  transition: box-shadow .15s ease, transform .12s ease;
}
.kanban-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
/* The placeholder left behind in the list while dragging. */
.sortable-ghost {
  opacity: .4;
  background: var(--accent-soft) !important;
  border: 1px dashed var(--accent) !important;
}

/* The element following the cursor. Rotation is applied to the fallback clone,
   which SortableJS appends to <body>, so it must not be transformed away. */
.sortable-drag {
  box-shadow: var(--shadow-lg) !important;
  opacity: 1 !important;
  cursor: grabbing !important;
}

.sortable-chosen { cursor: grabbing; }

/* Cards advertise that they can be picked up, and a drag must not turn into a
   text selection. */
.kanban-card { cursor: grab; user-select: none; -webkit-user-select: none; }
.kanban-card:active { cursor: grabbing; }

/* Touch panning is handled by SortableJS's delayed start, so the browser should
   not claim vertical gestures inside a column. */
.column-body { touch-action: pan-x; min-height: 24px; }

.pri-Low { background: rgba(120,120,128,.14); color: var(--text-secondary); }
.pri-Normal { background: rgba(10,132,255,.14); color: #0060df; }
.pri-High { background: rgba(255,159,10,.18); color: #b26800; }
.pri-Urgent { background: rgba(255,69,58,.16); color: #c9271c; }

/* Charts fill a parent of known height rather than sizing themselves. */
.chart-box { position: relative; width: 100%; }
.chart-box > canvas { position: absolute; inset: 0; }

/* ---------- Notifications ---------- */
.notif-unread { background: var(--accent-soft); }

/* Above every panel in the content area, and above the messenger dock. */
#notifPanel { z-index: 170; }

/* The panel hangs below the toolbar, so the window must not clip it. */
#mainWindow { overflow: visible; }
#mainWindow > main { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ---------- Toasts ---------- */
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.mac-toast { animation: toastIn .22s cubic-bezier(.2,.9,.3,1.2); }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .18);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, .3); background-clip: content-box; }

/* ---------- File viewer ---------- */
#viewerBody img, #viewerBody iframe, #viewerBody pre { max-height: calc(100vh - 96px); border-radius: 10px; }
#viewerBody iframe { min-height: 72vh; border: 0; width: 100%; background: #fff; }

/* ---------- Receipt scanner ---------- */
.scan-preview { max-height: 260px; border-radius: 10px; box-shadow: var(--shadow-sm); }
.scan-progress { height: 4px; border-radius: 999px; background: rgba(120,120,128,.16); overflow: hidden; }
.scan-progress > div { height: 100%; background: var(--accent); transition: width .3s ease; }

/* Rows parsed out of a receipt, before the user commits them */
.scan-row { display: grid; grid-template-columns: 1fr 92px 32px; gap: 8px; align-items: start; }
.scan-row .mac-input { padding-top: 5px; padding-bottom: 5px; }

/* A row the OCR wasn't confident about — flagged rather than silently trusted. */
.scan-row-suspect > div > .row-desc { border-color: var(--orange); background: rgba(255, 159, 10, .06); }

/* ---------- Utility ---------- */
.hairline-t { border-top: 1px solid var(--separator); }
.hairline-b { border-bottom: 1px solid var(--separator); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   Responsive — phones and small tablets
   The desktop layout is a fixed sidebar + floating chat dock.
   On small screens the sidebar becomes an off-canvas drawer, the
   dock becomes a full-screen sheet, and every multi-column grid
   collapses to a single column.
   ============================================================ */

/* Comfortable tap targets on touch devices, where hover never fires. */
@media (hover: none) {
  .mac-btn { padding: 9px 16px; }
  .nav-btn { padding-top: 10px; padding-bottom: 10px; }
  .traffic-light { width: 13px; height: 13px; }
}

@media (max-width: 1024px) {
  /* Three-column dashboards get cramped well before phone width. */
  .grid-cols-3 > .col-span-2 { grid-column: span 3 / span 3; }
}

@media (max-width: 768px) {
  body { background-attachment: scroll; }

  /* ---- Shell ---- */
  #app { padding: 0; gap: 0; height: 100dvh; }

  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 264px;
    max-width: 84vw;
    z-index: 130;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.2, .9, .3, 1);
  }
  #sidebar.open { transform: translateX(0); box-shadow: var(--shadow-window); }

  #sidebarBackdrop {
    position: fixed; inset: 0; z-index: 125;
    background: rgba(0, 0, 0, .35);
    backdrop-filter: blur(2px);
  }

  #mainWindow { border-radius: 0; border: none; box-shadow: none; }
  #menuBtn { display: flex !important; }

  /* The toolbar needs room for the menu button and stays sticky while scrolling. */
  header.mac-toolbar { padding-left: 12px; padding-right: 12px; }
  #viewTitle { font-size: 16px; }
  #rtStatus { display: none; }

  main { padding: 12px !important; padding-bottom: 96px !important; }

  /* ---- Grids collapse ---- */
  #view-insights .grid,
  #view-expenses .grid { grid-template-columns: 1fr !important; }
  #view-insights .col-span-2,
  #view-expenses .col-span-2 { grid-column: span 1 / span 1 !important; }
  #view-boards .grid-cols-3 { grid-template-columns: 1fr !important; }

  /* Expenses: the group list stacks above the detail rather than sitting beside it. */
  #view-expenses > .flex { flex-direction: column; height: auto; }
  #view-expenses > .flex > .w-64 { width: 100%; }
  #view-expenses #groupList {
    display: flex; gap: 8px; overflow-x: auto;
    padding-bottom: 4px; scroll-snap-type: x mandatory;
  }
  #view-expenses #groupList > * { min-width: 190px; scroll-snap-align: start; }

  /* KPI strip: two up instead of four. */
  #view-insights .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .stat-value { font-size: 21px; }

  /* ---- Modals become bottom sheets ---- */
  #modalRoot { padding: 0; align-items: flex-end; }
  #modalCard {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: sheetUp .26s cubic-bezier(.2, .9, .3, 1);
  }
  @keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

  /* ---- Messenger ---- */
  #messengerDock { right: 12px; bottom: 12px; left: 12px; justify-content: flex-end; }
  #chatWindows { position: static; }

  /* One conversation at a time, filling the screen. */
  .chat-window {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    border-radius: 0;
    z-index: 140;
  }
  /* Minimised windows collapse to nothing on mobile — the launcher reopens them. */
  .chat-window.minimized { display: none; }

  #peoplePanel {
    position: fixed;
    left: 12px; right: 12px; bottom: 84px;
    width: auto;
    max-height: 62dvh;
  }

  /* ---- Calls ---- */
  #callOverlay { padding: 0; }
  #callOverlay > .relative { max-width: 100%; aspect-ratio: auto; height: 72dvh; }
  #callRemoteVideo { border-radius: 0; }
  #callLocalVideo { width: 104px; right: 12px; bottom: 12px; }
  .call-control { width: 58px; height: 58px; }

  /* ---- Kanban: columns swipe horizontally ---- */
  #columns { scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
  #columns > div[data-col] { scroll-snap-align: start; width: 82vw; max-width: 300px; }

  /* ---- Calendar ---- */
  .fc .fc-toolbar { flex-wrap: wrap; gap: 6px; }
  .fc .fc-toolbar-title { font-size: 15px !important; }
  .fc .fc-button { padding: 5px 9px !important; font-size: 11.5px !important; }
  #calChips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  #calChips > * { flex-shrink: 0; }

  /* ---- Scan / location pickers ---- */
  .scan-row { grid-template-columns: 1fr 78px 30px; }
  .lp-map { height: 180px !important; }

  /* ---- Viewer ---- */
  #viewerBody { padding: 8px; }
  #viewerBody iframe { min-height: 60dvh; }
}

@media (max-width: 420px) {
  #view-insights .grid-cols-4,
  #view-insights .grid-cols-2 { grid-template-columns: 1fr !important; }
  .msg-bubble { max-width: 86%; }
  .stat-value { font-size: 19px; }
}

/* Landscape phones: keep the call UI usable when height is scarce. */
@media (max-height: 480px) and (orientation: landscape) {
  #callOverlay > .relative { height: 62dvh; }
  .call-control { width: 44px; height: 44px; font-size: 17px; }
}

/* ---------- Camera capture ---------- */
#cameraOverlay .cam-video,
#cameraOverlay .cam-review { object-fit: contain; background: #000; }
#cameraOverlay .cam-shoot { box-shadow: 0 0 0 3px rgba(255, 255, 255, .25); }
#cameraOverlay .cam-shoot:disabled { opacity: .5; }
#cameraOverlay .cam-review-controls.flex { display: flex; }
#cameraOverlay .cam-quality { min-height: 18px; }

@media (max-width: 768px) {
  #cameraOverlay .cam-shoot { width: 68px; height: 68px; }
}

/* ============================================================
   Dark theme
   Same design language, inverted materials. Only the tokens and
   the handful of places that hard-code white are overridden, so
   every component follows automatically.
   ============================================================ */

html[data-theme="dark"] {
  --accent: #0a84ff;
  --accent-strong: #409cff;
  --accent-soft: rgba(10, 132, 255, .18);

  --material-thick: rgba(30, 30, 32, .82);
  --material-regular: rgba(38, 38, 41, .72);
  --material-thin: rgba(44, 44, 47, .6);
  --sidebar-material: rgba(24, 24, 26, .78);

  --separator: rgba(255, 255, 255, .09);
  --separator-strong: rgba(255, 255, 255, .16);

  --text: #f2f2f7;
  --text-secondary: rgba(235, 235, 245, .62);
  --text-tertiary: rgba(235, 235, 245, .35);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, .45), 0 8px 24px rgba(0, 0, 0, .4);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, .5), 0 20px 48px rgba(0, 0, 0, .5);
  --shadow-window: 0 10px 30px rgba(0, 0, 0, .55), 0 30px 90px rgba(0, 0, 0, .6);

  color-scheme: dark;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(1200px 700px at 12% -10%, #1e293b 0%, transparent 55%),
    radial-gradient(1000px 800px at 105% 0%, #2a2140 0%, transparent 50%),
    radial-gradient(900px 700px at 50% 115%, #0f2b33 0%, transparent 55%),
    linear-gradient(170deg, #131315 0%, #0c0c0e 100%);
}

/* Panels lose the bright inner edge; a faint light border reads better on dark. */
html[data-theme="dark"] .mac-panel,
html[data-theme="dark"] .mac-panel-flat,
html[data-theme="dark"] .mac-window { border-color: rgba(255, 255, 255, .08); }

html[data-theme="dark"] .mac-toolbar { background: rgba(30, 30, 32, .6); }

/* Controls: the light-mode gradients are white-on-white and vanish. */
html[data-theme="dark"] .mac-btn {
  background: linear-gradient(180deg, #3a3a3d 0%, #313134 100%);
  border-color: rgba(255, 255, 255, .1);
  color: var(--text);
}
html[data-theme="dark"] .mac-btn:hover {
  background: linear-gradient(180deg, #444447 0%, #3a3a3d 100%);
}
html[data-theme="dark"] .mac-btn-primary {
  background: linear-gradient(180deg, #0a84ff 0%, #0070e0 100%);
  color: #fff;
}

html[data-theme="dark"] .mac-input {
  background: rgba(255, 255, 255, .06);
  border-color: rgba(255, 255, 255, .14);
  color: var(--text);
}
html[data-theme="dark"] .mac-segment { background: rgba(255, 255, 255, .08); }
html[data-theme="dark"] .mac-segment button.active {
  background: #48484b;
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

html[data-theme="dark"] .kanban-card { background: rgba(58, 58, 61, .9); }
html[data-theme="dark"] .msg-theirs { background: rgba(255, 255, 255, .12); }
html[data-theme="dark"] .meter { background: rgba(255, 255, 255, .12); }

/* Charts and maps: the doughnut segment borders and tiles both assume white. */
html[data-theme="dark"] .leaflet-tile { filter: brightness(.78) contrast(1.08); }
html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip { background: #2c2c2e; color: var(--text); }

html[data-theme="dark"] .insight-info { background: rgba(255, 255, 255, .05); }

/* FullCalendar draws its own light chrome. */
html[data-theme="dark"] .fc { --fc-page-bg-color: transparent; --fc-neutral-bg-color: rgba(255,255,255,.05); }
html[data-theme="dark"] .fc .fc-button {
  background: linear-gradient(180deg, #3a3a3d, #313134) !important;
  border-color: rgba(255, 255, 255, .1) !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .fc-theme-standard .fc-list-day-cushion { background: rgba(255, 255, 255, .06); }

html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .2); background-clip: content-box; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .32); background-clip: content-box; }

/* Native widgets inside modals (date pickers, colour swatches). */
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="datetime-local"] { color-scheme: dark; }

/* ============================================================
   Motion — soft and consistent
   ============================================================ */

/* Theme changes crossfade rather than snapping. */
html.theme-switching,
html.theme-switching * {
  transition: background-color .28s ease, color .28s ease, border-color .28s ease !important;
}

.mac-panel, .mac-panel-flat, .mac-window, .stat-card, .kanban-card, .insight-row {
  transition: background .22s ease, border-color .22s ease,
              box-shadow .22s cubic-bezier(.2, .8, .3, 1),
              transform .22s cubic-bezier(.2, .8, .3, 1);
}

.mac-btn, .nav-btn, .mac-input, .presence-dot, .meter > div {
  transition: background .18s ease, color .18s ease, border-color .18s ease,
              box-shadow .18s ease, transform .12s ease, width .5s cubic-bezier(.2, .8, .3, 1);
}

/* Views fade in instead of appearing abruptly. */
.view:not(.hidden) { animation: viewIn .26s cubic-bezier(.2, .9, .3, 1); }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Dropdown panels get the same easing as everything else. */
#notifPanel:not(.hidden), #peoplePanel:not(.hidden) {
  animation: panelIn .18s cubic-bezier(.2, .9, .3, 1);
  transform-origin: top right;
}
@keyframes panelIn {
  from { opacity: 0; transform: scale(.97) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ============================================================
   Kanban drag affordances
   ============================================================ */

.card-grip {
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 1.1;
  cursor: grab;
  opacity: 0;
  transition: opacity .15s ease;
  user-select: none;
}
.kanban-card:hover .card-grip { opacity: 1; }

/* On touch there is no hover, so the grip is always visible. */
@media (hover: none) {
  .card-grip { opacity: .55; }
}

.kanban-card.is-done { opacity: .62; }

/* The column being dragged over lifts slightly and tints. */
.column-body.column-target {
  background: var(--accent-soft);
  border-radius: 10px;
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* While a card is in flight, nothing else should react to the cursor. */
body.is-dragging-card .kanban-card:hover { transform: none; box-shadow: var(--shadow-sm); }
body.is-dragging-card { cursor: grabbing; }

/* ============================================================
   Avatars
   ============================================================ */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  overflow: hidden;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Dashboard: transactions & categories ---------- */
.tx-row { transition: background .15s ease; }
.tx-row:hover { background: rgba(120, 120, 128, .07); }
html[data-theme="dark"] .tx-row:hover { background: rgba(255, 255, 255, .05); }

.cat-row { transition: background .15s ease; border-radius: 6px; }
.cat-row:hover { background: rgba(120, 120, 128, .07); }
html[data-theme="dark"] .cat-row:hover { background: rgba(255, 255, 255, .05); }

/* The headline figures lead with colour, as in a statement summary. */
.stat-card.text-center { padding: 18px 14px; }

/* The range picker sits inline with the heading and must not stretch. */
#dashRange, #dashFrom, #dashTo { width: auto; min-width: 130px; }

@media (max-width: 640px) {
  #dashCustomRange { width: 100%; }
  #dashFrom, #dashTo { flex: 1; min-width: 0; }
}

/* Tables scroll rather than squash on narrow screens. */
#dashBody table { border-collapse: collapse; }
#dashBody table td { vertical-align: middle; }

/* ============================================================
   Notes
   ============================================================ */

.notes-grid {
  display: grid;
  grid-template-columns: 210px 280px 1fr;
  gap: 12px;
  height: calc(100dvh - 132px);
  min-height: 460px;
}

.notes-tree { overflow-y: auto; }
.notes-list { overflow-y: auto; }
.notes-editor { overflow: hidden; display: flex; flex-direction: column; }

.note-row {
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s ease, transform .12s ease;
  border-bottom: 1px solid var(--separator);
}
.note-row:last-child { border-bottom: 0; }
.note-row:hover { background: rgba(120, 120, 128, .08); }
.note-row.is-active { background: var(--accent-soft); }
html[data-theme="dark"] .note-row:hover { background: rgba(255, 255, 255, .06); }

.line-clamp-2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(120, 120, 128, .14);
  color: var(--text-secondary);
  transition: background .15s ease, color .15s ease;
}
.note-tag:hover { background: var(--accent-soft); color: var(--accent); }
.note-tag.is-active { background: var(--accent); color: #fff; }

.note-tag-mini {
  font-size: 10px; padding: 1px 5px; border-radius: 4px;
  background: rgba(120, 120, 128, .14); color: var(--text-secondary);
}

/* ---- editor ---- */
.note-body { display: grid; }
.note-body.mode-edit { grid-template-columns: 1fr; }
.note-body.mode-preview { grid-template-columns: 1fr; }
.note-body.mode-split { grid-template-columns: 1fr 1fr; }

.note-body.mode-edit .note-preview,
.note-body.mode-preview .note-textarea { display: none; }

.note-textarea {
  width: 100%; height: 100%;
  border: 0; outline: 0; resize: none;
  padding: 16px 18px;
  background: transparent;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
}

.note-preview {
  overflow-y: auto;
  padding: 16px 18px;
  border-left: 1px solid var(--separator);
}
.note-body.mode-preview .note-preview { border-left: 0; }

.md-tool {
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text-secondary);
  transition: background .15s ease, color .15s ease;
}
.md-tool:hover { background: rgba(120, 120, 128, .14); color: var(--text); }

.note-file {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; padding: 4px 8px;
  border-radius: 8px;
  background: rgba(120, 120, 128, .1);
  border: 1px solid var(--separator);
}
.note-file button { color: var(--text-tertiary); padding: 0 2px; }
.note-file button:hover { color: var(--accent); }
.note-file .note-file-remove:hover { color: var(--red); }

/* ============================================================
   Rendered markdown
   ============================================================ */

.markdown-body { font-size: 13.5px; line-height: 1.7; color: var(--text); }
.markdown-body .md-h { font-weight: 600; letter-spacing: -.02em; margin: 1.1em 0 .45em; }
.markdown-body .md-h1 { font-size: 22px; }
.markdown-body .md-h2 { font-size: 18px; }
.markdown-body .md-h3 { font-size: 15.5px; }
.markdown-body .md-h4, .markdown-body .md-h5, .markdown-body .md-h6 { font-size: 14px; }
.markdown-body .md-p { margin: .55em 0; }
.markdown-body .md-hr { border: 0; border-top: 1px solid var(--separator); margin: 1.4em 0; }

.markdown-body .md-list { margin: .5em 0 .5em 1.2em; }
.markdown-body .md-list li { margin: .22em 0; }
.markdown-body ol.md-list { list-style: decimal; }
.markdown-body ul.md-list { list-style: disc; }
.markdown-body .md-tasks { list-style: none; margin-left: 0; }
.markdown-body .md-task { display: flex; gap: 7px; align-items: flex-start; }
.markdown-body .md-check { color: var(--accent); }
.markdown-body .md-done { color: var(--text-tertiary); text-decoration: line-through; }

.markdown-body .md-quote {
  border-left: 3px solid var(--accent);
  padding: .1em 0 .1em .9em;
  margin: .7em 0;
  color: var(--text-secondary);
}

.markdown-body .md-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .88em;
  background: rgba(120, 120, 128, .16);
  padding: 1px 5px; border-radius: 5px;
}
.markdown-body .md-pre {
  background: rgba(120, 120, 128, .12);
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: .8em 0;
}
.markdown-body .md-pre code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px; line-height: 1.6; background: none; padding: 0;
}

.markdown-body .md-link { color: var(--accent); text-decoration: none; }
.markdown-body .md-link:hover { text-decoration: underline; }

.markdown-body .md-img {
  max-width: 100%; border-radius: 10px; margin: .6em 0;
  box-shadow: var(--shadow-sm);
}

.markdown-body .md-video {
  position: relative; width: 100%; padding-top: 56.25%;
  border-radius: 10px; overflow: hidden; margin: .8em 0;
  box-shadow: var(--shadow-sm); background: #000;
}
.markdown-body .md-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.markdown-body .md-table-wrap { overflow-x: auto; margin: .8em 0; }
.markdown-body .md-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.markdown-body .md-table th, .markdown-body .md-table td {
  border: 1px solid var(--separator); padding: 6px 10px; text-align: left;
}
.markdown-body .md-table th { background: rgba(120, 120, 128, .1); font-weight: 600; }

.markdown-body .md-tag {
  color: var(--accent); background: var(--accent-soft);
  padding: 1px 5px; border-radius: 5px; cursor: pointer; font-size: .92em;
}

/* ============================================================
   Ask panel
   ============================================================ */

.ask-panel {
  position: fixed;
  right: 20px; bottom: 20px;
  width: 420px; max-width: calc(100vw - 40px);
  height: 560px; max-height: calc(100dvh - 120px);
  z-index: 135;
  display: flex; flex-direction: column;
  background: var(--material-thick);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-window);
  overflow: hidden;
  animation: windowIn .22s cubic-bezier(.2, .9, .3, 1.2);
}
html[data-theme="dark"] .ask-panel { border-color: rgba(255, 255, 255, .08); }

.ask-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--separator);
}

.ask-thread { flex: 1; overflow-y: auto; padding: 12px; }
.ask-empty { text-align: center; padding: 40px 16px; }

.ask-row { display: flex; margin-bottom: 10px; }
.ask-bubble { max-width: 92%; border-radius: 14px; padding: 10px 12px; font-size: 13px; }
.ask-mine {
  background: linear-gradient(180deg, #1e90ff, var(--accent-strong));
  color: #fff; border-bottom-right-radius: 5px;
}
.ask-theirs {
  background: rgba(120, 120, 128, .12);
  border-bottom-left-radius: 5px;
}
.ask-answer { font-size: 13px; }
.ask-answer .md-p:first-child { margin-top: 0; }

.ask-source {
  background: rgba(255, 255, 255, .55);
  border: 1px solid var(--separator);
  border-radius: 9px; padding: 7px 9px; cursor: pointer;
  transition: border-color .15s ease, transform .12s ease;
}
.ask-source:hover { border-color: var(--accent); transform: translateX(2px); }
html[data-theme="dark"] .ask-source { background: rgba(255, 255, 255, .05); }

.ask-relevance {
  margin-left: auto; font-size: 9.5px; padding: 1px 5px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}

.ask-media { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ask-media-item { border-radius: 8px; overflow: hidden; display: block; }
.ask-media-item img { width: 100%; height: 84px; object-fit: cover; display: block; }
.ask-media-item .md-video { margin: 0; grid-column: 1 / -1; }

.ask-link {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; padding: 5px 8px; border-radius: 8px;
  background: rgba(255, 255, 255, .5); color: var(--accent);
  border: 1px solid var(--separator);
}
html[data-theme="dark"] .ask-link { background: rgba(255, 255, 255, .05); }

.ask-suggest {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}

.ask-composer {
  display: flex; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--separator);
}

@media (max-width: 1100px) {
  .notes-grid { grid-template-columns: 190px 1fr; }
  .notes-editor { grid-column: 1 / -1; height: 60vh; }
}

@media (max-width: 768px) {
  .notes-grid { grid-template-columns: 1fr; height: auto; }
  .notes-tree { max-height: 220px; }
  .notes-list { max-height: 300px; }
  .notes-editor { height: 70vh; }
  .note-body.mode-split { grid-template-columns: 1fr; }
  .note-body.mode-split .note-preview { display: none; }

  .ask-panel {
    right: 12px; left: 12px; bottom: 12px;
    width: auto; height: 70dvh;
  }
}

/* ============================================================
   Dashboard: commitment tiles & to-do
   ============================================================ */

.commit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
}

.commit-tile {
  position: relative;
  padding: 12px 12px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--separator);
  background: rgba(255, 255, 255, .5);
  transition: transform .18s cubic-bezier(.2, .8, .3, 1), box-shadow .18s ease, border-color .18s ease;
  cursor: default;
  overflow: hidden;
}
html[data-theme="dark"] .commit-tile { background: rgba(255, 255, 255, .04); }

.commit-tile::before {
  content: '';
  position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--tile);
  opacity: .85;
}
.commit-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--tile);
}
.commit-tile.is-paid { opacity: .58; }
.commit-tile.is-due { border-color: var(--tile); box-shadow: 0 0 0 2px var(--accent-soft); }

.commit-icon { font-size: 20px; line-height: 1; margin-bottom: 6px; }
.commit-name {
  font-size: 12px; font-weight: 500; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.commit-amount { font-size: 15px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; }

.commit-meter {
  height: 3px; border-radius: 999px; margin-top: 7px;
  background: rgba(120, 120, 128, .16); overflow: hidden;
}
.commit-meter > div {
  height: 100%; background: var(--tile); border-radius: 999px;
  animation: meterGrow .7s cubic-bezier(.2, .8, .3, 1);
}
@keyframes meterGrow { from { width: 0 !important; } }

.commit-meta { font-size: 10px; color: var(--text-tertiary); margin-top: 5px; }

/* ---- to-do ---- */
.todo-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 6px; border-radius: 8px; cursor: pointer;
  border-bottom: 1px solid var(--separator);
  transition: background .15s ease;
}
.todo-row:last-child { border-bottom: 0; }
.todo-row:hover { background: rgba(120, 120, 128, .07); }
.todo-row.is-completing { opacity: .5; }

.todo-check {
  font-size: 15px; line-height: 1; color: var(--text-tertiary);
  transition: color .15s ease, transform .15s ease;
}
.todo-check:hover { color: var(--accent); transform: scale(1.15); }
.todo-check.is-done { color: var(--green); }

.todo-title { font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.todo-due { font-size: 10.5px; color: var(--text-tertiary); white-space: nowrap; }
.todo-due.is-overdue { color: var(--red); font-weight: 500; }

/* ============================================================
   Ask: full-page mode and the typing caret
   ============================================================ */

.ask-panel.is-full {
  right: 0; bottom: 0; left: 0; top: 0;
  width: 100%; height: 100dvh; max-height: none; max-width: none;
  border-radius: 0; border: 0;
  z-index: 175;
}
.ask-panel.is-full .ask-thread { padding: 28px max(24px, calc(50vw - 380px)); }
.ask-panel.is-full .ask-composer { padding: 16px max(24px, calc(50vw - 380px)); }
.ask-panel.is-full .ask-header { padding: 16px max(24px, calc(50vw - 380px)); }
.ask-panel.is-full .ask-bubble { max-width: 100%; font-size: 14px; }
.ask-panel.is-full .ask-answer { font-size: 14.5px; line-height: 1.7; }
.ask-panel.is-full .ask-media { grid-template-columns: repeat(3, 1fr); }
body.ask-fullpage { overflow: hidden; }

/* The blinking cursor while an answer is being written out. */
.ask-caret {
  display: inline-block;
  width: 2px; height: 1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: caretBlink 1s steps(1) infinite;
}
@keyframes caretBlink { 50% { opacity: 0; } }

/* ============================================================
   Contacts
   ============================================================ */

.contact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.contact-card {
  position: relative;
  padding: 16px 14px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  background: var(--material-thick);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  box-shadow: var(--shadow-sm);
  text-align: center;
  cursor: pointer;
  transition: transform .18s cubic-bezier(.2, .8, .3, 1), box-shadow .18s ease, border-color .18s ease;
}
.contact-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.contact-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.contact-pick { position: absolute; top: 10px; left: 10px; }

.contact-photo {
  width: 56px; height: 56px; margin: 0 auto 10px;
  border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 18px;
}
.contact-photo img { width: 100%; height: 100%; object-fit: cover; }

.contact-name { font-size: 13.5px; font-weight: 600; }
.contact-meta { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }

.contact-badges { margin-top: 8px; min-height: 18px; }
.contact-badge {
  display: inline-block; font-size: 9.5px; padding: 2px 7px;
  border-radius: 999px; background: rgba(120, 120, 128, .16); color: var(--text-secondary);
}
.contact-badge.is-user { background: rgba(48, 209, 88, .18); color: #1c7a35; }
html[data-theme="dark"] .contact-badge.is-user { color: #5fdd82; }
.contact-badge.is-muted { opacity: .65; }

.contact-actions {
  display: flex; justify-content: center; gap: 4px;
  margin-top: 10px; opacity: 0; transition: opacity .15s ease;
}
.contact-card:hover .contact-actions { opacity: 1; }
@media (hover: none) { .contact-actions { opacity: 1; } }

/* ============================================================
   Plans
   ============================================================ */

.plan-card { transition: transform .18s cubic-bezier(.2, .8, .3, 1), box-shadow .18s ease; }
.plan-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.plan-pill {
  font-size: 9.5px; padding: 2px 7px; border-radius: 999px; white-space: nowrap;
  background: rgba(120, 120, 128, .16); color: var(--text-secondary);
}
.plan-pill.is-action { background: var(--accent); color: #fff; }
.plan-pill.is-done { background: rgba(48, 209, 88, .2); color: #1c7a35; }
html[data-theme="dark"] .plan-pill.is-done { color: #5fdd82; }
.plan-pill.is-lead { background: rgba(255, 159, 10, .2); color: #b26800; }
html[data-theme="dark"] .plan-pill.is-lead { color: #ffb340; }

.plan-verdict { border-left: 3px solid var(--accent); }

.plan-person {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 4px; border-radius: 999px;
  background: rgba(120, 120, 128, .12);
  font-size: 11.5px;
  opacity: .6;
  transition: opacity .15s ease;
}
.plan-person.is-in { opacity: 1; background: var(--accent-soft); }
.plan-remove { color: var(--text-tertiary); font-size: 10px; }
.plan-remove:hover { color: var(--red); }

/* ---- ideas ---- */
.idea-card {
  display: flex; gap: 10px;
  padding: 10px; margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--separator);
  background: rgba(255, 255, 255, .45);
  transition: border-color .18s ease, transform .15s ease;
}
html[data-theme="dark"] .idea-card { background: rgba(255, 255, 255, .04); }
.idea-card:hover { transform: translateX(2px); }
.idea-card.is-leading { border-color: var(--orange); }
.idea-card.is-chosen { border-color: var(--green); box-shadow: 0 0 0 2px rgba(48, 209, 88, .18); }

.idea-photo {
  width: 62px; height: 62px; border-radius: 10px; overflow: hidden; flex-shrink: 0;
  background: rgba(120, 120, 128, .14);
  display: flex; align-items: center; justify-content: center;
}
.idea-photo img { width: 100%; height: 100%; object-fit: cover; }

.vote-btn {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: rgba(120, 120, 128, .14); color: var(--text-secondary);
  transition: background .15s ease, color .15s ease, transform .12s ease;
}
.vote-btn:hover:not(:disabled) { transform: scale(1.06); }
.vote-btn.is-on { background: var(--green); color: #fff; }
.vote-btn.is-against.is-on { background: var(--red); color: #fff; }
.vote-btn:disabled { opacity: .5; cursor: default; }

.idea-score { font-size: 11.5px; font-weight: 600; color: var(--text-tertiary); }
.idea-score.is-positive { color: var(--green); }
.idea-score.is-negative { color: var(--red); }

/* ---- times ---- */
.slot-row {
  padding: 10px; margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--separator);
  background: rgba(255, 255, 255, .45);
}
html[data-theme="dark"] .slot-row { background: rgba(255, 255, 255, .04); }
.slot-row.is-leading { border-color: var(--orange); }
.slot-row.is-chosen { border-color: var(--green); box-shadow: 0 0 0 2px rgba(48, 209, 88, .18); }

.slot-meter { height: 5px; border-radius: 999px; background: rgba(120, 120, 128, .16); overflow: hidden; }
.slot-meter > div {
  height: 100%; border-radius: 999px; background: var(--green);
  animation: meterGrow .6s cubic-bezier(.2, .8, .3, 1);
}

.avail-btn {
  flex: 1; font-size: 11px; padding: 4px 0; border-radius: 7px;
  background: rgba(120, 120, 128, .12); color: var(--text-secondary);
  transition: background .15s ease, color .15s ease;
}
.avail-btn:hover:not(:disabled) { background: rgba(120, 120, 128, .2); }
.avail-btn.avail-1.is-on { background: var(--green); color: #fff; }
.avail-btn.avail-2.is-on { background: var(--orange); color: #fff; }
.avail-btn.avail-3.is-on { background: var(--red); color: #fff; }
.avail-btn:disabled { opacity: .5; cursor: default; }

@media (max-width: 768px) {
  .contact-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .ask-panel.is-full .ask-thread,
  .ask-panel.is-full .ask-composer,
  .ask-panel.is-full .ask-header { padding-left: 14px; padding-right: 14px; }
}

/* ---------- Admin ---------- */
.admin-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--separator);
  background: rgba(255, 255, 255, .45);
  transition: border-color .15s ease;
}
html[data-theme="dark"] .admin-row { background: rgba(255, 255, 255, .04); }
.admin-row:hover { border-color: var(--accent); }

.admin-pill {
  font-size: 9px; padding: 1px 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); margin-left: 4px;
  vertical-align: middle;
}

/* ---------- Dashboard: current balance ---------- */
.balance-hero { border-left: 3px solid var(--accent); }

.balance-figure {
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: 1.1;
  margin-top: 2px;
}
.balance-figure.is-negative { color: var(--red); }

@media (max-width: 640px) {
  .balance-figure { font-size: 28px; }
}

/* ============================================================
   Money flow diagram
   ============================================================ */

.flow-wrap { width: 100%; overflow-x: auto; }
.flow-svg { width: 100%; min-width: 560px; height: auto; display: block; }

/* Bands grow out of nothing, in reading order left to right. */
.flow-band {
  transform-origin: left center;
  animation: flowGrow .55s cubic-bezier(.2, .85, .3, 1) both;
}
@keyframes flowGrow {
  from { transform: scaleX(0); opacity: 0; }
  to { transform: scaleX(1); opacity: 1; }
}

.flow-link { animation: flowFade .7s ease .25s both; }
@keyframes flowFade { from { opacity: 0; } }

.flow-label {
  font-size: 11px; font-weight: 600; fill: #fff;
  paint-order: stroke; letter-spacing: .01em;
}
.flow-value { font-size: 10px; fill: rgba(255, 255, 255, .85); }

/* ============================================================
   Month timeline
   ============================================================ */

.timeline-wrap { position: relative; width: 100%; overflow-x: auto; padding-bottom: 16px; }
.timeline-svg { width: 100%; min-width: 560px; height: 190px; display: block; }

/* The line draws itself across the month. */
.tl-line {
  stroke-dasharray: 2400;
  stroke-dashoffset: 2400;
  animation: tlDraw 1.1s cubic-bezier(.3, .8, .3, 1) .1s forwards;
}
@keyframes tlDraw { to { stroke-dashoffset: 0; } }

.tl-area { animation: tlFade .8s ease .5s both; }
@keyframes tlFade { from { opacity: 0; } }

.tl-marker { animation: tlPop .35s cubic-bezier(.2, .9, .3, 1.4) both; }
@keyframes tlPop { from { opacity: 0; transform: translateY(6px); } }

.tl-marker circle { cursor: help; transition: r .15s ease; }
.tl-marker circle:hover { r: 6.5; }

.tl-today { animation: tlFade .5s ease .9s both; }

.timeline-axis {
  position: relative; height: 14px; min-width: 560px;
  font-size: 10px; color: var(--text-tertiary);
}
.timeline-axis span { position: absolute; transform: translateX(-50%); }
.timeline-axis span.is-today { color: var(--orange); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .flow-band, .flow-link, .tl-line, .tl-area, .tl-marker, .tl-today {
    animation: none !important;
    stroke-dashoffset: 0 !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ============================================================
   Dashboard structure
   ============================================================ */

.dash-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}

.dash-jump { display: flex; gap: 6px; flex-wrap: wrap; }

.dash-jump-link {
  font-size: 12px; padding: 5px 11px; border-radius: 999px;
  background: var(--material-thin);
  border: 1px solid var(--separator);
  color: var(--text-secondary);
  text-decoration: none; white-space: nowrap;
  transition: background .15s ease, color .15s ease, transform .12s ease;
}
.dash-jump-link:hover {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent); transform: translateY(-1px);
}

.dash-section { margin-bottom: 22px; scroll-margin-top: 12px; }

.dash-section-head {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: left;
  padding: 6px 2px 10px;
  border-bottom: 1px solid var(--separator);
  margin-bottom: 14px;
  transition: border-color .15s ease;
}
.dash-section-head:hover { border-color: var(--accent); }
.dash-section-head:hover .dash-chevron { color: var(--accent); }

.dash-section-icon {
  font-size: 17px; line-height: 1;
  width: 32px; height: 32px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--material-thin);
  border: 1px solid var(--separator);
  flex-shrink: 0;
}

.dash-section-title {
  display: block; font-size: 15px; font-weight: 600;
  letter-spacing: -.01em; line-height: 1.2;
}
.dash-section-sub {
  display: block; font-size: 11.5px; color: var(--text-tertiary); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.dash-chevron {
  margin-left: auto; color: var(--text-tertiary); font-size: 13px;
  transition: color .15s ease;
}

/* Collapsing hides the body outright rather than animating a height, which
   would have to be measured and would fight the charts inside. */
.dash-section.is-collapsed .dash-section-body { display: none; }
.dash-section.is-collapsed .dash-section-head { margin-bottom: 0; }

.dash-section-body { animation: sectionIn .28s cubic-bezier(.2, .9, .3, 1); }
@keyframes sectionIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Security key prompt ---------- */
.passkey-nudge {
  position: fixed; right: 20px; bottom: 20px; z-index: 150;
  width: 340px; max-width: calc(100vw - 32px);
  padding: 14px 16px;
  background: var(--material-thick);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: nudgeIn .32s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes nudgeIn {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
}
.passkey-nudge.is-leaving {
  opacity: 0; transform: translateY(8px);
  transition: opacity .22s ease, transform .22s ease;
}

@media (max-width: 640px) {
  .passkey-nudge { right: 12px; left: 12px; bottom: 12px; width: auto; }
  .dash-jump { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .dash-section-sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dash-section-body, .passkey-nudge { animation: none; }
}

/* ============================================================
   Expense ledger
   ============================================================ */

.ledger-day { margin-bottom: 4px; }

.ledger-day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 10px 5px;
  font-size: 11.5px; font-weight: 600; color: var(--text-secondary);
  position: sticky; top: 0; z-index: 2;
  background: var(--material-thick);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.ledger-row {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  transition: background .15s ease, transform .12s ease;
}
.ledger-row:hover { background: rgba(120, 120, 128, .08); transform: translateX(2px); }
html[data-theme="dark"] .ledger-row:hover { background: rgba(255, 255, 255, .05); }

.ledger-icon {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}

/* ---- category chips in quick add ---- */
.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 128px; overflow-y: auto; }

.cat-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: rgba(120, 120, 128, .12);
  border: 1px solid transparent;
  color: var(--text-secondary);
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .12s ease;
}
.cat-chip:hover { transform: translateY(-1px); }
.cat-chip.is-on {
  background: color-mix(in srgb, var(--chip) 18%, transparent);
  border-color: var(--chip);
  color: var(--text);
  font-weight: 500;
}

/* Browsers without color-mix still need the selection to read clearly. */
@supports not (background: color-mix(in srgb, red 10%, transparent)) {
  .cat-chip.is-on { background: var(--accent-soft); border-color: var(--accent); }
}

.budget-chip {
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--separator);
  background: rgba(255, 255, 255, .45);
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}
html[data-theme="dark"] .budget-chip { background: rgba(255, 255, 255, .04); }
.budget-chip:hover { border-color: var(--accent); transform: translateY(-2px); }

/* ---------- Expense change approvals ---------- */
.change-row {
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--separator);
  background: rgba(255, 255, 255, .45);
}
html[data-theme="dark"] .change-row { background: rgba(255, 255, 255, .04); }

.chg-person {
  width: 22px; height: 22px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 600;
  background: rgba(120, 120, 128, .2); color: var(--text-secondary);
  border: 1.5px solid transparent;
}
.chg-person.is-yes { background: var(--green); color: #fff; }
.chg-person.is-no { background: var(--red); color: #fff; }

/* Row actions appear on hover; always visible on touch, where there is none. */
.ledger-actions {
  display: flex; gap: 2px; flex-shrink: 0;
  opacity: 0; transition: opacity .15s ease;
}
.ledger-row:hover .ledger-actions { opacity: 1; }
@media (hover: none) { .ledger-actions { opacity: .6; } }

.ledger-actions button {
  width: 24px; height: 24px; border-radius: 7px;
  font-size: 12px; color: var(--text-tertiary);
  transition: background .15s ease, color .15s ease;
}
.ledger-actions button:hover { background: rgba(120, 120, 128, .18); color: var(--text); }
.ledger-actions .led-del:hover { background: rgba(255, 69, 58, .16); color: var(--red); }
