/* ==========================================================================
   Rocket City Hauling — CRM dashboard
   Built on the marketing site's type + brand colors, extended with a neutral
   application palette. The marketing CSS is deliberately NOT loaded here.
   ========================================================================== */

/* ===== FONTS (shared with the public site) ===== */
@font-face {
  font-family: Clashgrotesk;
  src: url('../../fonts/ClashGrotesk-Regular.otf') format("opentype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: Clashgrotesk;
  src: url('../../fonts/ClashGrotesk-Medium.otf') format("opentype");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: Clashgrotesk;
  src: url('../../fonts/ClashGrotesk-Semibold.otf') format("opentype");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: Clashgrotesk;
  src: url('../../fonts/ClashGrotesk-Bold.otf') format("opentype");
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --main-font: Clashgrotesk, "Trebuchet MS", Arial, sans-serif;
  --secondary-font: Outfit, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Brand — unchanged from the public site */
  --blue: #00388f;
  --green: #a3ef05;

  --blue-800: #002a6b;
  --blue-600: #0a49a8;
  --blue-100: #dbe6f7;
  --blue-50: #eff4fc;

  /* Application neutrals */
  --ink: #14161c;
  --ink-2: #3d434f;
  --muted: #6f7684;
  --faint: #9aa1af;
  --line: #e4e7ec;
  --line-2: #eef0f4;
  --bg: #f5f6f8;
  --card: #ffffff;

  /* Status */
  --amber: #b45309;      --amber-bg: #fef4e6;
  --violet: #6d28d9;     --violet-bg: #f1eafe;
  --emerald: #047857;    --emerald-bg: #e7f6ef;
  --rose: #be123c;       --rose-bg: #fdeaee;
  --slate: #52525b;      --slate-bg: #f0f0f2;

  /* ---- LAYOUT CONTRACT ----
     Every page renders inside .portal. Changing --portal-w moves the calendar,
     the job tables, the client list and the message threads together, so no
     screen can ever drift to a different content width. */
  --sidebar-w: 264px;
  --portal-w: 1560px;
  --portal-pad: 24px;
  --topbar-h: 68px;

  --radius: 12px;
  --radius-sm: 9px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, .16);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--secondary-font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { font-family: var(--main-font); font-weight: 600; line-height: 1.15; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

::selection { background: var(--blue); color: #fff; }

/* ==========================================================================
   THE PORTAL — the single source of truth for content width
   ========================================================================== */
.portal {
  width: 100%;
  max-width: var(--portal-w);
  margin: 0 auto;
  padding-left: var(--portal-pad);
  padding-right: var(--portal-pad);
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}
.app[hidden] { display: none; }

/* ----- Sidebar ----- */
.sidebar {
  background: var(--blue);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 22px;
  flex-shrink: 0;
}
.sidebar-brand img { height: 30px; width: auto; }
.sidebar-brand .brand-text {
  font-family: var(--main-font);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .2px;
  line-height: 1.1;
}
.sidebar-brand .brand-text small {
  display: block;
  font-family: var(--secondary-font);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--green);
}

.nav { padding: 14px 14px 24px; display: flex; flex-direction: column; gap: 2px; }

.nav-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .45);
  padding: 18px 12px 7px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, .78);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: rgba(255, 255, 255, .09); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, .15); color: #fff; font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; stroke-width: 1.9; }
.nav-item .nav-count {
  margin-left: auto;
  background: var(--green);
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  padding: 0 6px;
}

.sidebar-foot {
  margin-top: auto;
  padding: 16px 26px 20px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, .4);
  line-height: 1.5;
}

/* ----- Main column ----- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
}
/* The topbar's inner row uses the SAME portal container as page content, so the
   avatar's right edge lines up with the content's right edge on every screen. */
.topbar .portal {
  display: flex;
  align-items: center;
  gap: 18px;
}

.topbar-title { min-width: 0; }
.topbar-title h1 {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-title p {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ----- Account menu ----- */
.account { position: relative; }
.account-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 9px 5px 5px;
  border: 1px solid var(--line);
  border-radius: 100px;
  background: var(--card);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.account-btn:hover { background: var(--blue-50); border-color: var(--blue-100); }
.account-meta { text-align: left; line-height: 1.2; }
.account-meta strong { display: block; font-size: 13.5px; font-weight: 600; }
.account-meta span { font-size: 11.5px; color: var(--muted); text-transform: capitalize; }
.account-btn .chev { width: 15px; height: 15px; color: var(--faint); }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--main-font);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .3px;
  flex-shrink: 0;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; }
