/* ==========================================================================
   Tulasi Group portal theme
   One stylesheet for every V2 portal route: applicant intake, staff sign-in
   and recovery, staff home and the recruitment workspace.

   1. Tokens       design decisions, defined once
   2. Base         element defaults
   3. Components   shared building blocks used by every page
   4. Layouts      page-specific arrangement only (no colours or fonts)
   5. Responsive
   ========================================================================== */

/* ---- 1. Tokens ---------------------------------------------------------- */
:root {
  /* Surfaces, text and lines */
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-subtle: #f8f9fc;
  --surface-hover: #edf0f6;
  --ink: #161d2b;
  --muted: #536075;
  --line: #dce2eb;
  --line-strong: #b9c3d2;
  --field-line: #7f8ba0;

  /* Accent */
  --accent: #3347b5;
  --accent-strong: #263792;
  --accent-soft: #e9ecfb;
  --accent-soft-hover: #dce1f8;
  --on-accent: #ffffff;

  /* Status */
  --ok-bg: #e2f3e9;
  --ok-ink: #17593a;
  --ok-line: #b5dcc5;
  --warn-bg: #fdf0d3;
  --warn-ink: #734600;
  --danger-bg: #fdecec;
  --danger-ink: #9b1c1c;
  --danger-line: #f3c3c3;
  --neutral-bg: #eceff4;
  --neutral-ink: #3c4758;

  /* Sidebar (the one dark surface) */
  --nav-bg: #141b2b;
  --nav-ink: #c9d1e0;
  --nav-strong: #ffffff;
  --nav-muted: #96a2ba;
  --nav-hover: #1e2740;
  --nav-active: #27324d;
  --nav-line: #2a3450;
  --nav-indicator: #8fa2ff;
  --nav-focus: #a9b8ff;
  --nav-control-line: #4a5672;
  --nav-control-line-hover: #6a779a;

  /* Typography */
  --font-sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --text-xs: .75rem;
  --text-sm: .8125rem;
  --text-base: .875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
  --weight-medium: 500;
  --weight-strong: 600;
  --leading: 1.5;
  --leading-tight: 1.25;

  /* Spacing (4px steps) */
  --space-half: 2px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-14: 56px;
  --card-pad: 18px;

  /* Controls */
  --control-height: 36px;
  --control-height-touch: 40px;
  --control-pad: 6px var(--space-3);
  --disabled-opacity: .6;

  /* Shape, elevation and focus */
  --radius: 10px;
  --radius-control: 7px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px #161d2b0a;
  --shadow-raised: 0 4px 14px #161d2b33;
  --focus-color: var(--accent);
  --focus-width: 2px;
}

/* ---- 2. Base ------------------------------------------------------------ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root { font-family: var(--font-sans); line-height: var(--leading); color: var(--ink); background: var(--bg); }
body { margin: 0; font-size: var(--text-base); }
main { min-width: 0; }
h1, h2, h3 { margin: 0; font-size: var(--text-md); font-weight: var(--weight-strong); letter-spacing: -.01em; line-height: var(--leading-tight); }
h1 { font-size: var(--text-xl); }
p { margin: 0; }
code { font-family: var(--font-mono); font-size: .95em; }
a { color: var(--accent); font-weight: var(--weight-strong); text-underline-offset: .18em; }
a:hover { color: var(--accent-strong); }
:focus-visible, .segmented input:focus-visible + label { outline: var(--focus-width) solid var(--focus-color); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }

/* ---- 3. Components ------------------------------------------------------ */

/* Text helpers */
.muted { color: var(--muted); }
.meta { font-size: var(--text-sm); color: var(--muted); }
.tag, .facts dt { font-size: var(--text-xs); font-weight: var(--weight-strong); color: var(--muted); letter-spacing: .02em; }
.text-center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; left: var(--space-3); top: -60px; z-index: 10; padding: var(--space-2) var(--space-4); border-radius: var(--radius-control); background: var(--surface); box-shadow: var(--shadow-raised); }
.skip-link:focus { top: var(--space-3); }
.reference { justify-self: start; max-width: 100%; padding: var(--space-2) var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--surface-subtle); font-family: var(--font-mono); overflow-wrap: anywhere; }

/* Brand */
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: var(--radius-control); background: var(--accent); color: var(--on-accent); font-size: var(--text-sm); font-weight: var(--weight-strong); letter-spacing: .03em; }
.brand-text { display: grid; line-height: var(--leading-tight); }
.brand-text strong { font-size: var(--text-md); font-weight: var(--weight-strong); color: var(--ink); }
.brand-text span { font-size: var(--text-xs); color: var(--muted); }

