/* CHG-1 Filing Assistant: single hand-written stylesheet. Mobile-first.
   No frameworks. Custom properties for theming; Grid and Flexbox for layout. */

:root {
  --c-bg: #f4f6f9;
  --c-surface: #ffffff;
  --c-border: #d8dee7;
  --c-text: #1b2733;
  --c-muted: #5b6a7c;
  --c-primary: #1a4b8b;
  --c-primary-dark: #123a6f;
  --c-on-primary: #ffffff;
  --c-danger: #b3261e;
  --c-danger-bg: #fdecea;
  --c-ok: #1d6f42;
  --c-ok-bg: #e6f4ec;
  --c-warn: #8a6d00;
  --c-warn-bg: #fff7dd;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 30, 54, 0.12);
  --topbar-h: 52px;
  --rail-w: 60px;
  --panel-w: 224px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 var(--space-3);
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 var(--space-2);
}

a {
  color: var(--c-primary);
}

.muted {
  color: var(--c-muted);
}

.plain-list {
  margin: 0;
  padding-left: 1.2rem;
}

.container {
  max-width: 1100px;
  margin-inline: auto;
  padding: var(--space-3);
}

/* ---- Top bar, left sidebar and content ---- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  background: var(--c-primary);
  color: var(--c-on-primary);
  box-shadow: var(--shadow);
  z-index: 40;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--c-on-primary);
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.topbar-user {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}

.topbar-logout {
  margin: 0;
}

.topbar-logout .btn-link {
  color: var(--c-on-primary);
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: var(--c-on-primary);
  border-radius: var(--radius);
  padding: var(--space-1);
  cursor: pointer;
}

.nav-toggle svg {
  width: 22px;
  height: 22px;
  display: block;
}

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-x: hidden;
  overflow-y: auto;
  transition: width 0.18s ease;
  z-index: 30;
}

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

.nav a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius);
  color: var(--c-text);
  text-decoration: none;
  white-space: nowrap;
}

.nav a:hover {
  background: var(--c-bg);
}

.nav a.active {
  background: var(--c-primary);
  color: var(--c-on-primary);
}

.nav-ico {
  flex: 0 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-ico svg {
  width: 22px;
  height: 22px;
  display: block;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-backdrop {
  display: none;
}

.content {
  margin-top: var(--topbar-h);
  margin-left: var(--panel-w);
  padding: var(--space-4);
  transition: margin-left 0.18s ease;
}

/* Collapsed: icon rail only */
.nav-collapsed .sidebar {
  width: var(--rail-w);
}

.nav-collapsed .content {
  margin-left: var(--rail-w);
}

.nav-collapsed .nav-label {
  display: none;
}

.nav-collapsed .nav a {
  justify-content: center;
  gap: 0;
}

/* Mobile: the expanded panel overlays content instead of pushing it */
@media screen and (max-width: 767px) {
  .content {
    margin-left: var(--rail-w) !important;
  }

  .sidebar {
    box-shadow: var(--shadow);
  }

  .nav-collapsed .sidebar {
    box-shadow: none;
  }

  html:not(.nav-collapsed) .nav-backdrop {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(16, 30, 54, 0.4);
    z-index: 25;
  }
}

/* Narrow phones: keep the brand mark, drop its text so the top bar fits */
@media screen and (max-width: 559px) {
  .brand-label {
    display: none;
  }
}

/* ---- Forms ---- */

