:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-tint: #eef8f7;
  --ink: #172033;
  --muted: #64748b;
  --subtle: #94a3b8;
  --line: #dce5eb;
  --line-strong: #c6d3dc;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --blue: #2563eb;
  --amber: #b45309;
  --red: #dc2626;
  --green: #059669;
  --violet: #6d28d9;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 22px rgba(15, 23, 42, .08);
  --radius: 8px;
  --radius-sm: 6px;
}

* {
  box-sizing: border-box;
}

html,
body,
.app-root {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: .58;
}

.app-root {
  min-height: 100vh;
}

.login-page {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
}

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 42px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.login-context {
  display: grid;
  align-content: center;
  gap: 20px;
  padding: 42px;
  background: linear-gradient(135deg, #eef8f7 0%, #f8fafc 46%, #eef2ff 100%);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
}

.brand-copy strong {
  display: block;
  font-size: 16px;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

.login-panel h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.login-panel p {
  margin: 0;
  color: var(--muted);
}

.login-form,
.stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.field-label {
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
.compact-input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.compact-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .14);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.notice {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #f8fafc;
  color: var(--muted);
}

.notice strong {
  color: var(--ink);
}

.shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #0f172a;
  color: #dbeafe;
}

.sidebar .brand-lockup {
  min-height: 42px;
}

.sidebar .brand-mark {
  background: #14b8a6;
  color: #06231f;
}

.sidebar .brand-copy strong {
  color: #fff;
}

.sidebar .brand-copy span {
  color: #9fb2cb;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  display: grid;
  min-height: 42px;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 10px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav button:hover {
  background: rgba(148, 163, 184, .12);
  color: #fff;
}

.nav button.active {
  border-color: rgba(20, 184, 166, .46);
  background: rgba(20, 184, 166, .16);
  color: #fff;
}

.nav-icon {
  width: 22px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  color: #9fb2cb;
  font-size: 12px;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.title-block h1 {
  margin: 0 0 5px;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.title-block p {
  margin: 0;
  color: var(--muted);
}

.top-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.api-form {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--brand);
  color: var(--brand-strong);
}

.btn.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.btn.primary:hover {
  background: var(--brand-strong);
  color: #fff;
}

.btn.danger {
  border-color: #fecaca;
  color: #b91c1c;
}

.btn.warning {
  border-color: #fde68a;
  color: #92400e;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.content-grid {
  display: grid;
  gap: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(330px, .8fr);
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.panel-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-body {
  padding: 14px;
}

.stat {
  display: grid;
  gap: 7px;
  min-height: 108px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  background: #fff;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  font-size: 26px;
  line-height: 1;
}

.stat em {
  color: var(--subtle);
  font-size: 12px;
  font-style: normal;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

th {
  color: #475569;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: #f8fafc;
}

tbody tr:hover {
  background: #fbfdff;
}

.row-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 750;
  text-align: left;
}

.row-button:hover {
  text-decoration: underline;
}

.filters {
  display: grid;
  grid-template-columns: minmax(190px, 1.3fr) repeat(2, minmax(130px, .7fr)) auto;
  gap: 10px;
  align-items: end;
}

.grant-filters {
  grid-template-columns: minmax(170px, .9fr) minmax(220px, 1.1fr) minmax(160px, .9fr) auto;
}

.pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 9px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.pill.green {
  border-color: #bbf7d0;
  background: #ecfdf5;
  color: #047857;
}

.pill.amber {
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.pill.red {
  border-color: #fecaca;
  background: #fff1f2;
  color: #b91c1c;
}

.pill.blue {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.pill.violet {
  border-color: #ddd6fe;
  background: #f5f3ff;
  color: #6d28d9;
}

.pill.gray {
  border-color: #e2e8f0;
  background: #f8fafc;
  color: #64748b;
}

.meta-list {
  display: grid;
  gap: 9px;
}

.meta-item {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.meta-item:last-child {
  border-bottom: 0;
}

.meta-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.company-list,
.grant-list {
  display: grid;
  gap: 10px;
}

.company-row,
.grant-row,
.route-row {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px;
  background: #fff;
}

.company-row strong,
.grant-row strong {
  font-size: 14px;
}

.grant-row-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.scope-chips,
.inline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.inline-meta {
  color: var(--muted);
  font-size: 12px;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.check-item {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 9px;
  background: #fff;
}

.check-item input {
  width: 16px;
  height: 16px;
}

.empty-state,
.error-state {
  display: grid;
  gap: 7px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 18px;
  background: #fbfdff;
  color: var(--muted);
}

.error-state {
  border-color: #fecaca;
  background: #fff7f7;
  color: #991b1b;
}

.toast-stack {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100vw - 36px));
}

.toast {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.toast.error {
  border-color: #fecaca;
  color: #991b1b;
}

.toast.success {
  border-color: #bbf7d0;
  color: #047857;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(15, 23, 42, .44);
}

.modal {
  width: min(540px, 100%);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
}

.modal header,
.modal footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal h2 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1120px) {
  .topbar,
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-items: stretch;
  }
}

@media (max-width: 860px) {
  .login-page,
  .shell {
    grid-template-columns: 1fr;
  }

  .login-context {
    display: none;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .grid-3,
  .filters,
  .grant-filters {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .main,
  .login-panel {
    padding: 16px;
  }

  .api-form,
  .check-grid {
    grid-template-columns: 1fr;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .meta-item {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