/* Buttons: variants only set the --btn-* values. */
.btn {
  --btn-bg: var(--accent);
  --btn-line: var(--accent);
  --btn-ink: var(--on-accent);
  --btn-hover-bg: var(--accent-strong);
  --btn-hover-line: var(--accent-strong);
  --btn-hover-ink: var(--on-accent);
  display: inline-flex; align-items: center; justify-content: center; min-height: var(--control-height); margin: 0; padding: var(--space-1) var(--space-4); border: 1px solid var(--btn-line); border-radius: var(--radius-control); background: var(--btn-bg); color: var(--btn-ink); font-family: inherit; font-size: var(--text-base); font-weight: var(--weight-strong); line-height: var(--leading-tight); text-decoration: none; cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--btn-hover-bg); border-color: var(--btn-hover-line); color: var(--btn-hover-ink); }
.btn:disabled { cursor: default; }
.btn-quiet { --btn-bg: var(--surface); --btn-line: var(--line-strong); --btn-ink: var(--ink); --btn-hover-bg: var(--surface-hover); --btn-hover-line: var(--field-line); --btn-hover-ink: var(--ink); }
.btn-link { --btn-bg: var(--accent-soft); --btn-line: transparent; --btn-ink: var(--accent-strong); --btn-hover-bg: var(--accent-soft-hover); --btn-hover-line: transparent; --btn-hover-ink: var(--accent-strong); }
.btn-nav { --btn-bg: transparent; --btn-line: var(--nav-control-line); --btn-ink: var(--nav-ink); --btn-hover-bg: var(--nav-active); --btn-hover-line: var(--nav-control-line-hover); --btn-hover-ink: var(--nav-strong); }
.btn-block { width: 100%; }

/* Forms and fields */
.form-stack { --control-height: var(--control-height-touch); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
.field { display: grid; gap: var(--space-1); min-width: 0; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
label, legend { display: block; margin: 0; padding: 0; font-size: var(--text-sm); font-weight: var(--weight-strong); }
legend { margin-bottom: var(--space-1); }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.form-section > legend { margin-bottom: var(--space-3); font-size: var(--text-md); }
input, select, textarea { display: block; width: 100%; min-height: var(--control-height); padding: var(--control-pad); border: 1px solid var(--field-line); border-radius: var(--radius-control); background: var(--surface); color: var(--ink); font: inherit; }
textarea { resize: vertical; }
:is(input, textarea)::placeholder { color: var(--muted); opacity: 1; }
:is(input, select, textarea):focus-visible { outline-offset: 0; border-color: var(--accent); }
:is(input, textarea)[aria-invalid="true"] { border-color: var(--danger-ink); box-shadow: inset 0 0 0 1px var(--danger-ink); }
input[type="file"] { padding: var(--space-1); color: var(--muted); }
input::file-selector-button { margin-inline-end: var(--space-3); padding: var(--space-1) var(--space-3); border: 1px solid var(--line-strong); border-radius: calc(var(--radius-control) - 1px); background: var(--surface-subtle); color: var(--ink); font: inherit; font-weight: var(--weight-strong); cursor: pointer; }
fieldset:disabled { opacity: var(--disabled-opacity); }
:is(.btn, input, select, textarea, .combo-clear):disabled:not(fieldset:disabled *) { opacity: var(--disabled-opacity); }
.field-error { font-size: var(--text-sm); font-weight: var(--weight-strong); color: var(--danger-ink); }
.check { display: flex; align-items: flex-start; gap: var(--space-2); }
.check input { flex: none; width: 18px; height: 18px; min-height: 0; margin: 1px 0 0; padding: 0; accent-color: var(--accent); }
.check label { font-size: var(--text-base); cursor: pointer; }
.actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row-edit { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row-edit input { flex: 1 1 180px; width: auto; max-width: 320px; }
.row-edit .field-error { flex: 1 0 100%; }

/* Combobox (searchable single choice with a popup list) */
.combo { position: relative; }
.combo input { padding-inline-end: calc(var(--control-height) + var(--space-1)); }
.combo-clear { position: absolute; inset-block-start: 0; inset-inline-end: 0; display: grid; place-items: center; width: var(--control-height); height: var(--control-height); margin: 0; padding: 0; border: 0; border-radius: var(--radius-control); background: none; color: var(--muted); font: inherit; font-size: var(--text-lg); line-height: 1; cursor: pointer; }
.combo-clear:hover:not(:disabled) { color: var(--ink); }
.combo-popup { position: absolute; z-index: 5; inset-inline: 0; top: calc(100% + var(--space-1)); border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--surface); box-shadow: var(--shadow-raised); overflow: hidden; }
.combo-list { max-height: 264px; margin: 0; padding: var(--space-1); list-style: none; overflow-y: auto; }
.combo-option { padding: var(--space-2) var(--space-3); border-radius: calc(var(--radius-control) - 1px); overflow-wrap: anywhere; cursor: pointer; }
.combo-option:hover { background: var(--surface-hover); }
.combo-option.is-active { background: var(--accent-soft); color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent); }
.combo-option[aria-selected="true"] { font-weight: var(--weight-strong); }
.combo-note { padding: var(--space-2) var(--space-3); border-top: 1px solid var(--line); background: var(--surface-subtle); }

/* Segmented choice (radio group drawn as one control) */
.segmented { position: relative; }
.segmented-options { display: flex; border: 1px solid var(--field-line); border-radius: var(--radius-control); background: var(--surface); }
.segmented input { position: absolute; width: 1px; height: 1px; min-height: 0; margin: 0; padding: 0; border: 0; opacity: 0; }
.segmented label { display: inline-flex; align-items: center; gap: var(--space-2); min-height: calc(var(--control-height) - 2px); padding: var(--space-1) var(--space-3); border-radius: calc(var(--radius-control) - 1px); font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--muted); white-space: nowrap; cursor: pointer; }
.segmented label:hover { color: var(--ink); }
.segmented input:checked + label { background: var(--accent-soft); color: var(--accent-strong); font-weight: var(--weight-strong); box-shadow: inset 0 0 0 1px var(--accent); }
.count { font-variant-numeric: tabular-nums; font-weight: var(--weight-strong); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-4) var(--card-pad); border-bottom: 1px solid var(--line); }
.card-foot { display: flex; align-items: center; gap: var(--card-pad); flex-wrap: wrap; padding: var(--space-4) var(--card-pad); }
.card-foot-ruled { border-top: 1px solid var(--line); }
.card-foot:empty { display: none; }
.card-body { padding: var(--space-5) var(--card-pad); }
.card-title { font-size: var(--text-lg); font-weight: var(--weight-strong); }
.card-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); padding: var(--space-7); }
.card-link { display: grid; gap: var(--space-half); height: 100%; padding: var(--space-4) var(--card-pad); color: var(--ink); font-weight: inherit; text-decoration: none; }
.card-link:hover { border-color: var(--accent); color: var(--ink); }
.card-link-action { margin-top: var(--space-3); font-weight: var(--weight-strong); color: var(--accent); }
.card-link:hover .card-link-action { text-decoration: underline; text-underline-offset: .18em; }
.metric-value { font-size: var(--text-2xl); font-weight: var(--weight-strong); line-height: var(--leading-tight); font-variant-numeric: tabular-nums; }

