/* ============================================================
   db2026  —  styles.css
   ============================================================ */

/* ── Z-index stacking order ─────────────────────────────────
   Everything with a z-index, this file and the styles app.js injects
   (verify with: grep -n 'z-index' public/css/styles.css public/js/app.js).
     0  .noon-rule — a real element, painted under the event blocks
     1  .event-block
     5  .notes-index (sticky letter index)
    10  .now-marker (current-time line, above the blocks)
    40  #event-fab           ← injected by showEventFab() in app.js
    49  #sidebar-backdrop (≤ 599px)
    50  #app-header; #app-sidebar drawer (≤ 599px)
    60  .tag-context-menu (this file's absolute-positioned rule)
    61  #offline-banner — sits above the FAB it has to clear
   100  #settings-modal-overlay; #ptr-indicator  ← injected by app.js
   150  #modal-overlay (edit modal)
   200  #user-menu, #mini-cal-picker, #ics-popup-overlay;
        .tag-context-menu again ← injected by app.js (position: fixed), and
        appended after this stylesheet, so 200 is the value that applies
   250  .ui-overlay (schedule popup)
   260  #ui-confirm-overlay — above the edit modal and the popup
   300  .ui-toast — above every overlay; it reports on what they just did
  2000  .tag-dropdown — LOCAL, not global: it renders inside #modal-overlay,
        which is position: fixed with z-index 150 and therefore its own
        stacking context, so this 2000 is ranked only against its siblings
        there and can never paint over the confirm at 260.
   ─────────────────────────────────────────────────────────── */

/* ── Variables ──────────────────────────────────────────────── */
:root {
  --bg:            #f0f2f5;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --border-light:  #f1f5f9;
  --text:          #1a202c;
  --text-muted:    #64748b;
  --text-light:    #6b7280;
  --primary:       #f97316;
  --primary-dk:    #ea580c;
  --primary-text:  #c2410c;   /* orange as TEXT: 5.2:1 on --surface, 4.6:1 on --bg (F17) */
  --danger:        #ef4444;
  --danger-dk:     #dc2626;
  --danger-text:   #b91c1c;   /* red as TEXT: 6.5:1 on --surface, 5.8:1 on --bg */
  --today-color:   #ef4444;
  --event-own:     #f97316;
  --event-own-text:#1a202c;   /* ink on the orange block: 5.8:1 */
  --event-locked:  #3b82f6;
  --event-locked-tint: #6ca1f8;   /* --event-locked at 75% over --surface (partner blocks) */
  --event-locked-text: #1a202c;   /* ink on the partner tint: 6.3:1 (F-17b ruling 2026-09-04) */
  --on-accent:     #ffffff;   /* text on --primary / --danger / --today-color grounds */
  --on-light:      #000000;   /* text on a light ground of unknown hue (textOn(): partner ICS tints) */
  --chip-bg:       #e5e7eb;   /* recurring-arrow badge + tentative blocks */
  --chip-border:   #888888;
  --chip-text:     #333333;
  --warn-bg:       #fef3c7;
  --warn-border:   #fcd34d;
  --warn-text:     #92400e;
  --header-bg:     #1e293b;
  --header-text:   #f8fafc;
  --now-line:      #ef4444;
  --toast-bg:      #1e293b;   /* toast ground: its own token so it stays distinct from --bg */
  --toast-text:    #f8fafc;
  --am-tint:       rgba(191,219,254,0.13);   /* calendar morning wash (applyNoonMarker) */
  --pm-tint:       rgba(254,215,170,0.10);   /* calendar afternoon wash */
  --swatch-ring:   rgba(255,255,255,0.55);   /* ICS colour swatch ring */
  /* RGB triplets for rgba() tints/shadows — the alphas stay at the use sites */
  --overlay-rgb:   15,23,42;
  --shadow-rgb:    0,0,0;
  --hover-rgb:     0,0,0;
  --header-fg-rgb: 255,255,255;
  --primary-rgb:   249,115,22;
  --locked-rgb:    59,130,246;
  --danger-rgb:    220,38,38;
  --muted-rgb:     100,116,139;
  --grid-line-rgb: 203,213,225;
  --grid-today-rgb:59,130,246;
  --now-line-rgb:  239,68,68;    /* the now-line stroke is translucent so text under it stays readable */
  --sidebar-w:     220px;
  --header-h:      52px;
  --time-col-w:    60px;
  --hour-h:        64px;      /* calendar grid: px per hour — must equal HOUR_H in app.js */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0f172a;
    --surface:       #1e293b;
    --border:        #334155;
    --border-light:  #263244;
    --text:          #e2e8f0;
    --text-muted:    #94a3b8;
    --text-light:    #8b96a8;
    --primary:       #f97316;
    --primary-dk:    #ea580c;
    --primary-text:  #fb923c;   /* 6.4:1 on --surface */
    --danger:        #ef4444;
    --danger-dk:     #dc2626;
    --danger-text:   #f87171;   /* 5.3:1 on --surface */
    --today-color:   #ef4444;
    --event-own:     #f97316;
    --event-own-text:#1a202c;
    --event-locked:  #3b82f6;
    --event-locked-tint: #346cc7;
    --event-locked-text: #ffffff;   /* white on the dark tint: 5.1:1 */
    --on-accent:     #ffffff;
    --on-light:      #000000;
    --chip-bg:       #334155;
    --chip-border:   #64748b;
    --chip-text:     #e2e8f0;
    --warn-bg:       #3b2a08;
    --warn-border:   #a16207;
    --warn-text:     #fde68a;
    --header-bg:     #0b1220;
    --header-text:   #f8fafc;
    --now-line:      #f87171;
    --toast-bg:      #334155;   /* lighter than --surface #1e293b: the box reads as a box */
    --toast-text:    #f8fafc;
    --am-tint:       rgba(30,58,138,0.18);
    --pm-tint:       rgba(120,53,15,0.16);
    --swatch-ring:   rgba(30,41,59,0.55);
    --overlay-rgb:   0,0,0;
    --shadow-rgb:    0,0,0;
    --hover-rgb:     255,255,255;
    --header-fg-rgb: 255,255,255;
    --primary-rgb:   251,146,60;
    --locked-rgb:    96,165,250;
    --danger-rgb:    248,113,113;
    --muted-rgb:     148,163,184;
    --grid-line-rgb: 51,65,85;
    --grid-today-rgb:96,165,250;
    --now-line-rgb:  248,113,113;
  }
}

