:root {
  color-scheme: dark;
  --bg: #101315;
  --sidebar: #131719;
  --surface: #181d20;
  --surface-raised: #1d2427;
  --surface-hover: #222a2e;
  --line: #2b3438;
  --line-soft: #222a2d;
  --text: #edf1ed;
  --muted: #929d9d;
  --muted-2: #697578;
  --blue: #4b8ef7;
  --green: #49c583;
  --green-soft: #173d2c;
  --yellow: #e4b34d;
  --yellow-soft: #493715;
  --red: #ea6c69;
  --red-soft: #4b2527;
}

* { box-sizing: border-box; }

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

button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 52% 45%, #1b282b 0, var(--bg) 48%);
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px #00000045;
}

.brand-row { display: flex; gap: 13px; align-items: center; }
.brand-row h1, .brand-row p { margin: 0; }
.brand-row h1 { font-size: 20px; font-weight: 700; }
.brand-row p, .brand-row span, .muted { color: var(--muted); }

.brand-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 8px;
  object-fit: cover;
}

.compact .brand-logo { width: 34px; height: 34px; }
.compact { padding: 24px 22px 25px; }
.compact strong { display: block; font-size: 16px; line-height: 1.1; }
.compact span { display: block; margin-top: 3px; font-size: 13px; }

label { display: grid; gap: 8px; margin-top: 26px; color: var(--muted); font-size: 13px; }
input {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0e1214;
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #4b8ef724; }

button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease;
}
button:hover { background: #619bf8; }
.login-panel button { width: 100%; margin-top: 16px; }

.app { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line-soft);
  background: var(--sidebar);
}
nav { display: grid; gap: 2px; padding: 0 12px; }
.nav {
  position: relative;
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-size: 14px;
  font-weight: 500;
}
.nav-index { width: 20px; color: var(--muted-2); font-size: 10px; font-variant-numeric: tabular-nums; }
.nav.active, .nav:hover { background: var(--surface-raised); color: var(--text); }
.nav.active { box-shadow: inset 2px 0 var(--blue); }
.nav.active .nav-index { color: var(--blue); }

.workspace { min-width: 0; }
.topbar {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 21px clamp(22px, 4vw, 56px);
  border-bottom: 1px solid var(--line-soft);
  background: #111517db;
  backdrop-filter: blur(12px);
}
.topbar h2, .topbar p { margin: 0; }
.topbar h2 { font-size: 22px; line-height: 1.2; }
.topbar p { margin-top: 4px; color: var(--muted); font-size: 13px; }
.top-actions { width: min(420px, 46%); display: flex; align-items: center; gap: 8px; }
.search-field {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted-2);
}
.search-field:focus-within { border-color: #546b76; }
.search-field input { height: 38px; padding: 0; border: 0; background: transparent; box-shadow: none; }
.search-field input:focus { box-shadow: none; }
.icon-button {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.icon-button:hover { background: var(--surface-hover); color: var(--text); }

.content { max-width: 1540px; padding: 36px clamp(22px, 4vw, 56px) 52px; }
.eyebrow { margin: 0 0 6px; color: var(--muted-2); font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }

.overview-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 10px; }
.primary-metrics { min-width: min(100%, 790px); }
.metric { min-height: 116px; padding: 16px 17px; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--surface); }
.metric span { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; }
.metric strong { display: block; margin-top: 12px; color: var(--text); font-size: 30px; font-weight: 650; line-height: 1; font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 6px; color: var(--muted); }
.metric.ok strong { color: var(--green); }
.metric.warn strong { color: var(--yellow); }
.metric.bad strong { color: var(--red); }
.system-state { min-width: 210px; display: flex; align-items: center; gap: 10px; padding: 14px 0; }
.system-state strong, .system-state small { display: block; }
.system-state small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px #49c58318; }
.unhealthy .status-dot { background: var(--red); box-shadow: 0 0 0 5px #ea6c6918; }

.stats-strip { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 10px; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--surface); }
.stats-strip .metric { min-height: 86px; border: 0; border-right: 1px solid var(--line-soft); border-radius: 0; background: transparent; }
.stats-strip .metric:last-child { border-right: 0; }
.stats-strip .metric strong { margin-top: 9px; font-size: 22px; }

