/* ==========================================================================
   Redwater Technologies Client Portal — design system
   Hand-authored, dependency-free CSS. No build step required.
   ========================================================================== */

:root {
  --brand-red: #d81b1b;
  --brand-red-dark: #a91414;
  --brand-red-light: #fdeceb;
  --ink: #14151a;
  --ink-soft: #4b4f58;
  --ink-faint: #85899194;
  --border: #e4e5e9;
  --border-soft: #eef0f2;
  --surface: #ffffff;
  --surface-sunk: #f7f7f9;
  --surface-app: #f4f4f6;
  --success: #14804a;
  --success-bg: #e8f7ef;
  --warning: #9a6700;
  --warning-bg: #fff6e0;
  --danger: #b3251d;
  --danger-bg: #fdeceb;
  --info: #1c5fae;
  --info-bg: #eaf2fc;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 21, 26, 0.06);
  --shadow: 0 4px 16px rgba(20, 21, 26, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 21, 26, 0.14);
  --sidebar-w: 248px;
  --topbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--surface-app);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
a { color: var(--brand-red); text-decoration: none; }
a:hover { text-decoration: underline; }
small, .text-sm { font-size: 0.85em; }
.text-center { text-align: center; }
.text-muted { color: var(--ink-soft); }
.text-faint { color: var(--ink-faint); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  color: #f4f4f6;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; }
.sidebar-brand img { height: 34px; width: auto; filter: brightness(0) invert(1); }
.sidebar-brand span { font-weight: 700; font-size: 0.95rem; letter-spacing: 0.02em; }
.sidebar-nav { flex: 1; padding: 8px 10px; overflow-y: auto; }
.sidebar-section { margin-top: 18px; padding: 0 10px 6px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: #9a9ca4; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: #d7d8dd; font-size: 0.9rem; font-weight: 500;
  margin-bottom: 2px;
}
.sidebar-link:hover { background: #24252c; text-decoration: none; color: #fff; }
.sidebar-link.active { background: var(--brand-red); color: #fff; }
.sidebar-link .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 650; font-size: 1.02rem; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.org-switcher select { min-width: 200px; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-red); color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: 0.8rem; flex-shrink: 0;
}

.content { padding: 28px 32px; max-width: 1320px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-soft); }
.eyebrow { font-size: 0.74rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); margin-bottom: 2px; }
.page-head h1 { font-size: 1.85rem; }

/* ---------- Grid / layout helpers ---------- */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 6px; } .gap-2 { gap: 12px; } .gap-3 { gap: 18px; }
.stack > * + * { margin-top: 12px; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm);
}
.card-tight { padding: 14px 16px; }
.card-title { font-weight: 650; margin-bottom: 2px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

.stat-card { display: flex; flex-direction: column; gap: 4px; }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-card .stat-label { color: var(--ink-soft); font-size: 0.83rem; }
.stat-card .stat-trend { font-size: 0.78rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 8px 16px; font-size: 0.88rem; font-weight: 600; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  text-decoration: none; line-height: 1.3; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand-red); color: #fff; }
.btn-primary:hover { background: var(--brand-red-dark); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-sunk); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-sunk); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1d17; }
.btn-sm { padding: 5px 11px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--ink-soft); cursor: pointer; }
.icon-btn:hover { background: var(--surface-sunk); color: var(--ink); }

