:root {
  /* ===== Base tokens (light) ===== */
  --bg: #f1f4f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #0f1b2d;
  --muted: #5b6b82;
  --line: #e6ebf2;
  --brand: #1f6feb;
  --brand-2: #3b8aff;
  --brand-soft: #eaf1ff;
  --danger-bg: #fdecec;
  --danger-text: #b3261e;
  --warn-bg: #fbf0da;
  --warn-text: #8a5a08;
  --success-bg: #e3f6ea;
  --success-text: #1a7a44;
  /* Solid danger fill (destructive buttons) — pairs with white text in both themes.
     Distinct from --danger-text, which is tuned for text on --danger-bg. */
  --danger-solid: #d92d20;

  /* Sidebar tokens */
  --sidebar: #0f1b2d;
  --sidebar-ink: #aeb9ca;
  --sidebar-ink-strong: #ffffff;
  --sidebar-active: #1f6feb;
  --sidebar-hover: rgba(255, 255, 255, 0.06);

  /* Elevation + shape */
  --shadow-sm: 0 1px 2px rgba(16, 30, 54, 0.06), 0 1px 3px rgba(16, 30, 54, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 30, 54, 0.08), 0 2px 4px rgba(16, 30, 54, 0.04);
  --radius: 14px;

  --sidebar-w: 236px;
  --header-h: 54px;
}

/* ===== Dark theme: same token system, overridden values ===== */
[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #121c2e;
  --surface-2: #0f1828;
  --ink: #e8eef7;
  --muted: #8b9bb4;
  --line: #22304a;
  --brand: #4d93ff;
  --brand-2: #6aa8ff;
  --brand-soft: #16243d;
  --danger-bg: #3a1d1d;
  --danger-text: #f0a0a0;
  --warn-bg: #3a2f16;
  --warn-text: #e8c07a;
  --success-bg: #16301f;
  --success-text: #7ad39b;
  --danger-solid: #e5484d;

  --sidebar: #0a111d;
  --sidebar-ink: #8b9bb4;
  --sidebar-ink-strong: #ffffff;
  --sidebar-active: #1f6feb;
  --sidebar-hover: rgba(255, 255, 255, 0.05);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* Respect OS preference when no explicit theme is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --surface: #121c2e;
    --surface-2: #0f1828;
    --ink: #e8eef7;
    --muted: #8b9bb4;
    --line: #22304a;
    --brand: #4d93ff;
    --brand-2: #6aa8ff;
    --brand-soft: #16243d;
    --danger-bg: #3a1d1d;
    --danger-text: #f0a0a0;
    --warn-bg: #3a2f16;
    --warn-text: #e8c07a;
    --success-bg: #16301f;
    --success-text: #7ad39b;
    --danger-solid: #e5484d;
    --sidebar: #0a111d;
    --sidebar-ink: #8b9bb4;
    --sidebar-ink-strong: #ffffff;
    --sidebar-active: #1f6feb;
    --sidebar-hover: rgba(255, 255, 255, 0.05);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over component rules that set an
   explicit `display` (e.g. .login-screen/.profile-pill use display:flex). Without
   this, toggling `hidden` in JS has no effect and the login overlay never hides. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
  transition: background 0.25s ease, color 0.25s ease;
}

/* ===== Sidebar (left rail) ===== */
.topbar {
  grid-column: 1;
  grid-row: 1 / span 2;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 20px 14px;
  background: var(--sidebar);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; text-decoration: none; }
.brand-logo { display: block; height: 34px; width: auto; }
/* The sidebar is dark in both themes, so use the dark-background wordmark inks. */
.brand-word { fill: #F2F4F8; }
.brand-word-accent { fill: #7FA0F5; }
.logo {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(31, 111, 235, 0.4);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; color: var(--sidebar-ink-strong); }

/* Primary nav: vertical list */
.tabs { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.tab {
  appearance: none;
  border: none;
  background: none;
  text-align: left;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--sidebar-ink);
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, transform 0.12s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}
.tab-icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}
.tab-icon svg { width: 100%; height: 100%; }
.tab:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-strong); }
.tab:active { transform: scale(0.985); }
.tab.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(31, 111, 235, 0.35);
}