/* ── Reset / Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { touch-action: manipulation; color-scheme: light dark; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  height: 100dvh;   /* Safari (non-PWA): don't let the toolbar cover the last hour + FAB (F-26) */
  overflow: hidden;
}

/* ── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Buttons ────────────────────────────────────────────────── */
button { cursor: pointer; font-size: 13px; font-family: inherit; border: none; background: none; }

button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-accent);
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary:hover  { background: var(--primary-dk); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 13px;
  border-radius: 6px;
}
.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: var(--danger);
  color: var(--on-accent);
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 500;
}
.btn-danger:hover { background: var(--danger-dk); }

.icon-btn {
  width: 32px; height: 32px;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  transition: background 0.12s;
}
.icon-btn:hover { background: rgba(var(--hover-rgb),0.07); }
.icon-btn.small { width: 24px; height: 24px; font-size: 14px; }

.nav-btn {
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--header-text);
  font-size: 18px;
  opacity: 0.8;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s;
}
.nav-btn:active { opacity: 1; background: rgba(var(--header-fg-rgb),0.1); }

/* Prev / next week arrows */
.nav-arrow {
  opacity: 1;
  padding: 4px 8px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.nav-arrow:active { background: rgba(var(--header-fg-rgb),0.18); }

/* "This Week" / "Today" — styled as a visible outlined button */
.today-btn {
  font-size: 13px;
  font-weight: 600;
  opacity: 1;
  padding: 4px 0;
  border: 1.5px solid rgba(var(--header-fg-rgb),0.45);
  border-radius: 6px;
  letter-spacing: 0.02em;
  text-align: center;
  width: 150px;
}
.today-btn.day-mode { width: 138px; }
.today-btn:active { border-color: rgba(var(--header-fg-rgb),0.8); background: rgba(var(--header-fg-rgb),0.12); }

/* Hover effects only on devices with a real pointer (prevents sticky hover on touch) */
@media (hover: hover) {
  .nav-btn:hover { opacity: 1; background: rgba(var(--header-fg-rgb),0.1); }
  .nav-arrow:hover { background: rgba(var(--header-fg-rgb),0.18); }
  .today-btn:hover { border-color: rgba(var(--header-fg-rgb),0.8); background: rgba(var(--header-fg-rgb),0.12); }
}

.error-msg {
  color: var(--danger-text);
  font-size: 12px;
  margin-top: 4px;
}

/* ── Offline banner (F-2) ───────────────────────────────────── */
/* Bottom-centre pill, clear of the event FAB (bottom-right, z 60). */
#offline-banner {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 61;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  font-size: 12px; font-weight: 500; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(var(--shadow-rgb),0.12);
  pointer-events: none;
}

/* ── Login ──────────────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
#login-card {
  background: var(--surface);
  padding: 40px 36px;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(var(--shadow-rgb),0.10);
  width: 340px;
  max-width: 92vw;
}
#login-card h1 { font-size: 26px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.login-subtitle { color: var(--text-muted); margin-bottom: 24px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 5px; color: var(--text); }
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb),0.12);
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

#login-btn, #code-submit-btn {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 10px;
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  background: var(--primary);
  color: var(--on-accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
#login-btn:hover, #code-submit-btn:hover { background: var(--primary-dk); }
#login-btn:disabled, #code-submit-btn:disabled { opacity: 0.6; cursor: default; }
/* "Sign in with your saved passkey" — a secondary text link (.btn-link) centred under the
   send-code button, with a full-height tap target. */
#pk-signin-link { display: block; margin: 10px auto 0; min-height: 44px; font-size: 14px; }

/* ── Code-entry input (sign-in code from email) ─────────────── */
#login-code {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
  padding: 12px 14px;
  font-size: 24px;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 4px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
#login-code:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb),0.12);
}

/* ── Check-email step ────────────────────────────────────────── */
.check-email-icon { font-size: 42px; text-align: center; margin-bottom: 10px; }
.check-email-title { font-size: 18px; font-weight: 600; text-align: center; margin-bottom: 6px; color: var(--text); }
.check-email-detail { font-size: 14px; text-align: center; color: var(--text); margin-bottom: 4px; }
.check-email-hint { font-size: 13px; text-align: center; color: var(--text-muted); margin-bottom: 16px; }
.check-email-sep { color: var(--text-muted); margin: 0 4px; }
.btn-link {
  background: none; border: none; cursor: pointer;
  color: var(--primary-text); font-size: 13px; padding: 0;
  text-decoration: underline;
}
.btn-link:hover { opacity: 0.8; }
.btn-link:disabled { opacity: 0.5; cursor: default; }

/* ── Header ─────────────────────────────────────────────────── */
#app-header {
  position: fixed; top: 0; left: 0; right: 0;
  /* On iOS with black-translucent status bar, the header extends behind the
     status bar. padding-top pushes content below it; height expands to match. */
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--header-bg);
  display: flex; align-items: center;
  padding-left: 12px; padding-right: 12px;
  gap: 8px;
  z-index: 50;
}
#header-left {
  display: flex; align-items: center; gap: 8px;
  flex: 1;
}
#header-left .icon-btn { color: rgba(var(--header-fg-rgb),0.7); }
#header-left .icon-btn:hover { background: rgba(var(--header-fg-rgb),0.1); }
#header-search {
  display: flex; align-items: center; gap: 6px;
  background: transparent;
  border: none;
  border-radius: 7px;
  padding: 5px 9px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