/* Fact lists */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-4); margin: 0; padding: var(--space-4) var(--card-pad); }
.facts dd { margin: var(--space-half) 0 0; font-weight: var(--weight-strong); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.facts-band { border-bottom: 1px solid var(--line); background: var(--surface-subtle); }

/* Notices, badges and states */
.notice { padding: var(--space-3) var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--surface-subtle); color: var(--muted); }
.notice-error { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger-ink); }
.notice-ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.notice:empty, .field-error:empty, [role="status"]:empty { display: none; }
.badges { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.badge { display: inline-block; padding: var(--space-half) var(--space-2); border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-strong); white-space: nowrap; }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-ink); }
.empty { display: grid; gap: var(--space-2); justify-items: center; padding: var(--space-8) var(--card-pad); text-align: center; color: var(--muted); }
.state { display: grid; gap: var(--space-4); justify-items: start; padding: var(--space-5); color: var(--muted); }

/* Data tables */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: var(--space-3) var(--card-pad) var(--space-3) 0; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; font-weight: inherit; }
.data-table th:first-child, .data-table td:first-child { padding-inline-start: var(--card-pad); }
.data-table thead th { padding-block: var(--space-2); border-top: 1px solid var(--line); background: var(--surface-subtle); font-size: var(--text-xs); font-weight: var(--weight-strong); color: var(--muted); letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.card-head + * .data-table thead th { border-top: 0; }
.data-table tbody tr:hover { background: var(--surface-subtle); }
.data-table tbody tr:last-child > * { border-bottom: 0; }
.data-table td { white-space: nowrap; font-variant-numeric: tabular-nums; }
.applicant-name { display: block; font-weight: var(--weight-strong); }
.applicant-line { display: block; overflow-wrap: anywhere; }

/* ---- 4. Layouts --------------------------------------------------------- */

/* Vertical rhythm */
.stack, .stack-sm { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-5); }
.stack-sm { gap: var(--space-3); }
.page-head { display: grid; gap: var(--space-1); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); margin: 0; padding: 0; list-style: none; }