.topbar-right { margin-top: auto; padding: 8px; }
.env-pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 5px 10px;
  border-radius: 999px;
}

/* ===== Sub tabs: sticky header band in content column ===== */
.subtabs {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 20px;
  align-items: center;
  height: var(--header-h);
  padding: 0 36px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.subtab {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  padding: 16px 2px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  transition: color 0.16s ease, border-color 0.16s ease;
}
.subtab:hover { color: var(--ink); }
.subtab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ===== View ===== */
.view {
  grid-column: 2;
  grid-row: 2;
  padding: 40px 36px;
  max-width: 1120px;
  margin: 0;
  animation: fv-fade 0.32s ease;
}

/* Dashboard: map as a card panel */
.view.dashboard-view {
  padding: 40px 36px 24px;
  max-width: 100%;
  animation: none;
  display: flex;
  flex-direction: column;
}
.dashboard-title {
  margin: 0 0 20px;
}
#dashboard-map-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  position: relative;
  flex: 1;
}
#dashboard-map {
  width: 100%;
  height: 100%;
}
#dashboard-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 1;
}
.map-spinner-ring {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: map-spin 0.75s linear infinite;
}
@keyframes map-spin { to { transform: rotate(360deg); } }
@keyframes fv-fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.page-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.page-sub { color: var(--muted); font-size: 13px; margin: 0 0 28px; }

.placeholder {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  box-shadow: var(--shadow-md);
  padding: 64px 24px;
  text-align: center;
  color: var(--muted);
  position: relative;
  overflow: hidden;
}
.placeholder::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}
.placeholder strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }

/* ===== Sites list ===== */
.sites-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.sites-search {
  flex: 1;
  max-width: 360px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.sites-search:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.sites-count { font-size: 12px; color: var(--muted); }
.sites-filter-select {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.16s ease;
}
.sites-filter-select:focus { border-color: var(--brand); }

.sites-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.sites-table thead th {
  padding: 11px 18px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.sites-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}
.sites-table thead th.sortable:hover { color: var(--ink); }
.sort-icon { font-style: normal; margin-left: 4px; opacity: 0.5; }
.sites-table thead th.sortable:hover .sort-icon { opacity: 1; }
.sites-table tbody tr {
  transition: background 0.12s ease;
}
.sites-table tbody tr:hover { background: var(--brand-soft); }
.sites-table tbody td {
  padding: 13px 18px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.sites-table tbody tr:last-child td { border-bottom: none; }
.site-name { font-weight: 600; color: var(--ink); }
.site-address { color: var(--muted); }

/* Work orders */
.wo-row { cursor: pointer; }
.wo-summary-cell { color: var(--muted); max-width: 320px; }
.wo-muted { color: var(--muted); }
.wo-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.wo-detail-row:last-child { border-bottom: none; }
.wo-detail-label { color: var(--muted); font-weight: 600; }
.wo-summary-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
}
.wo-office-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
}
/* Non-billable / dispatch-only marker */
.wo-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 6px;
  vertical-align: middle;
}
.wo-detail-note { font-size: 13px; color: var(--muted); line-height: 1.5; }
.wo-notes-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }

/* Scheduling calendar (SCH-1) */
.sched-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.sched-nav { display: flex; align-items: center; gap: 6px; }
.sched-range { font-weight: 600; font-size: 14px; margin-left: 6px; color: var(--ink); }
.sched-views { display: inline-flex; border: 0.5px solid var(--line); border-radius: 8px; overflow: hidden; }
.sched-view-btn { border: none; background: transparent; padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--muted); }
.sched-view-btn:hover { background: var(--surface-2); }
.sched-view-btn.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sched-filters { display: flex; gap: 8px; margin-left: auto; }

.sched-week { display: grid; gap: 4px; }
.sched-corner { }
.sched-colhead { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0; }
.sched-colhead.today { color: var(--brand); font-weight: 700; }
.sched-rowlabel { font-size: 12px; font-weight: 600; color: var(--ink); padding: 6px 6px 0 0; display: flex; align-items: center; }
.sched-cell { min-height: 52px; border: 0.5px solid var(--line); border-radius: 8px; padding: 3px; display: flex; flex-direction: column; gap: 3px; }
.sched-cell.open { border-style: dashed; align-items: center; justify-content: center; }
.sched-plus { color: var(--muted); font-size: 15px; opacity: 0.5; }