/* ---------- Forms ---------- */
label, .form-label { display: block; font-size: 0.83rem; font-weight: 600; margin-bottom: 5px; color: var(--ink); }
.input, input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], input[type=tel], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-size: 0.9rem; font-family: inherit;
}
textarea { resize: vertical; min-height: 90px; }
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-red); box-shadow: 0 0 0 3px var(--brand-red-light);
}
.field { margin-bottom: 16px; }
.field-hint { font-size: 0.78rem; color: var(--ink-faint); margin-top: 4px; }
.field-error { font-size: 0.78rem; color: var(--danger); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
fieldset { border: none; padding: 0; margin: 0; }

/* A ModelMultipleChoiceField rendered with CheckboxSelectMultiple — a
   scrollable, bordered list of checkboxes (used for e.g. assigning clients
   to a Technician). */
.checkbox-list {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; max-height: 240px; overflow-y: auto; background: var(--surface);
}
.checkbox-list ul { list-style: none; margin: 0; padding: 0; }
.checkbox-list li { list-style: none; padding: 4px 0; }
.checkbox-list label { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.checkbox-list input[type="checkbox"] { width: auto; }
.checkbox-list-empty { color: var(--ink-faint); font-size: 0.85rem; }

/* A checkbox-dropdown UI layered over a <select multiple> (invoice line
   item tax rates) by JS — picking a combination of rates (e.g. state +
   local) is much easier than ctrl/cmd-clicking a native multi-select. The
   panel is positioned via inline style (JS, position: fixed) rather than
   here, so it isn't clipped by an ancestor's overflow:auto (e.g. the
   line-items table's horizontal scroll wrapper). */
.tax-picker { position: relative; }
.tax-picker-btn { text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tax-picker-panel {
  display: none; position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 8px 10px; max-height: 220px; overflow-y: auto;
}
.tax-picker-panel.open { display: block; }
.tax-picker-option { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 0.85rem; padding: 5px 2px; cursor: pointer; white-space: nowrap; }
.tax-picker-option input[type="checkbox"] { width: auto; }

/* ---------- List picker (client/internal scope picker) ---------- */
.list-picker { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.list-picker-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 18px; border-bottom: 1px solid var(--border-soft);
  color: var(--ink); text-decoration: none;
}
.list-picker-row:last-child { border-bottom: none; }
.list-picker-row:hover { background: var(--surface-sunk); text-decoration: none; }
.list-picker-row.is-hidden { display: none; }
.list-picker-name {
  font-weight: 600; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-picker-meta {
  color: var(--ink-soft); font-size: 0.85rem; text-align: right; flex: 0 1 auto; min-width: 0; max-width: 55%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-picker-empty { display: none; padding: 14px 2px; color: var(--ink-soft); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
thead th {
  text-align: left; padding: 11px 16px; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-soft); border-bottom: 1px solid var(--border); background: var(--surface-sunk); white-space: nowrap;
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-sunk); }
.table-empty { padding: 40px 20px; text-align: center; color: var(--ink-soft); }

/* ---------- Badges / status pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 650; text-transform: capitalize; white-space: nowrap;
}
.badge-gray { background: var(--surface-sunk); color: var(--ink-soft); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-amber { background: var(--warning-bg); color: var(--warning); }
.badge-blue { background: var(--info-bg); color: var(--info); }

/* ---------- Alerts / messages ---------- */
.alert { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; font-size: 0.88rem; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #bfe8d2; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #f3c6c2; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #f2e0a8; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #c4dbf5; }

/* Flash messages (django.contrib.messages) render as a fixed toast stack
   overlaid on the page instead of inline banners — so a status message
   never pushes the actual page content down. Static, non-dismissible
   .alert banners elsewhere (e.g. a ticket's "came in by email" notice)
   are unaffected — they don't get the .toast class, only this stack. */
.toast-stack {
  position: fixed; top: 16px; right: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px; max-width: 380px;
}
.toast { box-shadow: var(--shadow-lg); margin-bottom: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.toast-dismiss {
  background: none; border: none; cursor: pointer; color: inherit; opacity: 0.55;
  font-size: 1.15rem; line-height: 1; padding: 0 0 0 4px; flex-shrink: 0;
}
.toast-dismiss:hover { opacity: 1; }
@media (max-width: 640px) { .toast-stack { left: 12px; right: 12px; max-width: none; } }

/* ---------- Misc ---------- */
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-state h3 { color: var(--ink); }
.pill-tabs { display: flex; gap: 4px; background: var(--surface-sunk); padding: 4px; border-radius: 999px; width: fit-content; }
.pill-tab { padding: 6px 14px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); }
.pill-tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 0.88rem; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }
.breadcrumbs { font-size: 0.82rem; color: var(--ink-soft); margin-bottom: 8px; }
.breadcrumbs a { color: var(--ink-soft); }
.reveal-value { font-family: ui-monospace, monospace; background: var(--surface-sunk); padding: 6px 10px; border-radius: var(--radius-sm); display: inline-block; }
.copy-btn { cursor: pointer; }
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(circle at 18% 20%, rgba(216, 27, 27, 0.45), transparent 45%),
    radial-gradient(circle at 84% 78%, rgba(216, 27, 27, 0.3), transparent 50%),
    linear-gradient(135deg, #1c1d24 0%, var(--ink) 55%, #2d0f0f 100%);
}
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-lg); }
.login-card img { height: 52px; margin: 0 auto 22px; display: block; }
.login-lead { font-size: 0.82em; white-space: nowrap; }
.mobile-nav-toggle { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -260px; z-index: 40; transition: left .18s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { left: 0; }
  .mobile-nav-toggle { display: inline-flex; }
  .content { padding: 18px; }
}

/* knowledgebase: prose styles */
.prose { line-height: 1.65; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 1.4em 0 0.5em; line-height: 1.3; }
.prose h1:first-child, .prose h2:first-child, .prose h3:first-child, .prose h4:first-child { margin-top: 0; }
.prose p { margin: 0 0 1em; }
.prose ul, .prose ol { margin: 0 0 1em; padding-left: 1.4em; }
.prose li { margin-bottom: 0.3em; }
.prose blockquote { margin: 0 0 1em; padding: 4px 16px; border-left: 3px solid var(--border); color: var(--ink-soft); }
.prose code { font-family: ui-monospace, monospace; font-size: 0.88em; background: var(--surface-sunk); padding: 2px 5px; border-radius: 4px; }
.prose pre { background: var(--surface-sunk); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; margin: 0 0 1em; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; width: 100%; margin: 0 0 1em; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose th { background: var(--surface-sunk); }
.prose img { max-width: 100%; border-radius: var(--radius-sm); }
.prose a { color: var(--brand-red); }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }

/* ---------- Avatars (profile pictures) ---------- */
.avatar-img { object-fit: cover; }
.avatar-sm { width: 26px; height: 26px; font-size: 0.68rem; }
.avatar-md { width: 44px; height: 44px; font-size: 1rem; }
.avatar-lg { width: 88px; height: 88px; font-size: 1.9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---------- Dashboard metrics: Revenue vs. Expense bar chart ---------- */
.chart-card { --chart-revenue: #2a78d6; --chart-expense: #eb6834; }
.chart-legend { display: flex; gap: 18px; margin: 2px 0 18px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 0.84rem; color: var(--ink-soft); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.legend-swatch.rev { background: var(--chart-revenue); }
.legend-swatch.exp { background: var(--chart-expense); }
.bar-chart { display: flex; align-items: flex-end; gap: 22px; height: 190px; padding: 0 4px; border-bottom: 1px solid var(--border); }
.bar-chart-group { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar-chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 100%; width: 100%; justify-content: center; }
.bar-chart-bar { width: 22px; min-height: 3px; border-radius: 4px 4px 0 0; position: relative; transition: opacity .12s ease; }
.bar-chart-bar:hover { opacity: 0.82; }
.bar-chart-bar.bar-revenue { background: var(--chart-revenue); }
.bar-chart-bar.bar-expense { background: var(--chart-expense); }
.bar-chart-bar .bar-tip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 0.72rem; font-weight: 600;
  padding: 3px 7px; border-radius: 5px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity .12s ease;
}
.bar-chart-bar:hover .bar-tip { opacity: 1; }
.bar-chart-label { margin-top: 8px; font-size: 0.78rem; color: var(--ink-faint); font-weight: 600; }
.stat-trend.up { color: var(--success); font-weight: 650; }
.stat-trend.down { color: var(--danger); font-weight: 650; }

/* ---------- Print: invoices, statements, reports ---------- */
.print-header { display: none; }
@media print {
  .sidebar, .topbar, .no-print, .mobile-nav-toggle, .breadcrumbs { display: none !important; }
  .app-shell { display: block; min-height: 0; }
  .main-col { display: block; }
  .content { padding: 0; max-width: none; margin: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #d6d7db; break-inside: avoid; }
  a[href] { color: inherit; text-decoration: none; }
  .print-header { display: block; margin-bottom: 20px; }
  .print-header img { height: 34px; }
  .page-head, .card-header { break-after: avoid; }
  table { break-inside: auto; }
  tr { break-inside: avoid; break-after: auto; }
}
