/* ============================================================
   App UI Template — sitewide design system
   Extracted and generalized from the Gradebook admin dashboard.
   Soft elevation, rounded geometry, calm confident color, dense
   spacing. Everything is driven by the CSS custom properties in
   :root — change those to re-skin the whole app.
   ============================================================ */

:root {
  --accent: #0bab9a;
  --accent-hover: #0c9686;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --surface-3: #eef1f4;
  --surface-4: #e3e8ed;
  --text: #14181d;
  --muted: #5b6572;
  --border: #dde2e8;
  --border-dark: #c4cbd4;
  --button: #f3f5f7;
  --button-text: #14181d;
  --danger: #c72a3b;
  --success: #16815a;
  --warn: #a3620a;
  --danger-soft: #fdecee;
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 29, .05), 0 1px 1px rgba(20, 24, 29, .04);
  --shadow-md: 0 6px 16px rgba(20, 24, 29, .08), 0 2px 6px rgba(20, 24, 29, .05);
  --shadow-lg: 0 20px 48px rgba(20, 24, 29, .18), 0 6px 18px rgba(20, 24, 29, .08);
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1d222a;
  --surface-3: #262c35;
  --surface-4: #313945;
  --text: #eef1f5;
  --muted: #9aa6b4;
  --border: #2b323c;
  --border-dark: #3a4451;
  --button: #232a33;
  --button-text: #eef1f5;
  --danger: #ff7a86;
  --success: #6fe0ab;
  --warn: #ffc061;
  --danger-soft: rgba(255, 122, 134, .16);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 10px 24px rgba(0, 0, 0, .42), 0 2px 8px rgba(0, 0, 0, .3);
  --shadow-lg: 0 28px 64px rgba(0, 0, 0, .55), 0 8px 22px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

/* Respect the OS preference automatically when no explicit choice has been
   saved yet — app.js sets data-theme as soon as it knows better. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1d222a;
    --surface-3: #262c35;
    --surface-4: #313945;
    --text: #eef1f5;
    --muted: #9aa6b4;
    --border: #2b323c;
    --border-dark: #3a4451;
    --button: #232a33;
    --button-text: #eef1f5;
    --danger: #ff7a86;
    --success: #6fe0ab;
    --warn: #ffc061;
    --danger-soft: rgba(255, 122, 134, .16);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13.5px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  transition: background-color .15s var(--ease), color .15s var(--ease);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img, svg, canvas, video { max-width: 100%; height: auto; }

/* ---------- Top navigation bar ----------
   Fixed, full-width, single row. Nav links scroll horizontally instead of
   wrapping, so it stays a single row at any viewport width. */
