:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #637083;
  --line: #d9e2ef;
  --primary: #1457d9;
  --primary-dark: #0d3f9f;
  --secondary: #0f766e;
  --danger: #b42318;
  --warning: #b54708;
  --success: #067647;
  --shadow: 0 16px 40px rgba(20, 33, 61, 0.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, p { margin-top: 0; }

h1 { margin-bottom: .25rem; font-size: clamp(1.8rem, 4vw, 2.65rem); }
h2 { font-size: clamp(1.25rem, 2.5vw, 1.6rem); margin-bottom: .5rem; }

code {
  background: #eef3ff;
  border: 1px solid #d6e2ff;
  border-radius: 6px;
  padding: 2px 6px;
}

.login-body {
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(circle at top left, rgba(20, 87, 217, .18), transparent 30rem),
    linear-gradient(135deg, #f4f7fb, #e9f0fc);
}

.login-shell { width: min(100%, 500px); }

.login-card, .card, .stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.login-card { padding: clamp(1.25rem, 4vw, 2rem); }

.brand-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--primary);
  color: white;
  font-weight: 800;
  letter-spacing: .04em;
  margin-bottom: 1rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--primary);
  font-size: .75rem;
  font-weight: 800;
  margin-bottom: .25rem;
}

.muted { color: var(--muted); }
.tiny { color: var(--muted); font-size: .82rem; margin-bottom: .25rem; }

.stack { display: flex; flex-direction: column; }
.gap-lg { gap: 1rem; }

.starter-box, .notice {
  background: #f8fafc;
  border: 1px dashed #b8c4d8;
  border-radius: 18px;
  padding: 1rem;
  margin-top: 1.25rem;
}

.starter-box p { margin: .35rem 0; }
.setup-notice { margin-top: 0; margin-bottom: 0; }
.setup-notice p { margin: .35rem 0 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 4vw, 2rem);
  background: white;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 { margin-bottom: 0; }
.nav-actions, .button-row {
  display: flex;
  gap: .65rem;
  flex-wrap: wrap;
  align-items: center;
}

.page-grid {
  width: min(1200px, calc(100% - 2rem));
  margin: 1.5rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.page-grid.narrow { width: min(900px, calc(100% - 2rem)); }

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.span-all { grid-column: 1 / -1; }

.card { padding: clamp(1rem, 3vw, 1.5rem); }
.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid #bed3ff;
  background: #eef4ff;
  color: var(--primary-dark);
  border-radius: 999px;
  padding: .35rem .7rem;
  font-weight: 700;
  font-size: .85rem;
  white-space: nowrap;
}

label {
  display: grid;
  gap: .4rem;
  color: #344054;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  background: white;
  color: var(--text);
  border-radius: 12px;
  padding: .78rem .85rem;
  font: inherit;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(20, 87, 217, .18);
  border-color: var(--primary);
}

.form-grid, .filters-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.compact-form {
  display: grid;
  grid-template-columns: 1fr 130px auto;
  gap: .65rem;
  align-items: end;
  margin-bottom: 1rem;
}

.span-2 { grid-column: span 2; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  padding: .8rem;
  border-radius: 14px;
}

.checkbox-row input { width: auto; }


.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: .78rem 1rem;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .35rem;
  min-height: 44px;
}