#header-search:hover { background: rgba(var(--header-fg-rgb),0.1); }
.header-search-icon { color: rgba(var(--header-fg-rgb),0.65); font-size: 15px; line-height: 1; }
.header-search-placeholder { color: rgba(var(--header-fg-rgb),0.65); font-size: 13px; white-space: nowrap; }
#header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
}
#header-right {
  display: flex; align-items: center; gap: 8px;
  flex: 1; justify-content: flex-end;
}
/* ── View toggle (day / week) ──────────────────────────────────── */
#view-toggle { display: flex; gap: 2px; align-items: center; }
.vt-btn {
  background: none; border: none; cursor: pointer;
  padding: 5px; border-radius: 5px;
  color: var(--header-text); opacity: 0.45;
  transition: opacity 0.15s, background 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.vt-btn:hover { opacity: 0.75; }
.vt-btn.active { opacity: 1; background: rgba(var(--header-fg-rgb),0.15); }

/* ── User avatar + dropdown ─────────────────────────────────────── */
#user-menu-wrap { position: relative; }
#user-avatar-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary);
  border: 2px solid rgba(var(--header-fg-rgb),0.25);
  color: var(--on-accent);
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
#user-avatar-btn:hover { opacity: 0.85; border-color: rgba(var(--header-fg-rgb),0.5); }
#user-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(var(--shadow-rgb),0.14);
  min-width: 180px;
  z-index: 200;
  overflow: hidden;
}
#user-menu-name {
  padding: 12px 16px 10px;
  font-size: 13px; font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.user-menu-item {
  display: block; width: 100%;
  padding: 9px 16px;
  text-align: left;
  background: none; border: none;
  font-size: 13px; color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
  box-sizing: border-box;
}
.user-menu-item:hover { background: var(--bg); }
.user-menu-item.danger { color: var(--danger-text); }

/* ── App layout ─────────────────────────────────────────────── */
#app-layout {
  display: flex;
  /* Fixed to viewport so body rubber-band bounce can't carry it behind the header.
     top matches header height + iOS safe-area-inset-top. */
  position: fixed;
  top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  bottom: 0;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
#app-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: width 0.2s ease, opacity 0.2s ease;
}
#app-sidebar.closed {
  width: 0;
  opacity: 0;
  overflow: hidden;
}

/* Mini calendar */
#mini-cal { padding: 12px 10px 8px; position: relative; }
#mini-cal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
#mini-cal-label {
  font-size: 12px; font-weight: 600; color: var(--text);
  cursor: pointer; border-radius: 4px; padding: 2px 6px;
  transition: background 0.15s, color 0.15s;
}
#mini-cal-label:hover { background: rgba(var(--locked-rgb),0.1); color: var(--primary-text); }
#mini-cal-header .icon-btn { color: var(--text-muted); }

/* Month/year picker popup */
#mini-cal-picker {
  position: absolute;
  top: 36px; left: 4px; right: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(var(--shadow-rgb),0.13);
  padding: 10px 8px 8px;
  z-index: 200;
}
.mcp-year-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
#mcp-year { font-size: 13px; font-weight: 700; color: var(--text); }
.mcp-months {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px;
}
.mcp-month {
  display: flex; align-items: center; justify-content: center;
  padding: 6px 0; font-size: 12px; border-radius: 5px;
  cursor: pointer; transition: background 0.1s; color: var(--text);
}
.mcp-month:hover { background: var(--bg); }
.mcp-active { background: var(--primary) !important; color: var(--on-accent); font-weight: 600; }

#mini-cal-grid { user-select: none; }
.mc-row { display: grid; grid-template-columns: repeat(7, 1fr); }
.mc-cell {
  display: flex; align-items: center; justify-content: center;
  height: 26px;
  font-size: 11px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.1s;
}
.mc-cell:empty { cursor: default; }
.mc-dow { color: var(--text-muted); font-weight: 600; cursor: default; border-radius: 0; }
.mc-day { position: relative; touch-action: manipulation; }
.mc-day:hover { background: var(--bg); }
.mc-today  { background: var(--today-color) !important; color: var(--on-accent) !important; border-radius: 50%; }
.mc-active { background: var(--primary) !important; color: var(--on-accent) !important; border-radius: 50%; }
.mc-inweek { background: transparent; border-radius: 0; }
.mc-inweek.mc-today  { border-radius: 50%; }
.mc-inweek.mc-active { border-radius: 50%; }
.mc-inweek-row {
  background: rgba(var(--locked-rgb),0.15);
  border-radius: 4px;
  border-top: 1px solid rgba(var(--locked-rgb),0.28);
  border-bottom: 1px solid rgba(var(--locked-rgb),0.28);
}


/* Sidebar divider + section */
.sidebar-divider { height: 1px; background: var(--border); margin: 0 0 4px; }
#sidebar-databases { padding: 0 0 12px; position: relative; }
.sidebar-section-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px 4px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-light);
}
.db-item {
  padding: 7px 12px;
  cursor: pointer;
  touch-action: manipulation;
  font-size: 13px;
  color: var(--text);
  border-radius: 0;
  display: flex; align-items: center; gap: 6px;
  transition: background 0.1s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.db-item:hover { background: var(--bg); }
.db-item:active { background: var(--bg); }
.db-item.active { background: rgba(var(--primary-rgb),0.1); color: var(--primary-text); font-weight: 500; }

/* ── Main content area ──────────────────────────────────────── */
#app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Week view ───────────────────────────────────────────────── */
#week-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#week-header {
  display: grid;
  grid-template-columns: var(--time-col-w) repeat(7, 1fr);
  border-bottom: 2px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.week-header-spacer {
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding-bottom: 4px;
}
.whs-month {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1;
}
.whs-year {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  opacity: 0.7;
  line-height: 1;
}
.day-header {
  padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
.day-header-name { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); }
.day-header-num  { font-size: 20px; font-weight: 300; color: var(--text); line-height: 1; }
.day-header.today .day-header-num {
  background: var(--today-color);
  color: var(--on-accent);
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600;
}

/* ── All-day strip (between header and time grid) ─────────────── */
#week-allday {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-height: 24px;
}
.allday-spacer {
  width: var(--time-col-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 4px 6px 0 0;
  line-height: 1;
}
#allday-cols {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.allday-col {
  min-width: 0;
  padding: 3px 3px 3px 2px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  gap: 2px;
  overflow: hidden;
}
.allday-col:last-child { border-right: 1px solid var(--border); }
.allday-event {
  flex: 1 1 0;
  min-width: 0;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 12px;
  font-weight: 600;
  line-height: 12px;
  color: var(--event-own-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  background: var(--event-own);
  transition: filter 0.1s;
}
.allday-event:hover     { filter: brightness(1.08); }
.allday-event:active    { filter: brightness(0.93); }
.event-recurring::before { content: "↻"; display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%; background: var(--chip-bg); border: 1px solid var(--chip-border);
  font-size: 10px; margin-right: 3px; flex-shrink: 0; color: var(--chip-text); }
.allday-event.event-locked    { background: var(--event-locked); opacity: 0.75; color: var(--event-locked-text); }
.event-tentative {
  background: var(--chip-bg) !important;
  border: 2px solid var(--event-own) !important;
  color: var(--chip-text) !important;
}
.event-tentative.event-locked {
  border-color: var(--event-locked) !important;
}

#week-body {
  display: flex;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  overscroll-behavior-y: contain;
}