body.app-shell { padding-top: 64px; }
body.app-shell:has(#loginScreen:not(.hidden)) { padding-top: 0; }
body.app-nav-collapsed { padding-top: 0; }
body.app-nav-collapsed .app-side-nav { transform: translateY(-100%); box-shadow: none; }

.app-side-nav {
  position: fixed;
  left: 0; right: 0; top: 0;
  height: 64px;
  z-index: 9000;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 6px;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
body:has(#loginScreen:not(.hidden)) .app-side-nav { display: none; }

.app-side-title {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 18px 0 0;
  margin-right: 6px;
  border-right: 1px solid var(--border);
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.app-side-title:hover { color: var(--accent); }
.app-side-title span { display: none; }

.app-side-links {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  display: flex;
  align-items: center;
  gap: 3px;
  scrollbar-width: none;
}
.app-side-links::-webkit-scrollbar { display: none; }
.app-side-links a {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 8px 14px;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius-pill);
  line-height: 1.25;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  transition: background-color .12s var(--ease), color .12s var(--ease);
}
.app-side-links a:hover { background: var(--surface-2); color: var(--text); }
.app-side-links a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

/* ---------- Page chrome ---------- */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; color: var(--text); }
h1, h2, h3 { color: var(--text); letter-spacing: -.01em; }
h2 { margin: 0 0 12px 0; font-size: 16px; font-weight: 700; }
h3 { margin: 12px 0 8px 0; font-size: 14px; font-weight: 700; }
.sub, .muted, label { color: var(--muted); }
.small { font-size: 11.5px; }
:root { --density-scale: 1; }
html[data-density="compact"] { --density-scale: 0.6; }
html[data-density="spacious"] { --density-scale: 1.5; }
/* CSS zoom (not transform:scale) so layout, click hit-testing, and scroll sizing all rescale
   correctly, not just the visual appearance - see AppUI.setFontSize in theme.js. */
html[data-font-size="small"] body { zoom: 0.9; }
html[data-font-size="large"] body { zoom: 1.15; }

main { max-width: none; margin: 0; padding: calc(20px * var(--density-scale)); }

/* Once app.js merges a page's own <header> into the top nav bar (so there is
   one bar, not two stacked), this makes it sit flush inline. */
.app-side-nav > header {
  position: static;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0 0 0 14px;
  background: transparent;
  border: 0;
}
.app-side-nav > header .app-header-title { display: none; }
.app-header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.app-side-nav > header .app-header-actions {
  flex: 0 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.app-side-nav > header .app-header-actions::-webkit-scrollbar { display: none; }

.app-menu-btn, .menu-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 32px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  border-radius: var(--radius-sm);
  background: var(--button);
  color: var(--text);
}

/* ---------- Cards / panels ---------- */
.card, .panel, .login-card, .note {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  max-width: 100%;
}
.card { padding: calc(16px * var(--density-scale)); margin-bottom: calc(14px * var(--density-scale)); }
/* Two cards meant to read as one visual block (e.g. a section's title card directly above its
   data table) - put .card-joined-top on the first and .card-joined-bottom on the second to
   remove the gap and shared border between them. */
.card-joined-top { margin-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: none; }
.card-joined-bottom { border-top-left-radius: 0; border-top-right-radius: 0; border-top: none; }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover td { background: var(--surface-2); }
.note { padding: 12px; border-radius: var(--radius-sm); }

/* Dashboard: My Tasks (wider) beside Upcoming Events (narrower) */
.dashboard-columns { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; align-items: start; }
.dashboard-col-tasks, .dashboard-col-events { min-width: 0; }
@media (max-width: 900px) {
  .dashboard-columns { grid-template-columns: 1fr; }
}

/* ---------- Buttons ---------- */
button, .button-link, input[type="button"], input[type="submit"] {
  appearance: none;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  background: var(--button);
  color: var(--button-text);
  padding: 7px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
  transition: background-color .12s var(--ease), border-color .12s var(--ease), transform .08s var(--ease), box-shadow .12s var(--ease);
}
button:hover, .button-link:hover { background: var(--surface-3); }
button:active, .button-link:active { transform: translateY(1px); }
button:focus-visible, .button-link:focus-visible { outline: none; box-shadow: var(--focus); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary, .button-link.primary, button[type="submit"], input[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover, .button-link.primary:hover, button[type="submit"]:hover, input[type="submit"]:hover { background: var(--accent-hover); }
button.secondary, .button-link.secondary { background: var(--button); color: var(--button-text); }
button.danger, .button-link.danger { background: var(--button); color: var(--danger); border-color: var(--danger); }
button.good, .button-link.good { background: var(--button); color: var(--success); border-color: var(--success); }

/* Row-level action buttons (Log, Team Chat) - a fixed, deliberately compact size so a short
   icon-only button (e.g. the Team Chat "✨") lines up with a text button (e.g. "Log") instead
   of the two ending up visibly different sizes just because their labels differ in length. */
.row-action-btn {
  font-size: 12.5px;
  padding: 5px 10px;
  min-height: 30px;
  min-width: 40px;
}

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%;
  max-width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  min-height: 32px;
  outline: none;
  font-size: 13.5px;
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--focus); }
label { display: block; margin: 9px 0 4px; font-size: 12px; font-weight: 700; }
.toolbar, .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}
.full-width { grid-column: 1 / -1; }

/* ---------- Status ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
}
.pill.good { border-color: var(--success); color: var(--success); }
.pill.bad { border-color: var(--danger); color: var(--danger); }
.pill.warn { border-color: var(--warn); color: var(--warn); }
.good { color: var(--success); }
.bad { color: var(--danger); }
.warn { color: var(--warn); }
.hidden { display: none !important; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 14px;
}
.stat-kicker { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 800; letter-spacing: -.01em; line-height: 1.1; }
.stat-note { margin-top: 4px; font-size: 12px; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-md); }
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  font-size: 12.5px;
}
th, td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: middle; }
th { background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) td { background: var(--surface-2); }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }

/* Click-to-sort table column headers - see e.g. contacts.html's wireSortableHeaders(). */
th.sortable-col { cursor: pointer; user-select: none; }
th.sortable-col:hover { color: var(--text); }
th.sortable-col .sort-indicator { display: inline-block; width: 10px; margin-left: 3px; }
th.sortable-col.sort-active { color: var(--accent); }

/* ---------- Login screen ---------- */
#loginScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-wrap { width: 380px; max-width: 100%; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.login-brand-logo { display: block; max-width: 220px; max-height: 120px; object-fit: contain; }
.login-card { width: 100%; padding: 26px; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.login-card h1 { font-size: 21px; text-align: center; margin: 0 0 8px; }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Notification drawer ---------- */
.app-overlay {
  position: fixed; inset: 0;
  display: none;
  background: rgba(15, 18, 22, .42);
  z-index: 9200;
}
.app-overlay.open { display: block; }
.app-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border-left: 1px solid var(--border);
  z-index: 9300;
  padding: 18px;
  transform: translateX(100%);
  transition: transform .18s var(--ease);
  box-shadow: var(--shadow-lg);
}
.app-drawer.open { transform: translateX(0); }
.app-drawer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.app-drawer-head h2 { margin: 0; flex: 1; }
body.app-drawer-open { overflow: hidden; }

/* ---------- Account menu ---------- */
.app-user-pill { cursor: pointer; }
.app-menu-overlay {
  position: fixed; inset: 0;
  z-index: 9400;
  display: none;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 74px 18px 18px;
  background: rgba(15, 18, 22, .3);
}
.app-menu-overlay.open { display: flex; }
.app-menu-panel {
  width: min(300px, 92vw);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 14px;
}
.app-menu-panel h3 { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.app-menu-section { padding: 10px 0; border-top: 1px solid var(--border); }
.app-menu-section:first-child { border-top: 0; padding-top: 0; }
.app-menu-section button { width: 100%; }
.app-menu-name { font-weight: 700; font-size: 14px; }
.app-menu-role { color: var(--muted); font-size: 12px; }

/* ---------- Modal system ---------- */
.app-modal-overlay {
  position: fixed; inset: 0;
  z-index: 9500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 18, 22, .55);
  backdrop-filter: blur(2px);
}
.app-modal-overlay.open { display: flex; }
body.app-modal-open { overflow: hidden; }
.app-modal-window {
  width: min(680px, 96vw);
  max-height: min(86vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
/* Shared by any Cropper.js viewport - the business-card rotate/crop editor on contact-detail.html
   and the "Scan Business Card" flow on the Dashboard/Contacts pages. */
.crop-image-wrap { max-height: 55vh; overflow: hidden; background: var(--surface-2); border-radius: var(--radius-sm); }
.crop-image-wrap img { display: block; max-width: 100%; }

/* Live "similar name" duplicate-contact suggestions - contact-detail.html's New Contact form and
   mobile/contacts.html's New Contact modal (including right after a business-card scan). */
.dup-suggestions { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.dup-suggestions a { display: block; padding: 7px 10px; font-size: 12.5px; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); }
.dup-suggestions a:last-child { border-bottom: 0; }
.dup-suggestions a:hover { background: var(--surface-3); }
.dup-suggestions .muted { padding: 0 10px 6px; }

/* Full-size image viewer - AppUI.showImageLightbox(src). Click anywhere to dismiss. */
.app-image-lightbox {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0, 0, 0, .85);
  display: none; align-items: center; justify-content: center;
  padding: 24px; cursor: zoom-out;
}
.app-image-lightbox.open { display: flex; }
.app-image-lightbox img { max-width: 92vw; max-height: 92vh; object-fit: contain; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }

/* ---------- AI Assistant sidebar (desktop) - AppUI.toggleAiSidebar() ---------- */
.ai-sidebar-overlay {
  position: fixed; inset: 0; z-index: 9990;
  background: rgba(0, 0, 0, .4);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.ai-sidebar-overlay.open { opacity: 1; pointer-events: auto; }
.ai-sidebar {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 9991;
  width: min(400px, 92vw);
  background: var(--surface); color: var(--text);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease;
}
.ai-sidebar.open { transform: translateX(0); }
.ai-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.ai-sidebar-header h2 { margin: 0; font-size: 16px; }
.ai-sidebar-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.ai-msg { max-width: 85%; padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13.5px; line-height: 1.45; word-break: break-word; }
.ai-msg-text { white-space: pre-wrap; }
.ai-msg-user { align-self: flex-end; background: var(--accent); color: #fff; }
.ai-msg-assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }

/* A contact the AI just created/updated this turn - see AppUI.renderContactCards */
.contact-card-chip {
  display: flex; flex-direction: column; gap: 1px;
  margin-top: 6px; padding: 7px 11px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); text-decoration: none; color: var(--text);
  max-width: 220px;
}
.contact-card-chip:hover { background: var(--surface-3); border-color: var(--accent); }
.contact-card-chip-name { font-weight: 700; font-size: 13px; }
.contact-card-chip-org { font-size: 11.5px; color: var(--muted); }
.ai-msg-system { align-self: center; background: none; color: var(--muted); font-size: 12px; font-style: italic; }
.ai-msg-image { display: block; max-width: 160px; max-height: 120px; object-fit: contain; border-radius: var(--radius-sm); margin-bottom: 6px; cursor: zoom-in; background: var(--surface); }

/* @mention chips inside a rendered chat message, and the "type @ to mention" autocomplete list
   that appears under a chat composer input - see AppUI.renderMessageContent/attachMentionAutocomplete. */
.mention-chip { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 3px; cursor: pointer; font-weight: 600; }
.mention-chip:hover { text-decoration: underline; }
.app-mention-dropdown { z-index: 1000; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-md, var(--shadow-sm)); max-height: 200px; overflow-y: auto; }
.app-mention-dropdown-item { padding: 7px 10px; cursor: pointer; font-size: 13.5px; }
.app-mention-dropdown-item:hover { background: var(--surface-2); }
.ai-sidebar-composer { display: flex; align-items: center; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface-2); }
.ai-sidebar-composer input[type="text"] { flex: 1; }
.ai-sidebar-composer button { width: auto; }

