:root {
  color-scheme: light;
  --ink: #17233c;
  --muted: #68738a;
  --line: #dfe4ec;
  --paper: #f5f7fa;
  --panel: #ffffff;
  --navy: #101b31;
  --navy-2: #172640;
  --teal: #177f77;
  --teal-soft: #e5f5f1;
  --amber: #9b6412;
  --amber-soft: #fff4dc;
  --danger: #a33a3a;
  --danger-soft: #fbecec;
  --shadow: 0 14px 34px rgba(24, 40, 67, .08);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.auth-gate { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px; background: radial-gradient(circle at 15% 5%, #263c5d 0, var(--navy) 38%, #0b1425 100%); }
.auth-card { width: min(100%, 470px); padding: 34px; border: 1px solid rgba(255,255,255,.12); border-radius: 16px; background: #fff; box-shadow: 0 28px 75px rgba(0,0,0,.28); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; }
.auth-brand .brand-mark { color: #13746c; border-color: #bcded9; background: var(--teal-soft); }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand small { margin-top: 3px; color: var(--muted); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.auth-card h1 { margin-bottom: 10px; font-size: 32px; }
.auth-copy { margin-bottom: 24px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.auth-form { display: grid; gap: 16px; }
.auth-form label { display: grid; gap: 7px; color: #39465c; font-size: 12px; font-weight: 700; }
.auth-form label small { color: var(--muted); font-size: 10px; font-weight: 400; }
.auth-form input { width: 100%; padding: 11px 12px; border: 1px solid #cbd3de; border-radius: 8px; color: var(--ink); background: #fff; outline: none; }
.auth-form input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(23,127,119,.12); }
.primary-button { margin-top: 4px; padding: 12px 16px; border: 0; border-radius: 8px; color: #fff; background: var(--teal); font-weight: 800; }
.primary-button:disabled { cursor: wait; opacity: .6; }
.setup-key { margin: 0 0 22px; padding: 14px; border: 1px solid #c8e3df; border-radius: 9px; background: var(--teal-soft); }
.setup-key span, .setup-key code { display: block; }
.setup-key span { margin-bottom: 7px; color: #356760; font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.setup-key code { overflow-wrap: anywhere; color: #0d5852; font-size: 16px; font-weight: 800; letter-spacing: .09em; }
.auth-error { margin: 18px 0 0; }
.local-note { margin: 25px 0 0; color: #818b9d; font-size: 10px; text-align: center; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 252px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 18px 20px; display: flex; flex-direction: column; color: #eef4ff; background: linear-gradient(165deg, var(--navy), #0d1729 72%); }
.brand { display: flex; align-items: center; gap: 12px; margin: 0 8px 36px; color: inherit; text-decoration: none; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.24); border-radius: 11px; color: #b4eee6; background: rgba(75, 190, 174, .1); font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.brand strong, .brand small, .sidebar-foot strong, .sidebar-foot small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .01em; }
.brand small { margin-top: 3px; color: #91a0ba; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
nav { display: grid; gap: 7px; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 13px; padding: 12px 14px; border: 0; border-radius: 9px; color: #aebbd0; background: transparent; text-align: left; transition: background .16s ease, color .16s ease; }
.nav-item span { width: 20px; color: #6f809d; font-size: 18px; text-align: center; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: var(--navy-2); box-shadow: inset 3px 0 #63cdbf; }
.nav-item.active span { color: #8be0d5; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 11px; padding: 16px 10px 2px; border-top: 1px solid rgba(255,255,255,.09); }
.sidebar-foot strong { font-size: 12px; }
.sidebar-foot small { margin-top: 2px; color: #8090aa; font-size: 11px; }
.environment-dot { width: 9px; height: 9px; border-radius: 50%; background: #e0ae56; box-shadow: 0 0 0 4px rgba(224,174,86,.12); }

main { min-width: 0; padding: 0 46px 48px; }
.topbar { height: 104px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.account-area { display: flex; align-items: center; gap: 10px; }
.eyebrow { margin: 0 0 5px; color: var(--teal); font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-size: 27px; font-weight: 600; }
h2 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(25px, 2.4vw, 34px); font-weight: 500; }
h3 { margin-bottom: 0; font-size: 17px; }
.tenant-chip { min-width: 220px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.72); text-align: right; }
.tenant-chip span, .tenant-chip small { display: block; }
.tenant-chip span { font-size: 13px; font-weight: 700; }
.tenant-chip small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.demo-warning { margin: 24px 0 38px; padding: 12px 16px; display: flex; gap: 13px; align-items: baseline; border: 1px solid #edd6a9; border-radius: 8px; color: #76521c; background: var(--amber-soft); font-size: 12px; }
.demo-warning strong { text-transform: uppercase; letter-spacing: .07em; }
.demo-warning span { color: #8d6d3b; }
.error-banner { margin: -20px 0 24px; padding: 13px 16px; border: 1px solid #eabcbc; border-radius: 8px; color: #812d2d; background: var(--danger-soft); font-size: 13px; }

.view { animation: reveal .18s ease-out; }
@keyframes reveal { from { opacity: .45; transform: translateY(4px); } }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.section-actions { display: flex; align-items: center; gap: 14px; }
.quiet { color: var(--muted); font-size: 12px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 15px; margin-bottom: 22px; }
.metric-card { min-height: 114px; padding: 22px; display: flex; align-items: center; gap: 16px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); box-shadow: 0 6px 18px rgba(28,45,72,.035); }
.metric-card strong, .metric-card span { display: block; }
.metric-card strong { font-family: Georgia, "Times New Roman", serif; font-size: 30px; font-weight: 500; line-height: 1; }
.metric-card div span { margin-top: 7px; color: var(--muted); font-size: 12px; }
.metric-icon { width: 38px; height: 38px; display: grid; flex: 0 0 auto; place-items: center; border-radius: 9px; font-weight: 800; }
.metric-icon.mint { color: #18746d; background: var(--teal-soft); }
.metric-icon.blue { color: #365f9d; background: #eaf0fb; }
.metric-icon.amber { color: var(--amber); background: var(--amber-soft); }
.metric-icon.slate { color: #596579; background: #eef1f5; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(260px, .75fr); gap: 18px; }
.panel, .table-panel { border: 1px solid var(--line); border-radius: 11px; background: var(--panel); box-shadow: var(--shadow); }
.panel { padding: 24px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.count-badge { padding: 5px 9px; border-radius: 999px; color: var(--amber); background: var(--amber-soft); font-size: 11px; font-weight: 700; }
.task-list { margin: 0; padding: 0; list-style: none; }
.task-list li { display: grid; grid-template-columns: 12px minmax(0,1fr) auto; align-items: center; gap: 13px; padding: 16px 2px; border-top: 1px solid #edf0f4; }
.task-list strong, .task-list div span { display: block; }
.task-list strong { font-size: 13px; }
.task-list div span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.task-state { width: 8px; height: 8px; border-radius: 50%; background: #8794a8; }
.task-state.urgent { background: #d39435; box-shadow: 0 0 0 4px #fff3df; }
.tag { padding: 5px 8px; border-radius: 6px; color: #5f6c80; background: #eef1f5; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.amber-tag { color: var(--amber); background: var(--amber-soft); }
.boundary-panel { position: relative; overflow: hidden; color: #eef4ff; background: linear-gradient(150deg, #192943, #122037); border-color: #223550; }
.boundary-panel::after { content: ""; position: absolute; right: -70px; bottom: -80px; width: 190px; height: 190px; border: 1px solid rgba(108,211,197,.18); border-radius: 50%; }
.boundary-panel .eyebrow { color: #87ddd2; }
.boundary-panel h3 { margin-bottom: 15px; font-family: Georgia, "Times New Roman", serif; font-size: 23px; font-weight: 500; }
.boundary-panel p:not(.eyebrow) { color: #aab8cc; font-size: 12px; line-height: 1.65; }
.boundary-panel a { position: relative; z-index: 1; color: #8be0d5; font-size: 12px; font-weight: 700; text-decoration: none; }

.table-panel { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 13px 18px; color: #778296; background: #f9fafc; font-size: 10px; letter-spacing: .08em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 17px 18px; border-top: 1px solid #edf0f4; vertical-align: middle; }
td strong, td small { display: block; }
td strong { font-size: 13px; }
td small { margin-top: 4px; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.good { color: #14736b; background: var(--teal-soft); }
.status.bad { color: var(--danger); background: var(--danger-soft); }
.status.warn { color: var(--amber); background: var(--amber-soft); }
.action-button { min-width: 82px; padding: 7px 10px; border: 1px solid #cad1dc; border-radius: 7px; color: #42506a; background: #fff; font-size: 11px; font-weight: 700; }
.action-button:hover { border-color: #96a3b7; background: #f7f9fb; }
.action-button.danger { color: var(--danger); border-color: #e8bebe; }
.action-button:disabled { cursor: wait; opacity: .55; }
.primary-button.compact { margin: 0; padding: 8px 12px; font-size: 11px; }
.inline-form { margin-bottom: 18px; padding: 18px; display: grid; grid-template-columns: 1fr .7fr 1.3fr auto; gap: 14px; align-items: end; }
.inline-form label { display: grid; gap: 6px; color: #596579; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.inline-form input { min-width: 0; padding: 9px 10px; border: 1px solid #cbd3de; border-radius: 7px; }
.inline-form-actions { display: flex; gap: 8px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 7px; min-width: 220px; }
.modal-backdrop { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(9,17,31,.68); }
.modal-card { width: min(100%, 480px); padding: 30px; border-radius: 14px; background: #fff; box-shadow: 0 28px 80px rgba(0,0,0,.3); }
.modal-card h2 { margin-bottom: 12px; }
.auth-form select { width: 100%; padding: 11px 12px; border: 1px solid #cbd3de; border-radius: 8px; color: var(--ink); background: #fff; }
.reader-status { padding: 12px 13px; border: 1px solid #dfe4ec; border-radius: 8px; color: var(--muted); background: #f7f9fb; font-size: 12px; line-height: 1.5; }
.reader-status.ready { color: #146b64; border-color: #b9ddd8; background: var(--teal-soft); }
.reader-status.error { color: #812d2d; border-color: #eabcbc; background: var(--danger-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; }
.empty-state { min-height: 230px; display: grid; place-content: center; gap: 7px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 21px; font-weight: 500; }
.toast { position: fixed; right: 28px; bottom: 28px; max-width: 360px; padding: 13px 16px; border-radius: 9px; color: #fff; background: #1a2a43; box-shadow: 0 16px 40px rgba(12,23,40,.22); font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .brand { justify-content: center; margin-inline: 0; }
  .brand > span:last-child, .nav-item:not(.active) + span, .nav-item { font-size: 0; }
  .nav-item { justify-content: center; padding-inline: 0; }
  .nav-item span { font-size: 18px; }
  .sidebar-foot span:not(.environment-dot) { display: none; }
  .sidebar-foot { justify-content: center; }
  main { padding-inline: 28px; }
  .metrics { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
}

@media (max-width: 720px) {
  .auth-card { padding: 25px 20px; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 13px 16px; flex-direction: row; align-items: center; gap: 12px; }
  .brand { margin: 0 auto 0 0; }
  .brand-mark { width: 36px; height: 36px; }
  nav { display: flex; }
  .nav-item { width: 40px; min-height: 40px; }
  .sidebar-foot { display: none; }
  main { padding: 0 18px 32px; }
  .topbar { height: auto; padding: 20px 0; }
  .tenant-chip { min-width: 0; }
  .account-area { align-items: stretch; flex-direction: column; }
  .demo-warning { margin: 16px 0 28px; display: block; }
  .demo-warning span { display: block; margin-top: 5px; }
  .section-heading { align-items: start; flex-direction: column; gap: 8px; }
  .section-actions { width: 100%; align-items: start; flex-direction: column; }
  .inline-form { grid-template-columns: 1fr; }
  .row-actions { min-width: 190px; }
  .metrics, .overview-grid { grid-template-columns: 1fr; }
}