.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--secondary); color: white; }
.btn.ghost { background: #f8fafc; border-color: var(--line); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: white; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.message { font-weight: 800; min-height: 1.25rem; }
.message.error { color: var(--danger); }
.message.success { color: var(--success); }
.message.warning { color: var(--warning); }
.hidden { display: none !important; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.stat-card { padding: 1rem; }
.stat-card span { display: block; color: var(--muted); font-weight: 800; margin-bottom: .4rem; }
.stat-card strong { display: block; font-size: clamp(1.45rem, 3vw, 2rem); }
.stat-card.warning { border-color: #fed7aa; background: #fffbeb; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.small-table { max-height: 380px; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: white;
}

th, td {
  text-align: left;
  padding: .8rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

tr.major-row { background: #fff1f2; }
tr.oos-row { outline: 2px solid rgba(180, 35, 24, .15); }

.status-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: .22rem .55rem;
  font-size: .78rem;
  font-weight: 900;
  background: #eef2ff;
  color: #3730a3;
}
.status-pill.major { background: #fee2e2; color: #991b1b; }
.status-pill.minor { background: #fef3c7; color: #92400e; }
.status-pill.none { background: #dcfce7; color: #166534; }
.status-pill.inactive { background: #f1f5f9; color: #475569; }

.dialog-card {
  border: 0;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 1.25rem;
  width: min(850px, calc(100% - 2rem));
}
.dialog-card::backdrop { background: rgba(15, 23, 42, .45); }

@media (max-width: 880px) {
  .topbar { align-items: flex-start; flex-direction: column; position: static; }
  .form-grid, .filters-grid, .two-col { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-form { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .stats-grid { grid-template-columns: 1fr; }
  .nav-actions .btn { width: 100%; }
  .nav-actions { width: 100%; }
  .section-title { flex-direction: column; }
}

@media print {
  body { background: white; }
  .topbar, .button-row, .filters-grid, .no-print, .btn, dialog, .notice { display: none !important; }
  .page-grid { width: 100%; margin: 0; }
  .card, .stat-card { box-shadow: none; border: 1px solid #bbb; }
  .table-wrap { overflow: visible; }
  table { min-width: 0; font-size: 11px; }
}








/* ===== v6 responsive layout improvements ===== */
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }

.page-grid {
  width: min(1600px, calc(100% - 1.5rem));
  margin: 1rem auto 2rem;
}

.page-grid.narrow {
  width: min(950px, calc(100% - 1.5rem));
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

table {
  min-width: 0;
  table-layout: auto;
}

th, td {
  padding: .7rem .75rem;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: visible;
}

table .btn {
  padding: .55rem .7rem;
  min-height: 38px;
  border-radius: 10px;
  font-size: .9rem;
}

table .button-row {
  gap: .35rem;
}

table select {
  min-width: 92px;
  padding: .55rem .65rem;
  border-radius: 10px;
}

.compact-form {
  grid-template-columns: minmax(180px, 1.4fr) minmax(120px, .75fr) auto;
}

@media (min-width: 1181px) {
  .page-grid.two-col {
    width: min(1650px, calc(100% - 2rem));
  }
}

@media (max-width: 1180px) {
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 1050px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    position: static;
    padding: 1rem;
  }

  .nav-actions {
    width: 100%;
  }

  .nav-actions .btn {
    flex: 1 1 160px;
  }

  .card, .stat-card, .login-card {
    border-radius: 18px;
  }

  .table-wrap {
    border: 0;
    border-radius: 0;
  }

  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap th,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap table {
    background: transparent;
  }

  .table-wrap tr {
    background: white;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 8px 18px rgba(20, 33, 61, 0.06);
    margin-bottom: .8rem;
    padding: .35rem .8rem;
  }

  .table-wrap td {
    border-bottom: 1px solid #e6edf6;
    display: grid;
    grid-template-columns: minmax(120px, 34%) minmax(0, 1fr);
    gap: .75rem;
    align-items: center;
    padding: .7rem 0;
    text-align: right;
  }

  .table-wrap td::before {
    content: attr(data-label);
    color: #475467;
    font-size: .75rem;
    font-weight: 900;
    letter-spacing: .04em;
    text-align: left;
    text-transform: uppercase;
  }

  .table-wrap td:last-child {
    border-bottom: 0;
  }

  .table-wrap td[colspan] {
    display: block;
    text-align: center;
  }

  .table-wrap td[colspan]::before {
    content: "";
    display: none;
  }

  .table-wrap td .button-row {
    justify-content: flex-end;
  }

  .table-wrap td .btn {
    flex: 0 1 auto;
  }
}

@media (max-width: 700px) {
  h1 { font-size: clamp(1.55rem, 8vw, 2.15rem); }
  h2 { font-size: clamp(1.2rem, 6vw, 1.45rem); }

  .page-grid,
  .page-grid.narrow {
    width: min(100% - 1rem, 950px);
    margin-top: .75rem;
  }

  .card { padding: 1rem; }
  .form-grid, .filters-grid, .compact-form { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stat-card { padding: .8rem; }
  .stat-card strong { font-size: 1.35rem; }

  input, select, textarea, .btn {
    font-size: 1rem;
  }

  .button-row .btn {
    flex: 1 1 100%;
  }
}

@media (max-width: 520px) {
  .topbar { padding: .85rem; }
  .nav-actions .btn { width: 100%; flex-basis: 100%; }
  .stats-grid { grid-template-columns: 1fr; }
  .section-title { flex-direction: column; }

  .table-wrap tr {
    padding: .3rem .7rem;
  }

  .table-wrap td {
    display: block;
    text-align: left;
    padding: .65rem 0;
  }

  .table-wrap td::before {
    display: block;
    margin-bottom: .25rem;
  }

  .table-wrap td .button-row {
    justify-content: stretch;
  }

  .table-wrap td .btn {
    flex: 1 1 100%;
  }
}

@media print {
  body { overflow-x: visible; }
  .topbar, .button-row, .filters-grid, .no-print, .btn, dialog, .notice { display: none !important; }
  .page-grid, .page-grid.narrow, .page-grid.two-col { width: 100%; margin: 0; }
  .two-col { grid-template-columns: 1fr; }
  .card, .stat-card { box-shadow: none; border: 1px solid #bbb; }
  .table-wrap { overflow: visible; border: 1px solid #bbb; border-radius: 0; }
  .table-wrap table { display: table; width: 100%; min-width: 0; font-size: 11px; background: white; }
  .table-wrap thead { display: table-header-group; }
  .table-wrap tbody { display: table-row-group; }
  .table-wrap tr { display: table-row; box-shadow: none; border: 0; margin: 0; padding: 0; }
  .table-wrap th, .table-wrap td { display: table-cell; width: auto; text-align: left; padding: 4px; border-bottom: 1px solid #ddd; }
  .table-wrap td::before { content: none !important; display: none !important; }
}