#time-labels {
  width: var(--time-col-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border-light);
}
.time-label {
  height: var(--hour-h);
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 3px 8px 0 0;
  font-size: 11px; color: var(--text-light);
  border-top: 1px solid var(--border-light);
}
.time-label:first-child { border-top: none; }
.time-label-noon {
  font-weight: 600; color: var(--text);
  position: relative; border-top: none;
}
.time-label-noon::before {
  content: '';
  position: absolute;
  top: -1px; left: 0; right: 0;
  height: 2px;
  background: rgba(var(--muted-rgb),0.55);
}

#day-columns {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.day-col {
  position: relative;
  border-left: 1px solid var(--border);
  cursor: pointer;
  /* Grid lines + noon marker + AM/PM tint set by applyNoonMarker() in JS */
  /* Suppress iOS native long-press behaviors (text-selection magnifier,
     copy/paste callout) so our JS long-press is the only thing that fires
     when the user holds on empty calendar space. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.day-col:last-child { border-right: 1px solid var(--border); }
.day-col.day-today {
  background-color: rgba(var(--locked-rgb),0.05);
}

/* Noon rule — sits behind event blocks */
.noon-rule {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: rgba(var(--muted-rgb),0.55);
  z-index: 0;
  pointer-events: none;
}
/* Current-time line across today's column — positioned by applyNoonMarker(), moved
   every minute by the interval at the end of app.js */
.now-marker {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  margin-top: -1px;
  z-index: 10;
  pointer-events: none;
  /* Half-alpha stroke: it sits above event text, so it must not hide it.
     The dot (::before) stays solid — it lives in the gutter, over nothing. */
  background: rgba(var(--now-line-rgb),0.5);
}
.now-marker::before {
  content: '';
  position: absolute;
  left: -4px; top: -3px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--now-line);
}

/* Event blocks */
.event-block {
  position: absolute;
  z-index: 1;
  /* left/right/width set by layoutOverlaps() in JS */
  border-radius: 4px;
  padding: 1px 5px;
  overflow: hidden;
  cursor: pointer;
  color: var(--event-own-text);
  font-size: 12px;
  font-weight: 600;
  line-height: 13px;
  box-shadow: 0 1px 3px rgba(var(--shadow-rgb),0.15);
  background: var(--event-own);
  box-sizing: border-box;
  transition: filter 0.1s;
  user-select: none;
}
.event-block:hover { filter: brightness(1.08); }
.event-block:active { filter: brightness(0.93); }
.event-block.event-locked {
  background: var(--event-locked-tint);   /* opaque, so the noon rule is hidden */
  color: var(--event-locked-text);
}

/* ── Database view ───────────────────────────────────────────── */
#db-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
#db-view-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
#db-view-header h2 { font-size: 16px; font-weight: 600; }
#db-view-content {
  flex: 1;
  overflow: auto;
  padding: 16px 20px;
}


.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state p { margin-bottom: 12px; }
.empty-state-hint { font-size: 13px; opacity: 0.75; }

/* ── Record detail view ──────────────────────────────────────── */
.record-detail { max-width: 720px; }

.detail-back-bar {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border);
}
.detail-title {
  flex: 1;
  font-size: 20px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.detail-edit-btn { margin-left: auto; flex-shrink: 0; }
.detail-delete-btn { flex-shrink: 0; margin-left: 6px; padding: 6px 10px; font-size: 14px; }

.detail-field {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border-light);
  align-items: baseline;
}
.detail-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
  padding-top: 1px;
}
.detail-value {
  color: var(--text);
  line-height: 1.65;
  white-space: normal;
  word-break: break-word;
}
.date-link {
  color: var(--primary-text);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}
.date-link:hover { text-decoration: underline; }
.detail-timestamps {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 18px;
}

/* ── Note History ───────────────────────────────────────────── */
.note-history-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}
.note-history-toggle {
  font-size: 12px;
  color: var(--text-muted);
}
.history-list {
  margin-top: 8px;
}
.history-item {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
}
.history-item:hover { background: var(--bg); }
.history-date {
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 130px;
}
.history-title {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-viewer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-light);
}
.history-viewer-label {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Sidebar search inputs ───────────────────────────────────── */
.sidebar-search {
  padding: 8px 10px 4px;
}
.sidebar-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.sidebar-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb),0.12);
}

/* ── Directory list count badge in headers ──────────────────── */
.dir-count {
  color: var(--text-muted);
  font-size: 0.75em;
  font-weight: 400;
  margin-left: 6px;
}

/* ── Schedule popup (directory-list → event detail) — overlay/box: .ui-overlay/.dialog ── */
.sched-popup-close {
  position: absolute; top: 8px; right: 8px;
  font-size: 18px; line-height: 1;
}
.sched-popup-title {
  font-size: 16px; font-weight: 600;
  color: var(--text);
  padding-right: 28px;
  margin-bottom: 10px;
}
.sched-popup-row {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.sched-popup-desc {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}
.sched-popup-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.sched-popup-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--border-light);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 6px;
}

