/* Hand-written CSS so the project has no frontend build step.
 *
 * COLOURS LIVE HERE. Every colour in the app comes from the variables below —
 * nothing else hardcodes one — so changing the look means editing this block,
 * or better, not editing anything at all:
 *
 *   APP_THEME=purple              in .env, picks one of the themes below
 *   APP_ACCENT_COLOR=#0f766e      in .env, sets any accent colour you like
 *
 * See config/theme.py. Keep the accent dark enough that white button text
 * stays readable (4.5:1 contrast or better).
 */

:root {
  /* Default: light blue on white. */
  --bg: #f4f8fd;          /* page background, a faint blue tint */
  --surface: #ffffff;     /* cards, tables, nav */
  --surface-alt: #eff6fd; /* table headers, subtle fills */
  --border: #dbe7f5;
  --text: #0f2540;
  --muted: #5b7793;
  --brand: #1976d2;
  --brand-dark: #0d5cab;
  --brand-tint: #e3f0fc;
  --brand-ring: #bcdcfa;  /* focus outline */

  --danger-bg: #fef2f2;
  --danger-text: #b91c1c;
  --danger-border: #f3c9c9;
  --warn-bg: #fffbeb;
  --warn-text: #92400e;
  --warn-border: #fcd34d;
  --ok-bg: #f0fdf4;
  --ok-text: #15803d;
}

/* Alternate themes, selected with APP_THEME. Each only needs to restate what
 * differs from the light-blue default. Mirrored in config/theme.py so exports
 * pick up the same accent. */

[data-theme='purple'] {
  --bg: #f8f7fc;
  --surface-alt: #f3f0fa;
  --border: #e5e0f0;
  --text: #1c1330;
  --muted: #6b6480;
  --brand: #4c2a85;
  --brand-dark: #3b2068;
  --brand-tint: #f1ecfa;
  --brand-ring: #cdbdf0;
}

[data-theme='teal'] {
  --bg: #f2faf9;
  --surface-alt: #e9f6f4;
  --border: #d3e9e6;
  --text: #0d2b28;
  --muted: #5a7c78;
  --brand: #0f766e;
  --brand-dark: #0b5c56;
  --brand-tint: #e0f2f0;
  --brand-ring: #a7d9d4;
}

[data-theme='indigo'] {
  --bg: #f6f6fd;
  --surface-alt: #eeeefb;
  --border: #dedef5;
  --text: #14143a;
  --muted: #61618a;
  --brand: #4338ca;
  --brand-dark: #3730a3;
  --brand-tint: #e8e7fb;
  --brand-ring: #c0bdf3;
}

[data-theme='slate'] {
  --bg: #f8fafc;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #334155;
  --brand-dark: #1e293b;
  --brand-tint: #eef2f6;
  --brand-ring: #cbd5e1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

/* --- layout ------------------------------------------------------------- */

.container { max-width: 1440px; margin: 0 auto; padding: 24px 20px 64px; }
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }

/* --- module rail --------------------------------------------------------
 * Switches between the platform's modules (Visitor Management / Courier).
 * Only shows the modules a given account actually has access to — see
 * accounts.models.User.can_view_visitors / can_view_courier.
 * Collapses to a horizontal strip above the content on narrow screens.
 *
 * Deliberately deep indigo in EVERY theme, rather than following the accent.
 * It reads as fixed furniture — like an app's title bar — so switching the
 * theme recolours the content without the whole window changing character.
 * To change it, edit the four --rail-* values here and nothing else. The
 * logo uses teachmint-logo-light.svg because the standard wordmark is dark
 * navy and disappears against this background. */

:root {
  --rail-bg: #312e81;
  --rail-text: rgba(255, 255, 255, .72);
  --rail-hover-bg: rgba(255, 255, 255, .10);
  --rail-active-bg: rgba(255, 255, 255, .16);
}