label {
  display: block;
  font-weight: 600;
  margin: var(--space-3) 0 var(--space-1);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font: inherit;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

.field-hint {
  font-size: 0.85rem;
  color: var(--c-muted);
  margin: var(--space-1) 0 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.check-row label {
  margin: 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.form-narrow {
  max-width: 32rem;
}

/* ---- Buttons ---- */

.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: var(--c-on-primary);
}

.btn-primary:hover {
  background: var(--c-primary-dark);
}

.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.btn-block {
  display: block;
  width: 100%;
  margin-top: var(--space-4);
}

.btn-link {
  background: none;
  border: none;
  padding: var(--space-2);
  font: inherit;
  color: var(--c-primary);
  text-decoration: underline;
  cursor: pointer;
}

/* ---- Panels, login card, flash messages ---- */

.panel {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.auth-card {
  max-width: 24rem;
  margin: 10vh auto 0;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

.auth-card h1 {
  font-size: 1.2rem;
}

.flash {
  padding: var(--space-2) var(--space-3);
  border: 1px solid currentColor;
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
}

.flash-ok {
  background: var(--c-ok-bg);
  color: var(--c-ok);
}

.flash-error {
  background: var(--c-danger-bg);
  color: var(--c-danger);
}

.token-box {
  font-family: var(--font-mono);
  background: var(--c-warn-bg);
  border: 1px dashed var(--c-warn);
  border-radius: var(--radius);
  padding: var(--space-3);
  word-break: break-all;
  margin: var(--space-2) 0;
}

.token-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

.token-row .token-box {
  /* Size to the fixed-length token so the Copy button sits beside it, but
     allow shrinking and wrapping on narrow screens (no horizontal scroll). */
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
}

.copy-status {
  display: inline-block;
  min-height: 1.2em;
  margin-top: var(--space-1);
  font-size: 0.85rem;
  color: var(--c-muted);
}

.copy-status.ok {
  color: var(--c-ok);
}

.copy-status.error {
  color: var(--c-danger);
}

/* ---- Page head and stat cards ---- */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.page-head h1 {
  margin: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-3);
}

.stat-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-label {
  color: var(--c-muted);
  font-size: 0.9rem;
}

/* ---- Badges ---- */

.badge {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-role {
  background: #e8eef7;
  color: var(--c-primary);
  text-transform: capitalize;
}

.badge-ok {
  background: var(--c-ok-bg);
  color: var(--c-ok);
}

.badge-off {
  background: #eceff3;
  color: var(--c-muted);
}

/* ---- Data tables: stacked cards on narrow screens, real table from 768px ---- */

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  display: none;
}

.data-table tr {
  display: block;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
}

.data-table td {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) 0;
  border: 0;
  text-align: right;
}

.data-table td::before {
  content: attr(data-label);
  font-weight: 600;
  color: var(--c-muted);
  text-align: left;
}

.data-table td:empty {
  display: none;
}

@media (min-width: 768px) {
  .data-table thead {
    display: table-header-group;
  }

  .data-table tr {
    display: table-row;
    background: var(--c-surface);
    border: 0;
    box-shadow: none;
  }

  .data-table th,
  .data-table td {
    display: table-cell;
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--c-border);
  }

  .data-table td::before {
    content: none;
  }

  .data-table td:empty {
    display: table-cell;
  }

  .data-table thead th {
    border-bottom: 2px solid var(--c-border);
  }
}

/* ---- Case status badges and field source tags ---- */

.badge-status-draft {
  background: #eceff3;
  color: var(--c-muted);
}

.badge-status-extracted,
.badge-status-enriched,
.badge-status-validated {
  background: #e3edf9;
  color: var(--c-primary);
}

.badge-status-pending_approval {
  background: var(--c-warn-bg);
  color: var(--c-warn);
}

.badge-status-approved {
  background: var(--c-ok-bg);
  color: var(--c-ok);
}

.badge-status-filled,
.badge-status-submitted {
  background: var(--c-primary);
  color: var(--c-on-primary);
}

.source-tag {
  display: inline-block;
  margin-left: var(--space-1);
  padding: 0 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: #eceff3;
  color: var(--c-muted);
  vertical-align: middle;
}

.source-tag-bank_master {
  background: #e3edf9;
  color: var(--c-primary);
}

.source-tag-deed {
  background: var(--c-ok-bg);
  color: var(--c-ok);
}

.source-tag-board_resolution {
  background: #e2f0ee;
  color: #0f766e;
}

.source-tag-checklist {
  background: #fce8ef;
  color: #a3315e;
}

.source-tag-web {
  background: var(--c-warn-bg);
  color: var(--c-warn);
}

.source-tag-derived {
  background: #f0e8f7;
  color: #6b3fa0;
}

/* ---- Filing checklist ---- */

.checklist-note {
  color: var(--c-muted);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

/* ---- Approval readiness banner ---- */

.readiness {
  border: 1px solid;
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  margin-bottom: var(--space-3);
  font-size: 0.9rem;
}

.readiness-ok {
  background: var(--c-ok-bg);
  border-color: var(--c-ok);
  color: var(--c-ok);
}

.readiness-blocked {
  background: var(--c-danger-bg);
  border-color: var(--c-danger);
  color: var(--c-danger);
}

.readiness-head {
  font-weight: 600;
  margin: 0;
}

.readiness .plain-list {
  margin: 0.4rem 0 0;
}

.readiness-warn {
  margin: 0.6rem 0 0;
  color: var(--c-text);
}

.readiness-note {
  margin: 0.6rem 0 0;
  color: var(--c-muted);
  font-size: 0.82rem;
}

.checklist-summary {
  background: var(--c-danger-bg);
  color: var(--c-danger);
  border: 1px solid var(--c-danger);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.checklist-summary-ok {
  background: var(--c-ok-bg);
  color: var(--c-ok);
  border-color: var(--c-ok);
}

.checklist-table .chk-num {
  width: 2.2rem;
  color: var(--c-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  vertical-align: top;
}

.chk-req {
  color: var(--c-danger);
}

.chk-missing {
  color: var(--c-danger);
  font-weight: 700;
  letter-spacing: 0.1em;
}

.chk-row-missing th,
.chk-row-missing td {
  background: var(--c-danger-bg);
}

/* ---- Two-column form grid and case detail ---- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.form-grid .field label {
  margin: 0 0 var(--space-1);
}

.form-grid .field .field-hint {
  margin-top: var(--space-1);
}

@media (min-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid .field-wide {
    grid-column: 1 / -1;
  }
}

h3 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--c-muted);
  margin: var(--space-4) 0 var(--space-2);
}

textarea {
  min-height: 5.5rem;
  resize: vertical;
}

input[type="file"] {
  width: 100%;
  padding: var(--space-2) 0;
  font: inherit;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-3);
  color: var(--c-muted);
}

.meta-row strong {
  color: var(--c-text);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.filter-row label {
  margin: 0;
}

.filter-row select {
  width: auto;
}

.inline-form {
  display: inline;
  margin: 0;
}

/* ---- Deadline traffic lights ---- */

.deadline-ok {
  background: var(--c-ok-bg);
  color: var(--c-ok);
}

.deadline-amber {
  background: var(--c-warn-bg);
  color: var(--c-warn);
}

.deadline-red {
  background: var(--c-danger-bg);
  color: var(--c-danger);
}

/* ---- Validation results ---- */

.rule-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rule-list li {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  padding: var(--space-1) 0;
}

.rule-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--c-border);
}

.rule-pass .rule-dot {
  background: var(--c-ok);
}

.rule-warn .rule-dot {
  background: var(--c-warn);
}

.rule-fail .rule-dot {
  background: var(--c-danger);
}

.rule-msg {
  color: var(--c-muted);
  font-size: 0.9rem;
}

.rule-skip {
  opacity: 0.6;
}

.action-bar {
  margin-top: 0;
  margin-bottom: var(--space-3);
}

/* ---- Approval sheet ---- */

.sheet-head {
  margin-bottom: var(--space-3);
}

.sheet-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 var(--space-2);
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}

.sheet-table th {
  text-align: left;
  width: 40%;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--c-muted);
  padding: 0.45rem 0.75rem;
  vertical-align: top;
  border-bottom: 1px solid var(--c-border);
}

.sheet-table td {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 0.45rem 0.75rem;
  vertical-align: top;
  border-bottom: 1px solid var(--c-border);
}

.sheet-table tr:last-child th,
.sheet-table tr:last-child td {
  border-bottom: 0;
}

/* ---- Print: the approval sheet prints clean ---- */

@media print {
  .topbar,
  .sidebar,
  .nav-backdrop,
  .btn,
  .nav-toggle,
  .no-print,
  .flash {
    display: none !important;
  }

  body {
    background: #ffffff;
    font-size: 11pt;
  }

  .container,
  .content {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .sheet-table {
    border: 0;
  }

  .sheet-table th,
  .sheet-table td {
    border-bottom: 1px solid #ccc;
    padding: 4pt 6pt;
  }

  .source-tag {
    border: 1px solid #999;
    background: none;
    color: #555;
  }
}