/* ── Feedback layer (2026-09-04): overlay, dialog / sheet, toast ──────────── */
/* .ui-overlay + .dialog generalise the schedule popup's overlay/box; .sheet makes a
   .dialog present as a bottom sheet on viewports ≤ 640px. Behaviour: js/ui.js. */
.ui-overlay {
  position: fixed; inset: 0;
  background: rgba(var(--overlay-rgb),0.5);
  z-index: 250;
  display: none;
  align-items: center; justify-content: center;
  padding: 16px;
}
#ui-confirm-overlay { z-index: 260; }   /* above the edit modal (150) and the schedule popup (250) */
.dialog {
  background: var(--surface);
  border-radius: 12px;
  width: 420px;
  max-width: 100%;
  padding: 18px 20px 14px;
  box-shadow: 0 24px 64px rgba(var(--shadow-rgb),0.25);
  border: 1px solid var(--border);
  position: relative;
  outline: none;
}
.dialog-title {
  font-size: 16px; font-weight: 600;
  color: var(--text);
  padding-right: 28px;
  margin-bottom: 10px;
}
.dialog-body {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.dialog-actions {
  margin-top: 14px;
  display: flex;
  flex-direction: row-reverse;   /* DOM: confirm first; visual: … Cancel · Confirm */
  gap: 8px;
  justify-content: flex-start;
}
@keyframes ui-slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@media (max-width: 640px) {
  .ui-overlay { align-items: flex-end; padding: 0; }
  .dialog.sheet {
    width: 100%; max-width: none;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    padding: 20px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    animation: ui-slide-up 0.2s ease-out;
  }
  .dialog.sheet .dialog-actions { flex-direction: column; }
  /* DOM order is Edit, Go to event — column-reverse puts the primary on top, matching
     the confirm sheet's row-reverse. */
  .dialog.sheet .sched-popup-actions { flex-direction: column-reverse; }
  .dialog.sheet .dialog-actions button,
  .dialog.sheet .sched-popup-actions button { width: 100%; padding: 12px; font-size: 16px; }
}
.ui-toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 300;
  max-width: min(480px, calc(100vw - 32px));
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 12px 12px 14px;
  border-radius: 10px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: 0 8px 24px rgba(var(--shadow-rgb),0.2);
  font-size: 14px; line-height: 1.4;
}
.ui-toast-error { border-left: 4px solid var(--danger); }
.ui-toast-ok    { border-left: 4px solid var(--primary); }
.ui-toast-close {
  background: none; border: none; color: inherit;
  font-size: 18px; line-height: 1; cursor: pointer;
  padding: 0 2px; opacity: 0.8; flex-shrink: 0;
}
.ui-toast-close:hover { opacity: 1; }
@media (max-width: 640px) {
  .ui-toast {
    left: 16px; right: 16px; transform: none; max-width: none;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));   /* clear the FAB */
  }
}

/* ── Edit Modal ──────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(var(--overlay-rgb),0.4);
  z-index: 150;
  display: flex; align-items: center; justify-content: center;
}
#modal-box {
  background: var(--surface);
  border-radius: 12px;
  width: 520px;
  max-width: 96vw;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(var(--shadow-rgb),0.20);
  border: 1px solid var(--border);
  /* Default to non-selectable chrome so a touch-long-press that opens the
     modal under the user's finger doesn't trigger an iOS text-selection
     callout on labels/titles. Inputs/textareas re-enable selection below. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#modal-box input, #modal-box textarea, #modal-box select,
#modal-box [contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
#modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#modal-title { font-size: 15px; font-weight: 600; }
.modal-close-btn { color: var(--text-muted); font-size: 20px; }

#modal-body {
  flex: 1; overflow-y: auto;
  padding: 18px 18px 8px;
}
#modal-timestamps {
  padding: 4px 18px 2px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  flex-shrink: 0;
}
#modal-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px max(12px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.footer-spacer { flex: 1; }

/* Form elements inside modal */
#modal-body .form-group { margin-bottom: 8px; }
#modal-body .form-group label { margin-bottom: 3px; font-size: 12px; }
#modal-body input[type="text"],
#modal-body input[type="date"],
#modal-body textarea {
  display: block;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  box-sizing: border-box;
}
#modal-body input:focus, #modal-body textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb),0.12);
}
#modal-body .form-row { display: flex; gap: 10px; }
#modal-body .form-row .form-group { flex: 1; }
#modal-body textarea {
  resize: none;
  min-height: 90px;
  line-height: 1.55;
  overflow-y: hidden; /* let auto-resize control height; scrollbar only when capped */
}

.locked-notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--warn-text);
  font-size: 12px;
  margin-bottom: 12px;
}

/* ── Schedule edit modal — time selects ────── */
.time-selects { display: inline-flex; align-items: center; gap: 2px; }
#modal-body .time-selects select { width: auto; min-width: 0; display: inline-block; padding: 5px 2px; }
.time-colon { font-weight: 600; padding: 0 1px; }

/* ── Schedule edit modal — recurring toggle & pattern picker ────── */
.sched-options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 6px 0;
  font-size: 12px;
  color: var(--text);
  user-select: none;
}
.sched-options-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.sched-options-row input[type="checkbox"] {
  width: 14px; height: 14px;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.sched-recur-on { margin-bottom: 12px; }
.recur-on-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
label.radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 13px;
  min-width: 52px;
  color: var(--text);
  font-weight: normal;
  margin-bottom: 0;
}
label.radio-label input[type="radio"] { cursor: pointer; accent-color: var(--primary); width: auto !important; padding: 0 !important; }
#sched-day { width: 64px !important; }
#sched-week, #sched-weekday { width: auto !important; flex: 1 1 auto; min-width: 0; } /* Safari: !important needed to beat #modal-body select{width:100%} on <select> */
#modal-body select {
  display: block;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  box-sizing: border-box;
}
#modal-body select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb),0.12);
}
/* Stack time+duration on narrow screens to prevent overlap */
@media (max-width: 599px) {
  #modal-body .form-row.sched-time-group { flex-direction: column; gap: 0; }
}