.app-shell { display: flex; min-height: 100vh; }
.module-rail {
  width: 208px; flex-shrink: 0; background: var(--rail-bg);
  padding: 20px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.module-rail-brand { padding: 0 10px 18px; }
.module-link {
  display: block; padding: 10px 12px; border-radius: 8px;
  color: var(--rail-text); font-weight: 500;
  transition: background .15s, color .15s;
}
.module-link:hover { background: var(--rail-hover-bg); color: #fff; text-decoration: none; }
.module-link.active { background: var(--rail-active-bg); color: #fff; font-weight: 600; }
.app-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .module-rail {
    width: auto; flex-direction: row; align-items: center;
    padding: 10px 12px;
  }
  .module-rail-brand { padding: 0 12px 0 0; }
}

/* --- nav ---------------------------------------------------------------- */

/* Shares the rail's indigo, so the two form one continuous header rather than
 * a dark sidebar bolted onto a white bar. Same --rail-* variables, so changing
 * the shade in one place recolours both. */
.nav {
  background: var(--rail-bg);
  border-bottom: 1px solid rgba(255, 255, 255, .10);
}
.nav-inner {
  max-width: 1440px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.nav-left { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
/* margin-left: auto keeps this hugging the right edge even when nav-left's
 * links overflow and force it onto its own wrapped line — without it,
 * justify-content: space-between leaves a lone wrapped item at the start
 * (left) of that line instead of the end. */
.nav-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.brand { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.brand-logo { height: 22px; width: auto; display: block; }
/* Pill treatment matching the rail's links, so "where am I" reads the same in
 * both. Colour alone would be a weak signal against the indigo. */
.nav a {
  color: var(--rail-text); font-weight: 500;
  padding: 6px 10px; border-radius: 8px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--rail-hover-bg); color: #fff; text-decoration: none; }
.nav a.active { background: var(--rail-active-bg); color: #fff; font-weight: 600; }

.badge {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  background: var(--brand-tint); color: var(--brand-dark);
  padding: 2px 8px; border-radius: 999px;
}

/* --- account menu -------------------------------------------------------
 * A <details>/<summary> dropdown, so the toggle itself needs no JavaScript.
 * The email is the trigger; role and Sign out live in the panel. */

.user-menu { position: relative; }
/* Sits on the indigo bar, so it takes the rail's light-on-dark treatment.
 * The dropdown panel below stays a normal white card. */
.user-menu > summary {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; cursor: pointer;
  color: var(--rail-text); font-weight: 500; list-style: none;
  border: 1px solid transparent;
  transition: background .15s, color .15s;
}
/* Hide the default disclosure triangle in both engine families. */
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary::marker { content: ''; }
.user-menu > summary:hover { background: var(--rail-hover-bg); color: #fff; }
.user-menu[open] > summary { background: var(--rail-active-bg); color: #fff; }
.user-menu > summary:focus-visible { outline: 2px solid rgba(255, 255, 255, .55); outline-offset: 1px; }
.user-menu-caret { font-size: 10px; transition: transform .15s; }
.user-menu[open] .user-menu-caret { transform: rotate(180deg); }
.user-menu-email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 220px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .10);
}

/* --- generic dropdown ---------------------------------------------------
 * A button that opens a short list of actions, used where several related
 * buttons would otherwise crowd a toolbar (e.g. the export formats on the
 * Visitors page). Same <details> mechanism as the account menu — the toggle
 * needs no JavaScript, and base.html's shared handler closes it on an
 * outside click or Escape. */

.menu { position: relative; display: inline-block; }
.menu > summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::marker { content: ''; }
.menu > summary:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 1px; }
.menu-caret { font-size: 10px; transition: transform .15s; }
.menu[open] .menu-caret { transform: rotate(180deg); }

.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .10);
}
.menu-panel a {
  display: block; padding: 8px 10px; border-radius: 6px;
  color: var(--text); font-weight: 500; white-space: nowrap;
}
.menu-panel a:hover { background: var(--surface-alt); text-decoration: none; }
/* Required, not defensive: the browser's hiding of closed <details> content
 * does not apply to an absolutely-positioned child, so without this the
 * panel stays on screen with the menu shut. */
.menu:not([open]) .menu-panel { display: none; }
/* Required, not belt-and-braces: the browser's own hiding of closed <details>
 * content does not apply to an absolutely-positioned child, so without this
 * the panel stays on screen with the menu shut. */
.user-menu:not([open]) .user-menu-panel { display: none; }
.user-menu-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 12px; margin-bottom: 10px;
}

.pill {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-alt); color: var(--muted); white-space: nowrap;
}
.pill-inside { background: var(--ok-bg); color: var(--ok-text); }
.pill-danger { background: var(--danger-bg); color: var(--danger-text); }

.linkish {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-weight: 500; color: var(--muted);
}
.linkish:hover { color: var(--text); }

/* --- cards & panels ----------------------------------------------------- */

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.panel-body { padding: 16px; }

h1 { font-size: 18px; margin: 0 0 4px; }
h2 { font-size: 14px; margin: 0; }
.subtitle { color: var(--muted); margin: 0 0 16px; }
.muted { color: var(--muted); }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; color: inherit; text-decoration: none;
  transition: border-color .15s, box-shadow .15s;
}
a.stat:hover { border-color: var(--brand); box-shadow: 0 1px 8px rgba(0, 0, 0, .08); text-decoration: none; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 2px; }

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.theme-swatch {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 14px; border-radius: 10px; border: 2px solid var(--border);
  background: var(--surface); color: inherit; font: inherit; text-align: left;
  cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.theme-swatch:hover { border-color: var(--brand); }
.theme-swatch.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-ring); }
.theme-swatch-dot { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(0, 0, 0, .12); }