.split { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(300px, .92fr); gap: 36px; margin-top: 38px; }
.section-block, .split > div { min-width: 0; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading .muted { margin: 0; font-size: 12px; }
.section-title { margin: 0; font-size: 17px; line-height: 1.25; }
.section-title span { color: var(--muted); font-size: 14px; font-weight: 500; }
.count-badge { min-width: 26px; height: 26px; display: grid; place-items: center; padding: 0 7px; border-radius: 999px; background: var(--surface-raised); color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.count-badge.warn { color: var(--yellow); background: var(--yellow-soft); }
.count-badge.bad { color: var(--red); background: var(--red-soft); }

.list { display: grid; gap: 7px; }
.issue, .activity, .request-item, .empty-state { border: 1px solid var(--line-soft); border-radius: 7px; background: var(--surface); }
.issue { display: flex; align-items: flex-start; gap: 10px; padding: 13px 14px; color: var(--text); font-size: 13px; line-height: 1.45; }
.issue-marker { width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.issue.warn .issue-marker { background: var(--yellow); }
.issue.bad .issue-marker { background: var(--red); }
.activity { padding: 12px 14px; }
.activity strong { font-size: 13px; font-weight: 650; }
.activity p, .request-item p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.empty-state { padding: 18px; color: var(--muted); font-size: 13px; }

.table-heading { margin-bottom: 16px; }
.table-wrap { overflow: auto; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; font-size: 13px; }
th { color: var(--muted-2); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
td strong { font-weight: 650; }
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: #1d2528; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; min-height: 21px; padding: 0 7px; border-radius: 999px; background: #273033; color: var(--text); font-size: 11px; white-space: nowrap; }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.warn { background: var(--yellow-soft); color: var(--yellow); }
.badge.bad { background: var(--red-soft); color: var(--red); }
.table-action { min-height: 29px; padding: 0 9px; background: var(--surface-raised); border-color: var(--line); color: var(--text); font-size: 11px; }
.table-action:hover { background: var(--surface-hover); }
.danger-outline { margin-top: 11px; color: var(--red); }
.primary-action { margin-top: 11px; background: var(--blue); border-color: var(--blue); color: white; }
.primary-action:hover { background: #619bf8; }
.request-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.request-actions .danger-outline { margin-top: 11px; }

.request-item { padding: 14px 15px; }
.request-item strong { font-size: 13px; }
.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 9px; }
.link-item { min-height: 92px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--surface); }
.link-item strong { display: block; font-size: 13px; line-height: 1.35; }
.link-item p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.create-action { margin: 0; }
.composer { max-width: 720px; }
.composer-form { display: grid; gap: 14px; padding: 20px; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--surface); }
.composer-form .form-label { margin: 0; }
.composer-form textarea { min-height: 150px; }
.composer-note { margin: -4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.loading { display: flex; align-items: center; gap: 10px; min-height: 100px; color: var(--muted); font-size: 13px; }
.loading span { width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-root { position: fixed; z-index: 20; inset: 0; display: none; }
.modal-root.open { display: grid; place-items: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: #050708b8; backdrop-filter: blur(3px); }
.modal { position: relative; width: min(560px, 100%); max-height: min(760px, calc(100vh - 36px)); overflow: auto; padding: 23px; border: 1px solid var(--line); border-radius: 8px; background: #171d20; box-shadow: 0 26px 90px #00000075; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.modal-header h3 { margin: 0; font-size: 20px; line-height: 1.25; }
.modal-close { width: 32px; min-width: 32px; min-height: 32px; height: 32px; padding: 0; border-color: var(--line); background: transparent; color: var(--muted); font-size: 23px; line-height: 1; }
.modal-close:hover { background: var(--surface-raised); color: var(--text); }
.modal-copy { margin: 18px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin: 22px 0 0; border: 1px solid var(--line-soft); border-radius: 7px; overflow: hidden; }
.detail-grid div { min-height: 67px; padding: 12px; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.detail-grid div:nth-child(2n) { border-right: 0; }
.detail-grid div:nth-last-child(-n + 2) { border-bottom: 0; }
.detail-grid dt { color: var(--muted-2); font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.detail-grid dd { margin: 7px 0 0; color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums; }
.mini-list { display: grid; gap: 7px; }
.mini-subscription { width: 100%; min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 11px; border-color: var(--line-soft); background: var(--surface); color: var(--text); text-align: left; }
.mini-subscription:hover { background: var(--surface-hover); }
.mini-subscription strong, .mini-subscription small { display: block; }
.mini-subscription strong { font-size: 12px; }
.mini-subscription small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.modal-section { margin-top: 20px; padding-top: 19px; border-top: 1px solid var(--line-soft); }
.modal-section.last { margin-bottom: 0; }
.modal-label { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.preset-actions, .modal-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.preset-actions button { min-height: 34px; padding: 0 11px; background: var(--surface-raised); border-color: var(--line); color: var(--text); font-size: 12px; }
.preset-actions button:hover { background: var(--surface-hover); }
.form-label { gap: 8px; margin: 0; color: var(--muted); font-size: 12px; }
.form-label input, .form-label textarea { margin-top: 0; }
.form-label select { margin-top: 0; }
select { width: 100%; min-width: 0; height: 42px; padding: 0 35px 0 12px; border: 1px solid var(--line); border-radius: 6px; outline: none; background: #0e1214; color: var(--text); }
select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #4b8ef724; }
.grant-source-fields { display: grid; gap: 12px; margin-top: 12px; }
.modal-section form, .modal-section .secondary { margin-top: 10px; }
.form-label + .secondary { margin-top: 10px; }
textarea { width: 100%; min-height: 112px; padding: 10px 12px; resize: vertical; border: 1px solid var(--line); border-radius: 6px; outline: none; background: #0e1214; color: var(--text); }
textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #4b8ef724; }
.modal-actions { margin-top: 20px; justify-content: flex-end; }
.modal-actions.spread { justify-content: space-between; }
button.secondary { background: var(--surface-raised); border-color: var(--line); color: var(--text); }
button.secondary:hover { background: var(--surface-hover); }
button.primary { background: var(--blue); }
button.primary:hover { background: #619bf8; }
button.danger { background: var(--red); }
button.danger:hover { background: #ef7f7b; }
button.lifetime { background: var(--green-soft); border-color: #2c6c4d; color: var(--green); }
button.lifetime:hover { background: #205238; }
button:disabled, .disabled { opacity: .48; cursor: not-allowed; }
.notice { margin-top: 17px; padding: 11px 12px; border: 1px solid #745d2a; border-radius: 6px; background: var(--yellow-soft); color: var(--yellow); font-size: 12px; line-height: 1.45; }
.toast-root { position: fixed; z-index: 30; right: 22px; bottom: 22px; width: min(420px, calc(100vw - 44px)); }
.toast { padding: 13px 15px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-raised); box-shadow: 0 14px 40px #0000005c; color: var(--text); font-size: 13px; line-height: 1.4; }
.toast.ok { border-color: #2d6b4d; }
.toast.warn { border-color: #745d2a; color: var(--yellow); }
.toast.bad { border-color: #7a3838; color: var(--red); }

@media (max-width: 1050px) {
  .overview-hero { align-items: stretch; flex-direction: column; }
  .system-state { padding: 0; }
  .primary-metrics, .cards { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .compact { padding: 16px 18px; }
  nav { grid-template-columns: repeat(3, 1fr); padding: 0 10px 10px; }
  .nav { min-height: 38px; padding: 0 8px; gap: 7px; font-size: 12px; }
  .topbar, .split { display: grid; grid-template-columns: 1fr; }
  .topbar { padding: 18px 20px; }
  .top-actions { width: 100%; }
  .content { padding: 28px 20px 42px; }
  .split { gap: 30px; margin-top: 30px; }
  .modal { padding: 19px; }
}

@media (max-width: 560px) {
  .primary-metrics, .cards, .stats-strip { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 98px; }
  .metric strong { font-size: 25px; }
  .stats-strip .metric { border-bottom: 1px solid var(--line-soft); }
  .stats-strip .metric:nth-child(2) { border-right: 0; }
  .stats-strip .metric:nth-child(n + 3) { border-bottom: 0; }
  nav { grid-template-columns: repeat(2, 1fr); }
  .nav-index { display: none; }
  .topbar h2 { font-size: 20px; }
  .topbar p { max-width: 35ch; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid div, .detail-grid div:nth-child(2n) { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .detail-grid div:last-child { border-bottom: 0; }
  .modal-actions.spread { align-items: stretch; flex-direction: column; }
}