/* ── Date picker row ─────────────────────────────────────────── */
.date-picker-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  position: relative;
  height: 30px;
}
.date-step-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 0 8px;
  font-size: 12px;
  line-height: 1;
  user-select: none;
  transition: background 0.1s;
  box-sizing: border-box;
}
.date-step-btn:first-child { border-radius: 6px 0 0 6px; }
.date-step-btn:last-of-type { border-radius: 0 6px 6px 0; border-left: none; }
.date-step-btn:hover { background: var(--bg); }
.date-step-btn:active { background: var(--border); }
.date-input-inline {
  flex: 1;
  text-align: center;
  padding: 0 6px !important;
  font-size: 13px !important;
  font-weight: 600;
  line-height: 1 !important;
  color: var(--text);
  border: 1px solid var(--border) !important;
  border-left: none !important;
  border-right: none !important;
  border-radius: 0 !important;
  background: var(--surface);
  cursor: pointer;
  min-width: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  display: flex !important;
  align-items: center;
  justify-content: center;
}
.date-dow-label {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}

/* ── Sidebar tag count badge ─────────────────────────────────── */
.tag-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
  margin-left: auto;
  flex-shrink: 0;
}
.db-item-tag { padding-left: 10px; }

/* ── Notes list (directory style) ────────────────────────────── */
.notes-index {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 2px;
  margin-bottom: 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.notes-index-btn {
  flex: 0 0 auto;
  min-width: 22px;
  padding: 2px 4px;
  border: none;
  background: transparent;
  color: var(--primary-text);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  font-family: inherit;
}
.notes-index-btn:not(:disabled):hover { background: rgba(var(--hover-rgb),0.05); }
.notes-index-btn:disabled {
  color: var(--text-muted);
  opacity: 0.3;
  cursor: default;
}

.notes-dir-list {
  padding: 0 0 16px 0;
}
.notes-dir-section {
  margin-bottom: 12px;
  scroll-margin-top: 44px;  /* offset so jump lands below the sticky index bar */
}
.notes-dir-letter {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 8px 5px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 4px;
  background: var(--bg);
}
.notes-dir-item {
  padding: 6px 12px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notes-dir-item:hover { background: rgba(var(--hover-rgb),0.05); color: var(--primary-text); }
.notes-dir-item:active { background: var(--border-light); }
.notes-dir-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  background: rgba(var(--primary-rgb),0.08);
  color: var(--primary-text);
}

/* ── Tag chips (detail view) ─────────────────────────────────── */
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  margin-bottom: 6px;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  background: rgba(var(--primary-rgb),0.1);
  color: var(--primary-text);
  border: 1px solid rgba(var(--primary-rgb),0.25);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Tag editor (edit modal) ─────────────────────────────────── */
.note-tags-row { margin-bottom: 10px; }

.note-tags-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 0 2px;
}
.tag-chip-edit {
  display: inline-flex;
  align-items: center;
  background: rgba(var(--primary-rgb),0.1);
  color: var(--primary-text);
  border: 1px solid rgba(var(--primary-rgb),0.25);
  border-radius: 12px;
  padding: 2px 4px 2px 10px;
  font-size: 11px;
  font-weight: 500;
  gap: 3px;
  white-space: nowrap;
}
.tag-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: var(--primary-text);
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.1s, background 0.1s;
}
.tag-chip-remove:hover {
  opacity: 1;
  background: rgba(var(--primary-rgb),0.2);
}
.note-tag-input {
  flex: 1;
  min-width: 110px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  background: var(--surface);
}
.note-tag-input:focus { border-color: var(--primary); }

/* ── Note field rows (edit modal) ────────────────────────────── */
.note-field-row { position: relative; margin-bottom: 10px; }

.note-field-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}


/* ── Sidebar tag management buttons ─────────────────────────── */
.tag-item-actions {
  display: none;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
}
.db-item-tag:hover .tag-item-actions {
  display: inline-flex;
}
.tag-action-btn {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
  padding: 0;
  line-height: 1;
}
.tag-action-btn:hover {
  opacity: 1;
  background: rgba(var(--hover-rgb),0.07);
  color: var(--text);
}
.tag-action-del:hover {
  background: rgba(var(--danger-rgb),0.1);
  color: var(--danger-text);
}