.sched-chip { border-radius: 6px; padding: 3px 6px; font-size: 11px; line-height: 1.3; cursor: pointer; border: 0.5px solid transparent; overflow: hidden; }
.sched-chip-title { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-chip-sub { color: inherit; opacity: 0.8; }
.sched-chip-time { font-weight: 700; }
.sched-chip.bill { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-soft); }
.sched-chip.nonbill { background: var(--surface); color: var(--muted); border-color: var(--line); }
.sched-chip.done { background: var(--surface); color: var(--muted); border-color: var(--line); }

.sched-month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.sched-mcell { min-height: 86px; border: 0.5px solid var(--line); border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 3px; }
.sched-mcell.out { opacity: 0.45; }
.sched-mdate { font-size: 11px; color: var(--muted); }
.sched-mcell.today .sched-mdate { color: var(--brand); font-weight: 700; }
.sched-more { font-size: 10px; color: var(--muted); }

.sched-day-note { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.sched-caprow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 0.5px solid var(--line); }
.sched-capname { width: 150px; font-weight: 600; font-size: 13px; color: var(--ink); }
.sched-capbarwrap { width: 120px; height: 8px; background: var(--surface); border: 0.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.sched-capbar { height: 100%; background: var(--brand); }
.sched-capnum { font-size: 12px; color: var(--muted); }
.sched-capchips { width: 100%; display: flex; flex-wrap: wrap; gap: 4px; }

.sched-empty { padding: 28px; color: var(--ink); font-size: 14px; border: 0.5px dashed var(--line); border-radius: 10px; text-align: center; }

/* Work order summary tiles — clickable filters for the list below */
.wo-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.wo-tile { border-radius: 12px; padding: 12px 14px; cursor: pointer; border: 1.5px solid transparent; background: var(--surface-2); }
.wo-tile:hover { border-color: var(--line); }
.wo-tile.active { border-color: currentColor; }
.wo-tile-n { font-size: 22px; font-weight: 700; line-height: 1.1; }
.wo-tile-l { font-size: 12px; margin-top: 2px; }
.wo-tile.danger { background: var(--danger-bg); color: var(--danger-text); }
.wo-tile.warning { background: var(--warn-bg); color: var(--warn-text); }
.wo-tile.accent { background: var(--brand-soft); color: var(--brand); }
.wo-tile.neutral { color: var(--ink); }
.wo-tile.neutral .wo-tile-l { color: var(--muted); }

/* Pipeline stage pill in the work order list */
.wo-stage { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.wo-stage.neutral { background: var(--surface-2); color: var(--muted); }
.wo-stage.info { background: var(--brand-soft); color: var(--brand); }
.wo-stage.warning { background: var(--warn-bg); color: var(--warn-text); }
.wo-stage.success { background: var(--success-bg); color: var(--success-text); }

/* Work order row actions + overflow (⋯) menu */
.wo-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.wo-menu-wrap { position: relative; }
.wo-menu-trigger { border: none; background: transparent; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 7px; border-radius: 6px; }
.wo-menu-trigger:hover { background: var(--surface-2); color: var(--ink); }
.wo-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 172px; background: var(--surface); border: 0.5px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-md); padding: 4px; }
.wo-menu[hidden] { display: none; }
.wo-menu-item { display: block; width: 100%; text-align: left; border: none; background: transparent; cursor: pointer; font-size: 13px; padding: 7px 10px; border-radius: 7px; color: var(--ink); }
.wo-menu-item:hover { background: var(--surface-2); }
.wo-menu-item.danger { color: var(--danger-text); }
.wo-menu-item.danger:hover { background: var(--danger-bg); }

/* Pricing fields greyed out when a work order is marked non-billable */
#wo-pricing-fields.is-disabled { opacity: 0.45; }
#wo-pricing-fields.is-disabled .form-label.required::after { content: ""; }