/* Account pages: sign-in, forgot password, reset password */
.auth { display: grid; place-items: center; min-height: 100vh; padding: var(--space-8) var(--space-4); }
.auth-inner { display: grid; gap: var(--space-5); width: min(400px, 100%); }

/* Applicant intake */
.page-width { width: min(1040px, 100% - var(--space-8)); margin-inline: auto; }
.intake-bar { padding-block: var(--space-3); border-bottom: 1px solid var(--line); background: var(--surface); }
.intake { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); align-items: start; gap: clamp(var(--space-6), 6vw, var(--space-14)); padding-block: clamp(var(--space-6), 6vw, var(--space-14)); }

/* Staff app shell. The sidebar is a dark surface: it remaps the text and focus
   tokens once so shared components placed on it (brand, focus ring) follow. */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.app-nav { --ink: var(--nav-strong); --muted: var(--nav-muted); --focus-color: var(--nav-focus); position: sticky; top: 0; display: flex; flex-direction: column; gap: var(--space-6); height: 100vh; padding: var(--space-5) var(--space-4); background: var(--nav-bg); color: var(--nav-ink); }
.nav-list { display: grid; gap: var(--space-half); margin: 0; padding: 0; list-style: none; }
.nav-list a { display: block; padding: var(--space-2) var(--space-3); border-radius: var(--radius-control); color: var(--nav-ink); font-weight: var(--weight-medium); text-decoration: none; }
.nav-list a:hover { background: var(--nav-hover); color: var(--nav-strong); }
.nav-list a[aria-current="page"] { background: var(--nav-active); color: var(--nav-strong); font-weight: var(--weight-strong); box-shadow: inset 3px 0 0 var(--nav-indicator); }
.account { display: grid; gap: var(--space-3); margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--nav-line); }
.account-role { display: grid; font-size: var(--text-xs); color: var(--muted); }
.account-role strong { font-size: var(--text-base); font-weight: var(--weight-strong); color: var(--ink); }
.app-main { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-5); width: 100%; max-width: 1240px; padding: var(--space-5) var(--space-8) var(--space-14); }
.main-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; min-height: var(--control-height); }
.main-bar-actions { display: flex; align-items: center; gap: var(--space-3); }

/* Settings: readable line length for forms inside wide cards */
.form-narrow { max-width: 680px; }

/* Recruitment: application filters */
.toolbar { display: flex; align-items: flex-end; gap: var(--space-4); flex-wrap: wrap; padding: var(--space-4) var(--card-pad) var(--space-3); }
.field-search { flex: 1 1 240px; max-width: 380px; }
.results-status { padding: 0 var(--card-pad) var(--space-3); }

/* ---- 5. Responsive ------------------------------------------------------ */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .app-nav { position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-4); height: auto; padding: var(--space-3) var(--space-4); }
  .app-nav nav { order: 3; flex: 1 0 100%; min-width: 0; }
  .nav-list { display: flex; gap: var(--space-1); overflow-x: auto; padding: var(--space-half); }
  .nav-list a { white-space: nowrap; }
  .nav-list a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--nav-indicator); }
  .account { display: flex; align-items: center; margin: 0 0 0 auto; padding: 0; border: 0; }
  .account-role span { display: none; }
  .app-main { padding: var(--space-4) var(--space-4) var(--space-8); }
}
@media (max-width: 720px) {
  :root { --control-height: var(--control-height-touch); }
  .intake { grid-template-columns: minmax(0, 1fr); }
  .toolbar { align-items: stretch; flex-direction: column; }
  .field-search { flex: none; max-width: none; }
  .segmented label { flex: 1; justify-content: center; }
  /* Tables become stacked records with their column labels inline. */
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .data-table, .data-table tbody, .data-table tr { display: block; }
  .data-table tbody tr { padding: var(--space-3) var(--card-pad); border-bottom: 1px solid var(--line); }
  .data-table tbody tr:first-child { border-top: 1px solid var(--line); }
  .card-head + * .data-table tbody tr:first-child { border-top: 0; }
  .data-table tbody tr:last-child { border-bottom: 0; }
  .data-table tbody th, .data-table tbody td { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: var(--space-3); padding: var(--space-half) 0; border: 0; white-space: normal; }
  .data-table tbody th { display: block; padding-bottom: var(--space-1); }
  .data-table tbody td::before { content: attr(data-label); font-size: var(--text-xs); font-weight: var(--weight-strong); color: var(--muted); }
}
@media (max-width: 440px) {
  .page-width { width: calc(100% - var(--space-7)); }
  .card-form { padding: var(--space-5) var(--card-pad); }
  .field-row { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
  .segmented label { padding-inline: var(--space-2); }
}
@media (prefers-reduced-motion: no-preference) {
  .skip-link { transition: top .12s; }
}
