:root {
  /* Classic legal-chambers palette: navy + slate for structure, a
     warm gold/mustard accent, forest green for success, and burgundy for
     errors/required marks — traditional and distinctly not a generic
     blue "app" theme. Neutrals lean bright/cool (white + slate-blue)
     rather than warm beige/cream, so navy reads crisp against them. */
  --ink: #1e2530;
  --muted: #5a6472;
  --line: #dde3ec;
  --bg: #f7f9fc;
  --card: #ffffff;
  --brand: #16233f;
  --brand-dark: #0b1524;
  --brand-rgb: 22, 35, 63;
  --charcoal: #2b323d;
  --accent: #b8902f;
  --accent-dark: #8f6f24;
  --accent-rgb: 184, 144, 47;
  --forest: #2f5233;
  --forest-dark: #1e3a22;
  --success: var(--forest);
  --success-bg: #e9f1ea;
  --burgundy: #7b1e2b;
  --burgundy-dark: #5c1620;
  --error: var(--burgundy);
  --error-bg: #f6e9ea;
  --warning: #8a6414;
  --warning-bg: #f7f0dc;
  --radius: 8px;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", Times, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--accent-dark); text-decoration: underline; }

.topbar {
  background: linear-gradient(90deg, var(--brand-dark), var(--charcoal));
  color: #fff;
  border-bottom: 3px solid var(--accent);
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
  /* Overflow is measured (topbarInner.scrollWidth vs clientWidth) by the
     inline script in base.html to decide whether to collapse to a
     hamburger — nowrap here so that measurement reflects the nav's true
     one-line width instead of CSS wrapping masking the overflow. */
  overflow: hidden;
}
.brand { color: #fff; font-family: var(--serif); font-weight: 700; font-size: 1.25rem; letter-spacing: 0.02em; flex-shrink: 0; }
.brand:hover { text-decoration: none; opacity: 0.9; color: #fff; }
.nav-panel { display: flex; align-items: center; gap: 24px; flex: 1; min-width: 0; flex-wrap: nowrap; }
.topbar nav { display: flex; gap: 18px; flex: 1; flex-wrap: nowrap; }
.topbar nav a { color: #a9b6c9; font-size: 0.92rem; padding: 6px 2px; border-bottom: 2px solid transparent; white-space: nowrap; }
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar nav a.active { color: #fff; border-bottom-color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 0.88rem; color: #a9b6c9; flex-shrink: 0; white-space: nowrap; }
.badge { background: var(--accent); color: #201804; font-weight: 700; font-size: 0.7rem; padding: 1px 7px; border-radius: 999px; letter-spacing: 0.02em; }
.logout-link { color: #a9b6c9; }
.user-name {
  color: #a9b6c9;
  text-decoration: none;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(169, 182, 201, 0.4);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.user-name:hover, .user-name.active {
  color: #fff;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.5);
}
.topbar .btn { background: var(--accent); color: #201804; font-weight: 600; }
.topbar .btn:hover { background: #c9a24a; }

/* Hamburger toggle — hidden until base.html's script measures an actual
   overflow and adds .nav-collapsed to .topbar (see rules below); no
   fixed-width media query, since whether the nav fits depends on the
   logged-in user's own email length, not just viewport width. */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 34px;
  height: 34px;
  padding: 0;
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle span { display: block; width: 100%; height: 2px; background: #fff; border-radius: 2px; }

.topbar.nav-collapsed .nav-toggle { display: flex; }
.topbar.nav-collapsed .nav-panel {
  display: none;
  position: absolute;
  top: 56px;
  left: 0;
  right: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  background: var(--brand-dark);
  border-bottom: 3px solid var(--accent);
  padding: 8px 20px 16px;
  z-index: 20;
  overflow: visible;
}
.topbar.nav-collapsed .nav-panel.open { display: flex; }
.topbar.nav-collapsed { position: relative; }
.topbar.nav-collapsed .nav-panel nav { flex-direction: column; flex-wrap: wrap; gap: 2px; }
.topbar.nav-collapsed .nav-panel nav a { padding: 10px 2px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.topbar.nav-collapsed .nav-panel nav a.active { border-bottom-color: var(--accent); }
.topbar.nav-collapsed .nav-panel .topbar-right { flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px 2px 4px; white-space: normal; }

.container { max-width: 1440px; margin: 0 auto; padding: 28px 28px 60px; }

.auth-container { max-width: 420px; margin: 60px auto; padding: 0 20px; }

/* Profile page: heading/subtitle/hint block + the form card both use
   this so they stay the same width and centered together — 80% of the
   page on most screens, capped so it doesn't stretch into an
   unreadably wide single-column form on very large monitors, and full
   width on phones where 80% would waste too much screen as dead
   margin (see the <=600px override below). */
.profile-wrap { width: 80%; max-width: 900px; margin: 0 auto; }

h1 { font-family: var(--serif); font-weight: 700; font-size: 1.65rem; margin: 0 0 6px; color: var(--brand); }
h2 { font-family: var(--serif); font-weight: 700; font-size: 1.2rem; margin: 28px 0 12px; color: var(--brand); }
.subtitle { color: var(--muted); margin: 0 0 24px; }

.home-hero {
  padding: 40px 32px 32px;
  margin: -4px -4px 24px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(var(--brand-rgb), 0.06), rgba(var(--accent-rgb), 0.1));
  border: 1px solid var(--line);
}
.home-hero h1 { font-size: 2.15rem; }
.eyebrow {
  display: inline-block;
  background: rgba(var(--accent-rgb), 0.16);
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(var(--brand-rgb), 0.06);
  padding: 20px 22px;
  margin-bottom: 20px;
  /* Lets a wide table scroll horizontally within the card on a narrow
     screen instead of forcing the whole page wider (every <table> in
     this app lives inside a .card). No effect on cards whose content
     already fits. */
  overflow-x: auto;
}

/* auto-fit (not auto-fill): when a section has fewer cards than would
   fill a row (e.g. "Who it's for" with 2), the empty column tracks
   collapse and the existing cards stretch to share the row evenly,
   instead of sitting flush-left with a ragged gap on the right. */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }

.type-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(var(--brand-rgb), 0.06);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.type-card h3 { font-family: var(--serif); margin: 0; font-size: 1.04rem; color: var(--ink); }
.type-card .count { font-size: 1.7rem; font-weight: 700; color: var(--forest); }
.type-card .soon { color: var(--muted); font-size: 0.85rem; font-style: italic; }

/* An implemented type's whole tile is the click target (no separate
   "Draft ..." button inside it) — the tile itself becomes the <a>. */
a.type-card-link {
  text-decoration: none;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
}
a.type-card-link:hover {
  box-shadow: 0 4px 12px rgba(var(--brand-rgb), 0.16);
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}
a.type-card-link h3 { color: var(--ink); }

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}
.tab-bar .tab {
  padding: 10px 20px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 999px 999px 0 0;
  margin-bottom: -1px;
}
.tab-bar .tab:hover { color: var(--ink); text-decoration: none; background: #eef2f7; }
.tab-bar .tab.active {
  color: var(--brand);
  background: var(--card);
  border-color: var(--line);
}

.category-block { margin-bottom: 28px; }
.category-block h2 { margin: 0 0 4px; font-size: 1.05rem; }
.category-block .category-hint { color: var(--muted); font-size: 0.82rem; margin: 0 0 12px; }

.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 0.92rem;
  cursor: pointer;
  letter-spacing: 0.01em;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:disabled { background: #a8b0bc; cursor: not-allowed; }
.btn-secondary { background: #eef2f7; color: var(--brand); }
.btn-secondary:hover { background: #e2e8f0; }

.progress-bar { background: #eef2f7; border-radius: 6px; height: 10px; overflow: hidden; }
.progress-bar-fill { background: var(--brand); height: 100%; transition: width 0.3s ease; }

form .field { margin-bottom: 14px; }
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=file], textarea, select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  line-height: 1.3;
}
/* Native <select> chrome (OS-drawn padding/arrow) otherwise renders
   taller than a same-padding text input in most browsers — stripping
   it and drawing our own arrow keeps the box model identical to every
   other field above, so selects line up flush in a field-row/name-row
   instead of standing a few px taller. */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpolygon points='0,0 10,0 5,6' fill='%236b665c'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}
/* "Individual" (10 chars) is the longest #user_type option -- width is
   that length + 2 characters of breathing room, rather than stretching
   full-width like the rest of the form's inputs. */
#user_type { width: 12ch; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.18);
}
textarea { resize: vertical; min-height: 70px; }
/* margin-bottom matters most for a standalone .field-hint sitting
   between a field/row and the next one (describing the row above it,
   rather than living inside a single .field) -- without it, the next
   field's label sat right on top of the hint text with almost no
   demarcation. Harmless for a .field-hint nested inside a .field
   (the common case, right under one input's own label+input): it just
   collapses with that .field's own margin-bottom below. */
.field-hint { font-size: 0.78rem; color: var(--muted); margin-top: 3px; margin-bottom: 10px; }
.link-btn {
  background: none; border: none; padding: 0; margin: 0;
  color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: underline;
}
.link-btn:hover { color: var(--brand); }
.required-mark { color: var(--burgundy); margin-left: 2px; font-weight: 700; }
/* Required fields' labels darken from the default muted label color to
   stand out; optional fields need no extra styling on the label since
   var(--muted) (the default) already reads as secondary/duller.
   Optional inputs additionally get a lighter border than the default
   var(--line), so the field itself looks a touch quieter too. Together
   these replace the old "(optional)"/"*" text-only distinction with a
   look-based one, no marker text required on optional fields. */
.label-required { color: var(--ink); }
input.input-optional, textarea.input-optional, select.input-optional { border-color: #dfe4ec; }
input.field-invalid, textarea.field-invalid, select.field-invalid {
  border-color: var(--burgundy);
  background: var(--error-bg);
}
input.field-invalid:focus, textarea.field-invalid:focus, select.field-invalid:focus {
  box-shadow: 0 0 0 3px rgba(123, 30, 43, 0.15);
}
.field-error-text { font-size: 0.78rem; color: var(--burgundy); margin-top: 3px; font-weight: 600; }
::placeholder { color: var(--muted); opacity: 0.8; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
/* Prefix/First/Middle/Last on one line when there's room: Prefix is
   sized to its own longest option ("Prof.") rather than stretching
   like the name fields, First/Last keep room for 16 characters before
   wrapping, Middle enough to fit its own "Middle name" label (11
   characters) without wrapping. Collapses to 2 columns at the same
   tablet breakpoint as .field-row-3, then 1 column at the phone
   breakpoint below. */
.name-row { display: grid; grid-template-columns: 5.5em minmax(16ch, 1fr) minmax(12ch, 1fr) minmax(16ch, 1fr); gap: 14px; }
/* "I am a(n)" + whichever conditional field applies (Bar Council/Firm
   Name/Details) -- first column is exactly as wide as the dropdown
   itself (not a stretched 1fr half of the row), so the second field
   starts right after it instead of a wide empty gap in between. */
.type-row { display: grid; grid-template-columns: max-content 1fr; gap: 10px; align-items: start; }
/* A field-row/field-row-3/name-row/type-row directly followed by a
   standalone .field-hint (describing the row as a whole, rather than
   living inside one of the row's own .field wrappers) otherwise shows
   an oversized gap above that hint: grid doesn't collapse a child
   .field's own margin-bottom the way normal block flow would, so that
   14px stays "trapped" inside the row's rendered height on top of the
   hint's own margin-top. Moving the spacing from the children onto the
   row itself fixes that without losing any spacing when a row stacks
   to one column on narrow screens (the grid's own `gap` covers that). */
.field-row .field, .field-row-3 .field, .name-row .field, .type-row .field { margin-bottom: 0; }
.field-row, .field-row-3, .name-row, .type-row { margin-bottom: 14px; }

.phone-row { display: flex; gap: 8px; }
.phone-row .phone-country-select { flex: 0 0 40%; min-width: 0; }
.phone-row input { flex: 1 1 auto; min-width: 0; }
@media (max-width: 480px) {
  .phone-row { flex-direction: column; }
  .phone-row .phone-country-select { flex-basis: auto; }
}


fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 20px; }
legend { font-family: var(--serif); font-weight: 700; padding: 0 6px; font-size: 0.98rem; color: var(--brand); }
fieldset p.hint { color: var(--muted); font-size: 0.85rem; margin-top: -4px; }

.flash-stack { margin-bottom: 20px; }
.flash { padding: 12px 16px; border-radius: 6px; margin-bottom: 10px; font-size: 0.95rem; font-weight: 600; white-space: pre-wrap; border-width: 1px; border-left-width: 5px; border-style: solid; }
.flash-error { background: var(--error-bg); color: var(--burgundy); border-color: #e3c3c0; border-left-color: var(--burgundy); }
.flash-error::before { content: "⚠ "; }
.flash-success { background: var(--success-bg); color: var(--forest); border-color: #c3d9cb; border-left-color: var(--forest); }

.alert-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #e3cd9c;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.9rem;
  margin-bottom: 20px;
}
.alert-warning strong { display: block; margin-bottom: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }

.stat-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 20px; min-width: 140px; }
.stat .n { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; color: var(--brand); }
.stat .label { font-size: 0.8rem; color: var(--muted); }

.artifact-list { list-style: none; padding: 0; margin: 0; }
.artifact-list li { margin-bottom: 10px; }

.muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
code { background: #eef2f7; color: var(--brand); padding: 1px 5px; border-radius: 4px; font-size: 0.88em; }
pre { background: var(--brand-dark); color: #c9d3e0; padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-size: 0.82rem; }

/* ------------------------------------------------------------------
   Responsive: nav collapses to a hamburger below 900px (it has enough
   links — Drafting/Court Fee/My Documents/Activity/Credits/Profile,
   plus Default Templates for admins — to wrap onto a second line
   otherwise), then tablet (<=860px) and phone (<=600px) below that for
   the rest of the layout. Otherwise a plain flex/grid document, so most
   of this is just collapsing multi-column grids to fewer/one column.
   ------------------------------------------------------------------ */

@media (max-width: 860px) {
  .field-row-3 { grid-template-columns: 1fr 1fr; }
  .name-row { grid-template-columns: 1fr 1fr; }
  .home-hero { padding: 32px 24px; }
}

@media (max-width: 600px) {
  .container { padding: 20px 14px 48px; }
  .auth-container { margin: 32px auto; }
  .profile-wrap { width: 100%; }

  .topbar-inner { padding: 10px 16px; height: 52px; }
  .topbar.nav-collapsed .nav-panel { top: 52px; padding: 8px 16px 14px; }

  h1 { font-size: 1.35rem; }
  .home-hero { padding: 24px 18px; border-radius: 10px; }
  .home-hero h1 { font-size: 1.6rem; }

  .field-row, .field-row-3, .name-row, .type-row { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: 1fr; }

  fieldset { padding: 14px 14px; }

  table { min-width: 480px; } /* scrolls inside .card's overflow-x: auto rather than squeezing columns unreadably */
}