/* Conversation switcher list (AI sidebar list-view and mobile ai-chat.html) */
.ai-conversation-item { padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; margin-bottom: 8px; }
.ai-conversation-item:hover { background: var(--surface-2); }
.ai-conversation-title { font-weight: 600; font-size: 13.5px; }

.app-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.app-modal-title { margin: 0; font-size: 17px; font-weight: 700; }
.app-modal-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.app-modal-close { min-width: 32px; padding: 4px 9px; }
.app-modal-body { padding: 18px; overflow: auto; }
.app-modal-message {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  white-space: pre-wrap;
  font-size: 12px;
}
.app-modal-message.good { border-color: var(--success); color: var(--success); }
.app-modal-message.bad { border-color: var(--danger); color: var(--danger); }

/* ---------- Toasts ---------- */
.app-toast-stack {
  position: fixed;
  top: 76px; right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.app-toast {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  animation: app-toast-in .15s var(--ease);
}
.app-toast.good { border-color: var(--success); }
.app-toast.bad { border-color: var(--danger); }
@keyframes app-toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Theme toggle (floating fallback, used before shell is enabled) --- */
.app-theme-toggle {
  position: fixed;
  right: 14px; bottom: 14px;
  z-index: 9999;
  border-radius: var(--radius-pill);
  padding: 7px 14px;
  box-shadow: var(--shadow-md);
}

/* ============================================================
   Responsive pass — keeps the same components usable on phones
   without any separate mobile markup.
   ============================================================ */
@media (max-width: 900px) {
  .app-side-links a { padding: 7px 11px; }
  header { align-items: flex-start; flex-wrap: wrap; }
  main { padding: 10px; }
  .app-header-actions { width: 100%; margin-left: 0; }
  .stat-grid, .toolbar, .form-grid { grid-template-columns: 1fr; }
  table { font-size: 12px; }
  th, td { padding: 5px 7px; }
}

@media (max-width: 760px) {
  body { font-size: 14px; }

  /* Below this width the nav bar gives up trying to stay a fixed single
     row (that requires syncing body's padding-top to a height that keeps
     changing as content wraps) and instead becomes a sticky, top-anchored
     column: brand row, then the scrollable links row, then the merged
     page header — each full width, wrapping naturally. */
  body.app-shell { padding-top: 0; }
  .app-side-nav {
    position: sticky;
    top: 0;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    gap: 8px;
  }
  .app-side-title {
    padding: 0 0 8px;
    margin-right: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
  }
  .app-side-links a { padding: 6px 10px; font-size: 12.5px; }

  .app-side-nav > header {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 0 0;
    border-top: 1px solid var(--border);
  }
  header h1 { font-size: 18px; }

  .app-header-actions {
    width: 100%;
    margin-left: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .app-header-actions > * { width: 100%; min-width: 0; }

  main { padding: 10px; }
  .card, .panel, .login-card, .note { padding: 12px; margin-bottom: 10px; border-radius: var(--radius-md); }
  h2 { font-size: 15px; }
  h3 { font-size: 14px; }

  .toolbar, .form-grid, .stat-grid { grid-template-columns: 1fr; gap: 8px; }
  button, .button-link, input[type="button"], input[type="submit"] {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    font-size: 14px;
  }
  table { min-width: 680px; font-size: 12px; }
  .app-drawer { width: min(100vw, 420px); padding: calc(12px + env(safe-area-inset-top)) 12px 12px; }
  .login-card { width: min(100%, 420px); }
}

/* Online presence + intel (see CB.mountIntel in app.js) */
.intel-link-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--border); }
.intel-link-url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.intel-link-msg { flex: 1 1 100%; }
.intel-link-del { min-height: 26px !important; padding: 0 9px !important; }
.intel-add-form { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.intel-add-form .intel-platform { width: auto; flex: 0 0 auto; }
.intel-add-form .intel-url { flex: 1; min-width: 160px; }
.intel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.intel-head .intel-refresh { margin-left: auto; }
.intel-item { padding: 9px 0; border-bottom: 1px solid var(--border); display: grid; gap: 3px; }
.intel-item:last-child { border-bottom: none; }
.type-chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.type-chip { border-radius: 999px; padding: 4px 10px; font-size: 11.5px; font-weight: 700; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; min-height: auto; box-shadow: none; }

/* Labelled phone numbers (see CB.createPhoneEditor / CB.phonesHtml in app.js) */
.phone-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.phone-row .phone-label { width: auto; flex: 0 0 auto; }
.phone-row .phone-custom { width: 110px; flex: 0 0 auto; }
.phone-row .phone-number { flex: 1; min-width: 0; }
.phone-row .phone-del { min-height: 30px !important; padding: 0 10px !important; flex: 0 0 auto; }
.phone-line { white-space: nowrap; }