.avatar.client { background: var(--blue-100); color: var(--blue); }

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 232px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 60;
}
.menu[hidden] { display: none; }
.menu-head { padding: 11px 12px; border-bottom: 1px solid var(--line-2); margin-bottom: 6px; }
.menu-head strong { display: block; font-size: 14px; }
.menu-head span { font-size: 12px; color: var(--muted); word-break: break-all; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px;
  border: none; background: none; border-radius: var(--radius-sm);
  font-size: 14px; cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--bg); }
.menu-item.danger { color: var(--rose); }
.menu-item svg { width: 16px; height: 16px; }

/* ----- Scroll area ----- */
.scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 0 60px;
}

/* ==========================================================================
   PRIMITIVES
   ========================================================================== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-2);
}
.card-head h2 { font-size: 15.5px; font-weight: 600; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 20px; }
.card-body.tight { padding: 12px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.main-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { margin-left: auto; }
.stack { display: flex; flex-direction: column; gap: 18px; }

.section-title {
  font-size: 12px; font-weight: 600; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--muted); margin-bottom: 12px;
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:hover:not(:disabled) { background: var(--bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--blue-800); border-color: var(--blue-800); }

.btn-accent { background: var(--green); border-color: var(--green); color: var(--blue); font-weight: 700; }
.btn-accent:hover:not(:disabled) { filter: brightness(.95); background: var(--green); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

.btn-danger { color: var(--rose); border-color: #f5cdd6; }
.btn-danger:hover:not(:disabled) { background: var(--rose-bg); }

.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }

/* ----- Badges ----- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 23px;
  padding: 0 9px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--slate-bg);
  color: var(--slate);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }
.badge-new { background: var(--amber-bg); color: var(--amber); }
.badge-scheduled { background: var(--blue-50); color: var(--blue); }
.badge-in_progress { background: var(--violet-bg); color: var(--violet); }
.badge-completed { background: var(--emerald-bg); color: var(--emerald); }
.badge-cancelled { background: var(--slate-bg); color: var(--slate); }
.badge-paid { background: var(--emerald-bg); color: var(--emerald); }
.badge-unpaid { background: var(--amber-bg); color: var(--amber); }
.badge-refunded { background: var(--rose-bg); color: var(--rose); }

/* ----- Forms ----- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); }

.input, .select, .textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 56, 143, .12);
}
.textarea { min-height: 100px; resize: vertical; line-height: 1.55; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f7684' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.search {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}
.search svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--faint); pointer-events: none;
}
.search .input { padding-left: 34px; }

/* ----- Toolbar (filters row above tables) ----- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 32px; padding: 0 13px;
  border-radius: 100px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: all .15s ease;
}
.chip:hover { background: var(--bg); }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.chip .n { opacity: .65; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ----- Tables ----- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: #fafbfc;
}
.table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--blue-50); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }

.cell-primary { font-weight: 600; }
.cell-sub { font-size: 12.5px; color: var(--muted); }
.cell-person { display: flex; align-items: center; gap: 10px; }

/* ----- Stat tiles ----- */
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.stat .label {
  font-size: 11.5px; font-weight: 600; letter-spacing: .8px;
  text-transform: uppercase; color: var(--muted);
}
.stat .value {
  font-family: var(--main-font);
  font-size: 27px; font-weight: 600;
  letter-spacing: -.6px; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat.accent { background: var(--blue); border-color: var(--blue); color: #fff; }
.stat.accent .label { color: var(--green); }
.stat.accent .sub { color: rgba(255, 255, 255, .72); }

/* ----- Empty / loading ----- */
.empty { padding: 52px 24px; text-align: center; color: var(--muted); }
.empty svg { width: 34px; height: 34px; margin: 0 auto 12px; color: var(--faint); stroke-width: 1.5; }
.empty h3 { font-size: 16px; color: var(--ink); margin-bottom: 5px; }
.empty p { font-size: 13.5px; max-width: 380px; margin: 0 auto; }
.empty .btn { margin-top: 16px; }

.skeleton {
  background: linear-gradient(90deg, var(--line-2) 25%, #f7f8fa 50%, var(--line-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: 6px;
  height: 14px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner.dark { border-color: var(--line); border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   TIMELINE / THREAD
   ========================================================================== */
.thread { display: flex; flex-direction: column; gap: 16px; padding: 20px; }

.msg { display: flex; gap: 12px; max-width: 100%; }
.msg-body {
  border-radius: var(--radius);
  padding: 12px 15px;
  font-size: 14px;
  line-height: 1.6;
  max-width: 78%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg-meta { font-size: 11.5px; color: var(--muted); margin-top: 5px; display: flex; gap: 7px; align-items: center; }
.msg-subject { font-weight: 600; font-size: 13px; margin-bottom: 4px; }

/* Inbound — client, left aligned */
.msg-in .msg-body { background: var(--card); border: 1px solid var(--line); }

/* Outbound — us, right aligned */
.msg-out { flex-direction: row-reverse; }
.msg-out .msg-body { background: var(--blue); color: #fff; border: 1px solid var(--blue); }
.msg-out .msg-meta { justify-content: flex-end; }
.msg-out .msg-subject { color: rgba(255, 255, 255, .9); }

/* Internal note — never sent to the client */
.msg-note .msg-body {
  background: #fffbeb;
  border: 1px solid #fde9b0;
}
.msg-note .note-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .7px;
  text-transform: uppercase; color: var(--amber); margin-bottom: 4px;
}

/* System event — centered, quiet */
.msg-system { justify-content: center; }
.msg-system .msg-body {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  padding: 3px 12px;
  max-width: 100%;
}

.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.attachment {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 3px 9px;
  background: rgba(0, 0, 0, .05); border-radius: 6px;
}
.msg-out .attachment { background: rgba(255, 255, 255, .18); }

/* ----- Composer ----- */
.composer { border-top: 1px solid var(--line); padding: 14px 20px 16px; background: #fafbfc; }
.composer-tabs { display: flex; gap: 4px; margin-bottom: 11px; }
.composer-tab {
  padding: 6px 13px; border-radius: 100px; border: 1px solid transparent;
  background: none; font-size: 13px; font-weight: 500; cursor: pointer;
}
.composer-tab:hover { background: var(--line-2); }
.composer-tab.active { background: var(--card); border-color: var(--line); font-weight: 600; box-shadow: var(--shadow-sm); }
.composer .textarea { background: var(--card); }
.composer-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.composer-hint { font-size: 12px; color: var(--muted); }

/* ==========================================================================
   CALENDAR
   ========================================================================== */
.cal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line-2);
}
.cal-head h2 { font-size: 17px; min-width: 190px; }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-dow {
  padding: 9px 10px; font-size: 11px; font-weight: 600; letter-spacing: .8px;
  text-transform: uppercase; color: var(--muted); text-align: center;
  border-bottom: 1px solid var(--line); background: #fafbfc;
}
.cal-cell {
  min-height: 116px;
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
  padding: 7px;
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer;
  transition: background .12s ease;
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell:hover { background: var(--blue-50); }
.cal-cell.muted { background: #fbfcfd; }
.cal-cell.muted .cal-date { color: var(--faint); }
.cal-cell.today .cal-date {
  background: var(--blue); color: #fff; border-radius: 50%;
  width: 24px; height: 24px; display: grid; place-items: center;
}
.cal-cell.selected { background: var(--blue-50); box-shadow: inset 0 0 0 2px var(--blue); }
.cal-date { font-size: 12.5px; font-weight: 600; color: var(--ink-2); height: 24px; display: flex; align-items: center; padding: 0 3px; }

.cal-pill {
  font-size: 11.5px;
  padding: 3px 7px;
  border-radius: 5px;
  background: var(--blue-50);
  color: var(--blue);
  border-left: 3px solid var(--blue);
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-pill.s-new { background: var(--amber-bg); color: var(--amber); border-left-color: var(--amber); }
.cal-pill.s-in_progress { background: var(--violet-bg); color: var(--violet); border-left-color: var(--violet); }
.cal-pill.s-completed { background: var(--emerald-bg); color: var(--emerald); border-left-color: var(--emerald); }
.cal-pill.s-cancelled { background: var(--slate-bg); color: var(--slate); border-left-color: var(--slate); text-decoration: line-through; }
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }

/* ==========================================================================
   CUSTOMER PHOTOS
   ========================================================================== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.photo-cell {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  padding: 0;
  background: var(--bg);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color .15s ease, transform .12s ease;
}
.photo-cell:hover { border-color: var(--blue); transform: scale(1.02); }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; }

.photo-viewer { flex-direction: column; gap: 14px; }
.photo-viewer img {
  max-width: min(1100px, 92vw);
  max-height: 82vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.photo-viewer-open { background: var(--card); }

/* ==========================================================================
   MODAL / DRAWER
   ========================================================================== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(16, 24, 40, .45);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade .15s ease;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  animation: pop .18s cubic-bezier(.2, .9, .3, 1.2);
}
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }

.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 12px;
}
.modal-head h2 { font-size: 17px; }
.modal-head p { font-size: 13px; color: var(--muted); margin-top: 2px; }
.modal-body { padding: 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 10px; justify-content: flex-end;
}

/* ==========================================================================
   TOASTS
   ========================================================================== */
.toasts {
  position: fixed; bottom: 22px; right: 22px;
  z-index: 200; display: flex; flex-direction: column; gap: 9px;
  max-width: min(400px, calc(100vw - 44px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--ink); color: #fff;
  padding: 12px 15px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-size: 14px;
  animation: slidein .22s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }
.toast.ok { background: #05603a; }
.toast.err { background: #9f1239; }
.toast svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }

/* ==========================================================================
   LOGIN
   ========================================================================== */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 50% -10%, #0a49a8 0%, transparent 60%),
    var(--blue);
}
.login-screen[hidden] { display: none; }

.login-card {
  width: 100%; max-width: 400px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 34px 32px 28px;
}
.login-card .logo { height: 40px; width: auto; margin: 0 auto 22px; }
.login-card h1 { font-size: 22px; text-align: center; }
.login-card .sub { font-size: 13.5px; color: var(--muted); text-align: center; margin: 6px 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .btn { height: 44px; width: 100%; }
.login-error {
  background: var(--rose-bg); color: var(--rose);
  border-radius: var(--radius-sm); padding: 10px 13px; font-size: 13.5px;
}
.login-error[hidden] { display: none; }
.login-link {
  background: none; border: none; color: var(--blue);
  font-size: 13px; font-weight: 500; cursor: pointer; text-align: center;
  padding: 4px; text-decoration: underline;
}
.login-foot { margin-top: 20px; text-align: center; font-size: 12px; color: var(--faint); }

/* Full-screen boot state, shown until Firebase reports an auth result */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 300; }
.boot[hidden] { display: none; }

/* ==========================================================================
   DETAIL PAGES
   ========================================================================== */
.detail-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.detail-head .titles h1 { font-size: 23px; letter-spacing: -.4px; }
.detail-head .titles .meta { font-size: 13.5px; color: var(--muted); margin-top: 3px; }

.kv { display: flex; flex-direction: column; gap: 0; }
.kv-row {
  display: grid; grid-template-columns: 116px minmax(0, 1fr);
  gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-2);
  font-size: 14px; align-items: start;
}
.kv-row:last-child { border-bottom: none; }
.kv-row dt { color: var(--muted); font-size: 13px; }
.kv-row dd { font-weight: 500; overflow-wrap: anywhere; }
.kv-row dd a { color: var(--blue); }
.kv-row dd a:hover { text-decoration: underline; }
/* The bottom-line figure under a run of part-totals. */
.kv-row.kv-total { border-top: 1px solid var(--line); margin-top: 2px; }
.kv-row.kv-total dt { color: var(--ink-2); font-weight: 600; }

/* ----- Additional charges ----- */
/*
   Invoices raised against a job after it was booked. They sit in their own card
   under Payment rather than folding into it, because the booking's own total is
   settled history and these are not.
*/
.charge-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line-2);
}
.charge-row:last-child { border-bottom: none; }
.charge-row.is-void { opacity: 0.55; }
.charge-row.is-void .charge-desc { text-decoration: line-through; }
.charge-desc { font-size: 13.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.charge-meta {
  display: flex; flex-wrap: wrap; gap: 5px;
  font-size: 12px; color: var(--faint); margin-top: 4px;
}
.charge-actions { display: flex; gap: 6px; margin-left: auto; flex-shrink: 0; }

/* Someone on file with no jobs yet — an enquiry parked for follow-up. */
.badge-lead { background: var(--violet-bg); color: var(--violet); margin-top: 4px; }

.badge-charge-open { background: var(--amber-bg); color: var(--amber); }
.badge-charge-paid { background: var(--emerald-bg); color: var(--emerald); }
.badge-charge-refunded { background: var(--rose-bg); color: var(--rose); }
.badge-charge-void { background: var(--slate-bg); color: var(--slate); }

/* Optional invoice half of the New client dialog, kept visually separate so
   the form still reads as "add a client" at a glance. */
.invoice-toggle {
  margin-top: 4px; padding-top: 14px;
  border-top: 1px solid var(--line-2);
}

/* ----- Invoice handoff sheet ----- */
.invoice-summary {
  background: var(--bg); border-radius: var(--radius);
  padding: 18px; text-align: center; margin-bottom: 16px;
}
.invoice-amount {
  font-size: 30px; font-weight: 700; color: var(--blue);
  line-height: 1.15; font-variant-numeric: tabular-nums;
}
.invoice-desc { font-size: 13.5px; color: var(--ink-2); margin-top: 5px; }

.delivery-row {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 11px 0; border-bottom: 1px solid var(--line-2);
}
.delivery-row > svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; margin-top: 1px; }
.delivery-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.delivery-detail { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.delivery-tick { margin-left: auto; color: var(--emerald); display: flex; }
.delivery-tick svg { width: 17px; height: 17px; }

/* The exact text that will land on the client's phone — shown, not summarised,
   so nobody sends a message they haven't read. */
.sms-preview {
  margin-top: 14px; padding: 12px 14px;
  background: var(--blue-50); border-radius: var(--radius-sm);
  font-size: 13px; line-height: 1.55; color: var(--ink-2);
  overflow-wrap: anywhere; white-space: pre-wrap;
}

.back-link {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13.5px; color: var(--muted); margin-bottom: 14px;
  background: none; border: none; cursor: pointer; padding: 0;
}
.back-link:hover { color: var(--blue); }
.back-link svg { width: 15px; height: 15px; }

.thread-panel { display: flex; flex-direction: column; min-height: 0; }
.thread-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  /* Reaching the top of the thread shouldn't start scrolling the page behind it. */
  overscroll-behavior: contain;
}

/* ==========================================================================
   JOB PAGE — split layout + messenger-style thread
   Left half holds every detail panel; right half is the conversation, pinned
   to the viewport so the composer is always reachable without page scrolling.
   ========================================================================== */
.job-layout {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 1001px) {
  /* Hand scrolling to the two columns instead of the page. */
  .scroll[data-view="job"] {
    overflow: hidden;
    padding-bottom: 0;
    display: flex;
    flex-direction: column;
  }
  .scroll[data-view="job"] > .portal {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
  }
  .scroll[data-view="job"] .job-layout {
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }
  /* Details column scrolls on its own so a long note can't stretch the page. */
  .scroll[data-view="job"] .job-info {
    overflow-y: auto;
    min-height: 0;
    overscroll-behavior: contain;
    padding-right: 6px;
  }
  .scroll[data-view="job"] .thread-panel {
    height: 100%;
    min-height: 0;
  }
}

/* Stacked layout: the thread can't fill the viewport, so bound it instead. */
@media (max-width: 1000px) {
  .job-layout { grid-template-columns: minmax(0, 1fr); }
  .thread-panel { max-height: 72vh; }
}

.mono { font-variant-numeric: tabular-nums; }
.strong-num { font-family: var(--main-font); font-weight: 600; letter-spacing: -.3px; }
.muted-text { color: var(--muted); }
.copyable { cursor: pointer; }
.copyable:hover { color: var(--blue); }

/* ==========================================================================
   RESPONSIVE
   The portal contract holds: only the padding and the sidebar collapse.
   ========================================================================== */
@media (max-width: 1180px) {
  .grid.main-side { grid-template-columns: minmax(0, 1fr); }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 74px; --portal-pad: 18px; }
  .sidebar-brand .brand-text, .nav-item span, .nav-label, .sidebar-foot { display: none; }
  .sidebar-brand { justify-content: center; padding: 0; }
  .nav-item { justify-content: center; padding: 11px 0; }
  .nav-item .nav-count { position: absolute; margin: 0; transform: translate(14px, -12px); }
  .nav-item { position: relative; }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
  .account-meta { display: none; }
  .msg-body { max-width: 88%; }
}

@media (max-width: 620px) {
  :root { --portal-pad: 14px; --topbar-h: 60px; }
  .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .cal-cell { min-height: 76px; }
  .cal-pill { font-size: 10px; padding: 2px 4px; }
  .modal { max-width: 100%; }
}