/* ── Inline tag rename / delete confirm ─────────────────────────── */
.tag-rename-input {
  flex: 1;
  min-width: 0;
  width: 100px;
  padding: 2px 6px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
}
.tag-del-confirm {
  flex: 1;
  font-size: 11px;
  color: var(--danger-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Tag input custom dropdown ───────────────────────────────── */
.tag-input-wrap {
  position: relative;
  flex: 1;
  min-width: 110px;
}
.tag-dropdown {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  min-width: 180px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(var(--shadow-rgb),0.14);
  z-index: 2000;
}
.tag-dropdown-item {
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tag-dropdown-item:hover { background: var(--bg); }
.tag-dropdown-new {
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ── Address field display ──────────────────────────────────────────── */
.addr-display {
  font-style: normal;
  line-height: 1.6;
  color: var(--text);
  margin: 0;
}

/* ── Address field edit sub-form ────────────────────────────────────── */
.addr-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.addr-part {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  width: 100%;
  box-sizing: border-box;
}
.addr-part:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(var(--primary-rgb),0.12);
}
.addr-csz {
  display: flex;
  gap: 5px;
}
.addr-city  { flex: 2; min-width: 0; }
.addr-state { flex: 1; min-width: 0; }
.addr-zip   { flex: 1; min-width: 0; }


/* ── Change-password modal ──────────────────────────────────────── */
/* .pw-error is reused by the Settings/ICS modal — keep it */
.pw-error {
  font-size: 13px;
  color: var(--danger-text);
  padding: 6px 10px;
  background: rgba(var(--danger-rgb),0.07);
  border-radius: 6px;
  border: 1px solid rgba(var(--danger-rgb),0.18);
}

/* ── Ingredient field ─────────────────────────────────────── */
.ingr-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ingr-header {
  display: flex;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.ingr-col-amt  { flex: 0 0 70px; }
.ingr-col-meas { flex: 0 0 130px; }
.ingr-col-ingr { flex: 1; min-width: 0; }
.ingr-col-btn  { flex: 0 0 20px; } /* matches .ingr-remove-btn */
.ingr-rows { display: flex; flex-direction: column; gap: 3px; }
.ingr-row {
  display: flex;
  gap: 4px;
  align-items: center;
}
/* Use ID-level specificity to beat #modal-body input[type="text"] { width: 100% } */
#modal-body .ingr-row .ingr-amount { flex: 0 0 70px; width: 70px; }
#modal-body .ingr-row .ingr-measure    { flex: 0 0 130px; width: 130px; }
#modal-body .ingr-row .ingr-ingredient { flex: 1; width: auto; min-width: 0; }
.ingr-amount,
.ingr-measure,
.ingr-ingredient {
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  box-sizing: border-box;
}
.ingr-amount:focus,
.ingr-measure:focus,
.ingr-ingredient:focus { outline: none; border-color: var(--primary); }
.ingr-remove-btn {
  flex-shrink: 0;
  width: 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 0;
  line-height: 1;
  text-align: center;
  border-radius: 3px;
}
.ingr-remove-btn:hover { color: var(--danger-text); background: rgba(var(--danger-rgb),0.08); }
.ingr-add-btn {
  margin-top: 5px;
  align-self: flex-start;
  padding: 4px 10px;
  font-size: 12px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
}
.ingr-add-btn:hover { border-color: var(--primary); color: var(--primary-text); }

/* Multi-value separators in detail view */
.detail-value-item + .detail-value-item {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid var(--border-light);
}
/* Ingredients form a natural list — spacing only, no line */
.detail-value-item.dvi-ingredient + .detail-value-item.dvi-ingredient {
  margin-top: 2px;
  padding-top: 0;
  border-top: none;
}

/* ── Canonical type sections (edit modal) ────────────────────── */
.note-type-section { margin-bottom: 14px; }
.type-section-header { margin-bottom: 4px; }
.type-section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted);
}

/* Value rows */
.value-rows { display: flex; flex-direction: column; gap: 5px; }
.value-row { display: flex; align-items: flex-start; gap: 6px; }
.value-row input[type="text"],
.value-row input[type="email"],
.value-row input[type="date"],
.value-row textarea {
  flex: 1; min-width: 0;
}
.value-row-remove {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 16px; padding: 4px 2px;
  flex-shrink: 0; line-height: 1;
}
.value-row-remove:hover { color: var(--danger-text); }

/* Phone / Email label dropdowns */
/* Use #modal-body to beat the existing "#modal-body select { width:100% }" rule */
#modal-body .mv-label-select {
  width: 84px; flex-shrink: 0; padding: 5px 4px;
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 12px; color: var(--text); background: var(--surface);
}

/* Address value rows */
.addr-value-row { align-items: flex-start; }
.addr-value-inner { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
#modal-body .addr-label-input { width: 120px; flex-shrink: 0; }

/* Add-value link (inside a type section) */
.add-value-btn {
  font-size: 12px; color: var(--primary-text); background: none;
  border: none; cursor: pointer; padding: 3px 0; display: inline-block;
}
.add-value-btn:hover { text-decoration: underline; }

/* Add-type button bar */
.add-type-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 14px; padding-top: 10px;
  border-top: 1px solid var(--border);
}
.add-type-btn {
  font-size: 12px; color: var(--primary-text); background: none;
  border: 1px solid var(--primary); border-radius: 12px;
  padding: 3px 10px; cursor: pointer;
}
.add-type-btn:hover { background: rgba(var(--locked-rgb),0.07); }

/* Sub-label in display view (phone/email/address) */
.mv-label {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.03em;
  min-width: 52px; display: inline-block;
}

/* ── Settings modal (external calendar feeds) ────────────────────────── */
#settings-modal-overlay {
  position: fixed; inset: 0; background: rgba(var(--overlay-rgb),0.3);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#settings-modal-box {
  background: var(--surface); border-radius: 12px;
  box-shadow: 0 10px 40px rgba(var(--shadow-rgb),0.15); width: 90%; max-width: 400px;
}
#settings-modal-header {
  padding: 20px; border-bottom: 1px solid var(--border);
  font-weight: 600; display: flex; justify-content: space-between; align-items: center;
}
#settings-modal-body { padding: 20px; max-height: calc(65vh - 120px); overflow-y: auto; }
#settings-modal-footer {
  padding: 16px 20px max(12px, env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border-light);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ── Day view ──────────────────────────────────────────────── */
#week-view.day-view-mode #week-header  { grid-template-columns: var(--time-col-w) 1fr; }
#week-view.day-view-mode #day-columns  { grid-template-columns: 1fr; }
#week-view.day-view-mode #allday-cols  { grid-template-columns: 1fr; }

/* ICS calendar events */
.ics-event-block { font-style: italic; }  /* opacity removed — see inline bg */
.ics-allday { opacity: 0.9; font-style: italic; }