.stack > * + * { margin-top: 20px; }

.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.group-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  margin: 18px 0 6px;
}
.panel-body > .group-title:first-child { margin-top: 0; }

/* --- forms -------------------------------------------------------------- */

.filters {
  display: grid; gap: 10px; align-items: end;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
/* The search box earns more room than the single-purpose dropdowns. */
.filters > label.field:first-child { grid-column: span 2; }
@media (max-width: 760px) {
  .filters { grid-template-columns: 1fr; }
  .filters > label.field:first-child { grid-column: auto; }
}

label.field { display: block; }
label.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="date"], input[type="email"], select {
  width: 100%; padding: 8px 10px; font: inherit;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--brand-ring); outline-offset: 0; border-color: var(--brand); }

.btn {
  display: inline-block; padding: 8px 14px; font: inherit; font-weight: 500;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger { color: var(--danger-text); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Keeps the per-row selects and buttons on one line inside a table cell. */
.inline-form { display: flex; gap: 6px; align-items: center; }

textarea {
  width: 100%; padding: 8px 10px; font: inherit; resize: vertical;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
textarea:focus { outline: 2px solid var(--brand-ring); outline-offset: 0; border-color: var(--brand); }

.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }

.add-grid { display: grid; grid-template-columns: 1fr 200px; gap: 16px; align-items: start; }
.add-actions { display: grid; gap: 10px; }
@media (max-width: 760px) { .add-grid { grid-template-columns: 1fr; } }

.row-muted td { opacity: .6; }
.row-muted td:first-child, .row-muted td:nth-child(4) { opacity: 1; }

/* --- tables ------------------------------------------------------------- */

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 16px; text-align: left; white-space: nowrap; }
th { background: var(--surface-alt); color: var(--muted); font-weight: 500; font-size: 13px; }
tbody tr { border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-alt); }
td.wrap, th.wrap { white-space: normal; }
.empty { padding: 18px 16px; color: var(--muted); }

/* --- pagination --------------------------------------------------------- */

.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border);
  color: var(--muted); flex-wrap: wrap;
}
.pagination .pages { display: flex; align-items: center; gap: 10px; }
.pagination .disabled { opacity: .45; pointer-events: none; }

/* --- detail list -------------------------------------------------------- */

.detail { display: grid; gap: 0; }
.detail-row { display: flex; justify-content: space-between; gap: 20px; padding: 10px 0; border-top: 1px solid var(--border); }
.detail-row:first-child { border-top: 0; }
.detail-row dt { color: var(--muted); margin: 0; }
.detail-row dd { margin: 0; font-weight: 500; text-align: right; }

/* --- chart -------------------------------------------------------------- */

.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--brand); }
.chart .bar:hover { fill: var(--brand-dark); }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 9px; }

/* --- messages ----------------------------------------------------------- */

.messages { margin-bottom: 16px; display: grid; gap: 8px; }
.message { padding: 9px 12px; border-radius: 6px; font-size: 13px; }
.message.error { background: var(--danger-bg); color: var(--danger-text); }
.message.warning { background: var(--warn-bg); color: var(--warn-text); }
.message.success { background: var(--ok-bg); color: var(--ok-text); }
.message.info { background: var(--brand-tint); color: var(--brand-dark); }

/* --- login -------------------------------------------------------------- */

.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 28px;
}
.dev-box {
  margin-top: 22px; padding: 14px;
  border: 1px dashed var(--warn-border); border-radius: 8px; background: var(--warn-bg);
}
.dev-box .dev-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--warn-text);
}
.dev-box p { font-size: 12px; color: var(--warn-text); margin: 4px 0 10px; }
.dev-box > * + * { margin-top: 8px; }
/* Deliberately NOT themed: the dev-login button stays amber in every theme so
 * it always reads as "this is not a normal control". */
.btn-warn { background: #d97706; border-color: #d97706; color: #fff; width: 100%; }
.btn-warn:hover { background: #b45309; }