.sites-loading {
  padding: 64px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.sites-empty {
  padding: 48px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ===== Buttons ===== */
.btn-primary {
  appearance: none;
  border: none;
  cursor: pointer;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(31, 111, 235, 0.3);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--brand-2); box-shadow: 0 4px 12px rgba(31, 111, 235, 0.4); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-ghost {
  appearance: none;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  color: var(--ink);
  transition: background 0.15s ease;
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-secondary {
  appearance: none;
  border: 1px solid var(--brand);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand);
  transition: background 0.15s ease;
}
.btn-secondary:hover { background: var(--brand); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 11px; }

.btn-danger {
  appearance: none;
  border: none;
  cursor: pointer;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  background: var(--danger-solid);
  color: #fff;
  transition: filter 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}
.btn-danger:hover { filter: brightness(0.92); }
.btn-danger:active { transform: scale(0.97); }

/* Centered confirmation modal (destructive actions) */
.confirm-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 101;
  width: 440px;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, -48%);
  opacity: 0;
  background: var(--surface);
  border: 0.5px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 24px 26px 20px;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.confirm-modal.open { opacity: 1; transform: translate(-50%, -50%); }
.confirm-title { font-size: 18px; font-weight: 700; margin: 0 0 10px; letter-spacing: -0.02em; }
.confirm-text { font-size: 13.5px; color: var(--ink); margin: 0 0 10px; line-height: 1.5; }
.confirm-list { margin: 0 0 14px; padding-left: 20px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.confirm-flag { background: var(--warn-bg); color: var(--warn-text); font-size: 12.5px; line-height: 1.5; padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ===== Drawer ===== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.drawer-overlay.open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 600px;
  max-width: 100vw;
  z-index: 101;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.2);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.drawer-title { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.drawer-close {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}
.drawer-close:hover { background: var(--surface-2); color: var(--ink); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 28px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

/* ===== Form ===== */
.form-section {
  border: none;
  padding: 0;
  margin: 0 0 28px;
}
.form-section legend {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 14px;
  padding: 0;
  width: 100%;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row:last-child { margin-bottom: 0; }

.form-row-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.form-row-inline {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.form-row-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.form-label.required::after { content: " *"; color: #e5534b; }

.form-input {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}
.form-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.form-checkbox { width: 16px; height: 16px; cursor: pointer; accent-color: var(--brand); }

.form-hint { font-size: 11px; color: var(--muted); margin-bottom: 10px; display: block; }

.form-error {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fff0f0;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  font-size: 13px;
}
[data-theme="dark"] .form-error {
  background: #2d1515;
  border-color: #7f1d1d;
  color: #fca5a5;
}

/* ===== Rich text editor ===== */
.rte-toolbar {
  display: flex;
  gap: 4px;
  padding: 4px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}
.rte-toolbar button {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 12px;
  color: var(--ink);
  transition: background 0.12s ease;
}
.rte-toolbar button:hover { background: var(--line); }

.rte {
  min-height: 100px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
  outline: none;
}
.rte:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.rte:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }

/* ===== Break entries ===== */
.break-entries-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.break-entry-row {
  display: grid;
  grid-template-columns: 1fr 70px 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.be-check-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.be-remove {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.12s ease, color 0.12s ease;
}
.be-remove:hover { background: #fee2e2; color: #b91c1c; }

/* ===== Geofence map ===== */
.geofence-map-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.geofence-map {
  width: 100%;
  height: 320px;
}
.geofence-hint {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  border-top: 1px solid var(--line);
}
.geofence-preview {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  border-top: 1px solid var(--line);
}

/* ===== Auth: hide the app shell until signed in ===== */
.pre-auth .topbar,
.pre-auth .subtabs,
.pre-auth .view { visibility: hidden; }

/* ===== Login screen ===== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px 30px;
  animation: fv-fade 0.32s ease;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-brand .brand-name { color: var(--ink); font-size: 16px; }
.login-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-field { margin-bottom: 14px; }
.login-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.login-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.pw-wrap { position: relative; }
.pw-wrap .login-input { padding-right: 40px; }
.pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  line-height: 0;
}
.pw-toggle:hover { color: var(--ink); }
.pw-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.login-submit { width: 100%; margin-top: 8px; padding: 11px; font-size: 14px; }
.login-error {
  margin: 4px 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff0f0;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  font-size: 13px;
}
[data-theme="dark"] .login-error { background: #2d1515; border-color: #7f1d1d; color: #fca5a5; }

/* "Forgot password?" and "Back to sign in" helper row */
.login-aux { margin-top: 14px; text-align: center; }
.login-link {
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.login-link:hover { opacity: 0.75; }
.login-link:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 2px; }

/* ===== Sidebar footer (pinned to bottom of the left rail) ===== */
.sidebar-foot { margin-top: auto; position: relative; display: flex; flex-direction: column; gap: 10px; padding: 8px; }
.sidebar-tools { display: flex; align-items: center; gap: 10px; }

.theme-toggle {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--sidebar-ink-strong);
  cursor: pointer;
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.12); }

/* ===== Profile pill ===== */
.profile-pill {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.profile-pill:hover { background: var(--sidebar-hover); border-color: rgba(255, 255, 255, 0.18); }
.avatar {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.profile-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.profile-name {
  font-size: 13px; font-weight: 600; color: var(--sidebar-ink-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-email {
  font-size: 11px; color: var(--sidebar-ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-caret { color: var(--sidebar-ink); font-size: 12px; flex-shrink: 0; }

.profile-menu {
  position: absolute;
  left: 8px; right: 8px;
  bottom: calc(100% - 2px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 20;
}
.profile-menu-item {
  appearance: none;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  transition: background 0.12s ease;
}
.profile-menu-item:hover { background: var(--surface-2); }
/* Non-clickable role label shown above Sign out. */
.profile-menu-role {
  padding: 7px 10px 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ===== Chats ===== */
.chat-shell {
  display: flex;
  gap: 16px;
  height: calc(100vh - var(--header-h) - 80px);
  min-height: 420px;
}

/* Thread list (sites) */
.chat-threads {
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.chat-threads-head {
  padding: 14px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.chat-threads-search-wrap { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.chat-threads-search {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  outline: none;
}
.chat-threads-search:focus { border-color: var(--brand); }
.chat-threads-list { overflow-y: auto; padding: 8px; }
.chat-threads-empty, .chat-loading, .chat-empty {
  padding: 20px 16px; color: var(--muted); font-size: 13px;
}
.chat-empty { display: grid; place-items: center; height: 100%; }
.chat-thread {
  appearance: none;
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 9px 10px; margin-bottom: 2px;
  border: 1px solid transparent; border-radius: 10px;
  background: none; cursor: pointer;
  transition: background 0.12s ease;
}
.chat-thread:hover { background: var(--surface-2); }
.chat-thread.active { background: var(--brand-soft); border-color: var(--brand); }
.chat-thread-avatar, .chat-head-avatar, .chat-msg-avatar {
  flex-shrink: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-weight: 700;
}
.chat-thread-avatar { width: 34px; height: 34px; font-size: 12px; }
.chat-thread-meta { display: flex; flex-direction: column; min-width: 0; }
.chat-thread-name {
  font-size: 13px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-thread-sub {
  font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Main pane */
.chat-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.chat-head-avatar { width: 40px; height: 40px; font-size: 14px; }
.chat-head-name { font-size: 15px; font-weight: 700; color: var(--ink); }
.chat-head-sub { font-size: 12px; color: var(--muted); }

.chat-scroll {
  flex: 1; overflow-y: auto;
  padding: 18px; display: flex; flex-direction: column; gap: 14px;
  background: var(--surface-2);
}
.chat-load-older {
  align-self: center; margin-bottom: 4px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--brand); font-size: 12px; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
}

/* Message */
.chat-msg { display: flex; gap: 10px; max-width: 76%; }
.chat-msg.mine { flex-direction: row-reverse; margin-left: auto; }
.chat-msg-avatar { width: 32px; height: 32px; font-size: 11px; }
.chat-msg-body { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.chat-msg.mine .chat-msg-body { align-items: flex-end; }
.chat-msg-head { display: flex; align-items: baseline; gap: 8px; }
.chat-msg-name { font-size: 12px; font-weight: 700; color: var(--ink); }
.chat-msg-time { font-size: 11px; color: var(--muted); }

.chat-bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 9px 12px;
  font-size: 14px; line-height: 1.45; color: var(--ink);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.chat-msg.mine .chat-bubble { background: var(--brand-soft); border-color: var(--brand); }
.chat-text a { color: var(--brand); }
.chat-more { font-size: 12px; font-weight: 600; color: var(--brand); cursor: pointer; white-space: nowrap; }
.chat-translated {
  margin-top: 7px; padding-top: 7px;
  border-top: 1px dashed var(--line); color: var(--muted);
}
.chat-translated-tag {
  display: inline-block; font-size: 10px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--brand); margin-bottom: 3px;
}
.chat-translated .chat-text { color: var(--ink); opacity: 0.85; }

/* Photos */
.chat-photos {
  display: grid; gap: 4px; border-radius: 12px; overflow: hidden;
  width: 260px; max-width: 100%;
}
.chat-photos.grid-1 { grid-template-columns: 1fr; }
.chat-photos.grid-2 { grid-template-columns: 1fr 1fr; }
.chat-photos.grid-3, .chat-photos.grid-4 { grid-template-columns: 1fr 1fr; }
.chat-photo {
  position: relative; border: none; cursor: pointer; padding: 0;
  aspect-ratio: 1 / 1; background-size: cover; background-position: center;
  background-color: var(--line);
}
.chat-photos.grid-1 .chat-photo { aspect-ratio: 4 / 3; }
.chat-photos.grid-3 .chat-photo:first-child { grid-row: span 2; aspect-ratio: auto; }
.chat-photo-more {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 20px; font-weight: 700;
}

/* Reactions */
.chat-reactions { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chat-react-chip {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 2px 8px; font-size: 12px; cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.chat-react-chip.mine { background: var(--brand-soft); border-color: var(--brand); }
.chat-react-add {
  border: 1px dashed var(--line); background: none; color: var(--muted);
  border-radius: 999px; padding: 2px 8px; font-size: 12px; cursor: pointer;
}
.chat-react-add:hover { color: var(--brand); border-color: var(--brand); }

/* Emoji popover */
.chat-emoji-pop {
  position: absolute; z-index: 50;
  display: flex; flex-wrap: wrap; gap: 2px; max-width: 220px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow-md); padding: 6px;
}
.chat-emoji-opt {
  border: none; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; padding: 5px; border-radius: 7px;
}
.chat-emoji-opt:hover { background: var(--surface-2); }

/* Composer */
.chat-composer { border-top: 1px solid var(--line); padding: 10px 12px; background: var(--surface); }
.chat-attach-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chat-attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 12px; color: var(--muted);
}
.chat-attach-chip button { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; }
.chat-composer-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-icon-btn {
  flex-shrink: 0; width: 36px; height: 36px;
  border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 9px; cursor: pointer; font-size: 17px;
}
.chat-icon-btn:hover { background: var(--brand-soft); }
.chat-input {
  flex: 1; resize: none; max-height: 160px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--ink);
  padding: 9px 12px; font-size: 14px; font-family: inherit; line-height: 1.4;
  outline: none;
}
.chat-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.chat-send { flex-shrink: 0; height: 36px; padding: 0 16px; }
.chat-composer-hint { font-size: 12px; color: var(--muted); min-height: 16px; margin-top: 6px; }

/* Photo modal */
.chat-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, 0.86);
  display: grid; place-items: center;
  grid-template-columns: auto 1fr auto;
}
.chat-modal-img { max-width: 88vw; max-height: 88vh; border-radius: 8px; grid-column: 2; }
.chat-modal-close {
  position: absolute; top: 16px; right: 20px;
  border: none; background: none; color: #fff; font-size: 34px; cursor: pointer; line-height: 1;
}
.chat-modal-nav {
  border: none; background: rgba(255, 255, 255, 0.12); color: #fff;
  width: 48px; height: 64px; font-size: 32px; cursor: pointer; margin: 0 14px; border-radius: 10px;
}
.chat-modal-nav:hover { background: rgba(255, 255, 255, 0.24); }
.chat-modal-count {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 13px; background: rgba(0, 0, 0, 0.5); padding: 4px 12px; border-radius: 999px;
}

@media (max-width: 720px) {
  .chat-shell { flex-direction: column; height: auto; }
  .chat-threads { flex: none; max-height: 180px; }
  .chat-main { height: 70vh; }
  .chat-msg { max-width: 92%; }
}