/* ── ICS Feeds section (rendered inside the Settings modal) ─── */
.ics-section-title { font-weight: 600; font-size: 13px; margin: 18px 0 10px; border-top: 1px solid var(--border-light); padding-top: 14px; }
.audit-list { max-height: 220px; overflow-y: auto; }
.audit-row { display: flex; gap: 10px; justify-content: space-between; font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.audit-when { color: var(--text-muted); }
.audit-ip { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.audit-empty { color: var(--text-muted); font-size: 13px; padding: 6px 0; }
.ics-list-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border-light); font-size: 13px; }
.ics-swatch-edit { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; cursor: pointer; border: 2.5px solid var(--swatch-ring); outline: none; transition: transform 0.1s, border-color 0.1s; position: relative; }
.ics-swatch-edit:hover { transform: scale(1.25); border-color: var(--surface); }
.ics-inline-picker { display: flex; gap: 7px; flex-wrap: wrap; padding: 8px 10px; background: var(--bg); border-radius: 6px; margin: -2px 0 4px 0; border: 1px solid var(--border); }
.ics-inline-picker.hidden { display: none; }
.ics-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ics-delete { color: var(--danger-text); background: none; border: none; cursor: pointer; font-size: 12px; }
.ics-add-form { margin-top: 12px; }
.ics-add-form input { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; margin-bottom: 7px; box-sizing: border-box; }
.ics-color-row { display: flex; gap: 7px; margin-bottom: 8px; flex-wrap: wrap; }
.ics-color-swatch { width: 24px; height: 24px; border-radius: 50%; cursor: pointer; border: 2.5px solid transparent; outline: none; transition: transform 0.1s; }
.ics-color-swatch.selected { border-color: var(--surface); box-shadow: 0 0 0 2.5px var(--text); }
.ics-color-swatch:hover { transform: scale(1.2); }
.ics-add-btn { width: 100%; }

/* ── Mobile layout ─────────────────────────────────────────── */
@media (max-width: 599px) {
  #app-header { padding: 0 8px; }
  /* Prevent iOS auto-zoom on input focus (triggers when font-size < 16px) */
  input, textarea, select { font-size: 16px !important; }
  /* Collapse search to icon-only on narrow screens */
  .header-search-placeholder { display: none; }

  #app-sidebar {
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
    left: 0;
    height: calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px));
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 50;
    box-shadow: 2px 0 12px rgba(var(--shadow-rgb),0.15);
    overflow-y: auto;
  }
  #app-sidebar.open { transform: translateX(0); }

  #sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
    background: rgba(var(--overlay-rgb),0.3);
    z-index: 49;
  }
  #sidebar-backdrop.visible { display: block; }

  /* 11a — Larger touch targets for mini calendar */
  .mc-cell { height: 36px; }

  /* 11b — Bigger mini-cal nav arrows */
  #mini-cal .icon-btn.small { min-width: 36px; min-height: 36px; }

  /* 11c — Stacked detail fields (label above value) */
  .detail-field {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .detail-label { font-weight: 600; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
  .detail-value { padding-left: 0; }

  /* 11d — Bigger remove buttons on mobile */
  .tag-chip-remove { width: 20px; height: 20px; font-size: 14px; }

  /* 11e — Ingredient row stacks on mobile: amt+meas on row 1, ingredient+btn on row 2 */
  .ingr-row { flex-wrap: wrap; }
  .ingr-col-amt { flex: 0 0 80px; }
  .ingr-col-meas { flex: 1 1 auto; }
  .ingr-col-ingr { flex: 1 1 100%; min-width: 0; }
}

/* ── Tablet breakpoint ─────────────────────────────────────────────────── */
@media (min-width: 600px) and (max-width: 899px) {
  /* Slightly narrower sidebar to give more room to calendar columns */
  #app-sidebar { width: 190px; }
  /* Tighter event blocks to fit narrower columns */
  .event-block { padding: 1px 4px; }
}

/* ── Touch device fixes ─────────────────────────────────────────────────── */
/* On touch devices :hover fires on tap-then-click, which reveals the tag
   action buttons mid-tap. Those buttons have stopPropagation, so the parent
   onclick never fires. Suppress the hover-reveal on non-hovering devices. */
@media (hover: none) {
  .db-item-tag:hover .tag-item-actions { display: none; }
}

/* ── ICS event popup ─────────────────────────────────────────────────────── */
#ics-popup-overlay {
  position: fixed; inset: 0; background: rgba(var(--overlay-rgb),0.35);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
#ics-popup-overlay.hidden { display: none; }
#ics-popup-box {
  background: var(--surface); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(var(--shadow-rgb),0.2);
  width: 90%; max-width: 380px; padding: 20px 22px 18px;
  position: relative;
}
.ics-popup-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; font-size: 20px; line-height: 1;
  cursor: pointer; color: var(--text-muted); padding: 2px 6px;
}
.ics-popup-close:hover { color: var(--text); }
.ics-popup-title {
  font-size: 16px; font-weight: 600; margin-bottom: 10px; padding-right: 24px;
  color: var(--text); line-height: 1.3;
}
.ics-popup-meta {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-muted); margin-bottom: 8px;
}
.ics-popup-swatch {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.ics-popup-date {
  font-size: 13px; color: var(--text); margin-bottom: 6px;
}
.ics-popup-location {
  font-size: 12px; color: var(--text-muted); margin-top: 6px;
  word-break: break-word;
}
.ics-popup-desc {
  font-size: 12px; color: var(--text-muted); margin-top: 10px;
  border-top: 1px solid var(--border-light); padding-top: 10px;
  white-space: pre-wrap; max-height: 160px; overflow-y: auto;
  word-break: break-word; line-height: 1.5;
}

.ics-owner-label {
  font-size: 12px; opacity: 0.85; font-style: normal;
  text-transform: capitalize; margin-top: 1px; line-height: 1;
}

/* ── Mobile tag actions ─────────────────────────────────────────────────── */

/* Mobile-only "⋮" button on tag rows — always visible on touch, hidden on desktop hover-capable devices */
.tag-mobile-menu-btn {
  display: none;  /* hidden by default (desktop uses hover) */
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 6px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
  touch-action: manipulation;
}
@media (hover: none) {
  /* Show ⋮ button on touch devices; hide the hover-only action buttons */
  .tag-mobile-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
}

/* Mobile tag context menu (appears below the tag row) */
.tag-context-menu {
  position: absolute;
  right: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(var(--shadow-rgb),0.15);
  z-index: 60;
  min-width: 140px;
  overflow: hidden;
}
.tag-context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  font-size: 14px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}
.tag-context-menu button:hover, .tag-context-menu button:active { background: var(--bg); }
.tag-context-menu button.danger { color: var(--danger-text); }

