:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-muted: #f0f2f5;
  --surface-strong: #111318;
  --surface-strong-hover: #252832;
  --border: #dde1e7;
  --text: #15171c;
  --muted: #68707d;
  --soft: #98a1ae;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --teal: #0f9f7a;
  --warn: #b7791f;
  --danger: #d13f4a;
  --ok-bg: #e4f7ef;
  --ok-text: #0d6b4f;
  --warn-bg: #fff2c7;
  --warn-text: #805600;
  --critical-bg: #ffe3dc;
  --critical-text: #9b271d;
  --expired-bg: #521c21;
  --expired-text: #ffffff;
  --muted-bg: #e9edf2;
  --panel-bg: rgba(255, 255, 255, 0.9);
  --sidebar-bg: rgba(255, 255, 255, 0.86);
  --input-bg: #fbfcfd;
  --hover-bg: #fafbfc;
  --hover-border: #c2c8d2;
  --table-head-text: #4d5561;
  --row-alert-bg: #fff5f3;
  --type-bg: #eceff4;
  --type-text: #3f4650;
  --error-bg: #ffe2e7;
  --error-text: #9d1e32;
  --field-error: #a3221b;
  --notice-border: #9bd1bd;
  --notice-bg: #e9f8f0;
  --notice-text: #115c39;
  --notice-error-border: #e7b3ad;
  --notice-error-bg: #fff1ef;
  --notice-error-text: #8c2119;
  --pre-bg: #17191f;
  --pre-text: #f4f7fb;
  --danger-zone-bg: #fff8f7;
  --focus-ring: rgba(37, 99, 235, 0.13);
  --metric-hero-muted: rgba(255, 255, 255, 0.7);
  --body-gradient-a: rgba(255, 255, 255, 0.78);
  --body-gradient-b: rgba(247, 248, 250, 0.98);
  --grid-line: rgba(17, 19, 24, 0.025);
  --shadow: 0 18px 48px rgba(17, 19, 24, 0.08);
  --radius: 8px;
  --sidebar-width: 264px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0f14;
    --surface: #151820;
    --surface-muted: #20242e;
    --surface-strong: #f4f7fb;
    --surface-strong-hover: #dce3ee;
    --border: #2a303b;
    --text: #eef2f7;
    --muted: #9ba5b4;
    --soft: #6f7b8c;
    --accent: #6ea8ff;
    --accent-dark: #8dbbff;
    --ok-bg: #123a30;
    --ok-text: #86f0ca;
    --warn-bg: #453513;
    --warn-text: #ffd982;
    --critical-bg: #4a231e;
    --critical-text: #ffb0a4;
    --expired-bg: #711f2a;
    --muted-bg: #252b35;
    --panel-bg: rgba(21, 24, 32, 0.92);
    --sidebar-bg: rgba(17, 20, 27, 0.9);
    --input-bg: #10131a;
    --hover-bg: #1e2330;
    --hover-border: #394354;
    --table-head-text: #b8c1cf;
    --row-alert-bg: rgba(113, 31, 42, 0.24);
    --type-bg: #27303d;
    --type-text: #d6deea;
    --error-bg: #54212b;
    --error-text: #ffb1bf;
    --field-error: #ff9b9b;
    --notice-border: #235e4a;
    --notice-bg: #102b24;
    --notice-text: #a7f3d0;
    --notice-error-border: #704047;
    --notice-error-bg: #31181d;
    --notice-error-text: #ffc0c7;
    --pre-bg: #090b0f;
    --pre-text: #e7eef8;
    --danger-zone-bg: #211419;
    --focus-ring: rgba(110, 168, 255, 0.2);
    --metric-hero-muted: rgba(17, 19, 24, 0.68);
    --body-gradient-a: rgba(13, 15, 20, 0.92);
    --body-gradient-b: rgba(10, 12, 17, 0.98);
    --grid-line: rgba(255, 255, 255, 0.035);
    --shadow: 0 20px 56px rgba(0, 0, 0, 0.38);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0f14;
  --surface: #151820;
  --surface-muted: #20242e;
  --surface-strong: #f4f7fb;
  --surface-strong-hover: #dce3ee;
  --border: #2a303b;
  --text: #eef2f7;
  --muted: #9ba5b4;
  --soft: #6f7b8c;
  --accent: #6ea8ff;
  --accent-dark: #8dbbff;
  --ok-bg: #123a30;
  --ok-text: #86f0ca;
  --warn-bg: #453513;
  --warn-text: #ffd982;
  --critical-bg: #4a231e;
  --critical-text: #ffb0a4;
  --expired-bg: #711f2a;
  --muted-bg: #252b35;
  --panel-bg: rgba(21, 24, 32, 0.92);
  --sidebar-bg: rgba(17, 20, 27, 0.9);
  --input-bg: #10131a;
  --hover-bg: #1e2330;
  --hover-border: #394354;
  --table-head-text: #b8c1cf;
  --row-alert-bg: rgba(113, 31, 42, 0.24);
  --type-bg: #27303d;
  --type-text: #d6deea;
  --error-bg: #54212b;
  --error-text: #ffb1bf;
  --field-error: #ff9b9b;
  --notice-border: #235e4a;
  --notice-bg: #102b24;
  --notice-text: #a7f3d0;
  --notice-error-border: #704047;
  --notice-error-bg: #31181d;
  --notice-error-text: #ffc0c7;
  --pre-bg: #090b0f;
  --pre-text: #e7eef8;
  --danger-zone-bg: #211419;
  --focus-ring: rgba(110, 168, 255, 0.2);
  --metric-hero-muted: rgba(17, 19, 24, 0.68);
  --body-gradient-a: rgba(13, 15, 20, 0.92);
  --body-gradient-b: rgba(10, 12, 17, 0.98);
  --grid-line: rgba(255, 255, 255, 0.035);
  --shadow: 0 20px 56px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, var(--body-gradient-a), var(--body-gradient-b)),
    repeating-linear-gradient(90deg, var(--grid-line) 0 1px, transparent 1px 82px);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: inherit;
}

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

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 26px;
  padding: 22px 16px;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  backdrop-filter: blur(18px);
}

.main-shell {
  min-width: 0;
}

.topbar,
.auth-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar {
  min-height: 76px;
  padding: 18px clamp(18px, 3vw, 34px) 0;
}

.auth-topbar {
  padding: 22px clamp(18px, 4vw, 44px);
}

.brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--bg);
  font-size: 0.78rem;
  letter-spacing: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  line-height: 1.05;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

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

.nav-item {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 750;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.nav-item.is-active {
  border-color: var(--surface-strong);
  background: var(--surface-strong);
  color: var(--bg);
}

.sidebar-actions {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.top-theme-toggle {
  display: none;
}

.theme-toggle {
  gap: 0.5rem;
}

[data-theme-toggle-icon] {
  font-size: 1rem;
  line-height: 1;
}

.logout-form,
.table-actions form,
.section-title form,
.danger-actions form {
  margin: 0;
}

.page {
  width: min(1460px, calc(100% - 48px));
  margin: 0 auto;
  padding: 22px 0 44px;
}

.auth-body .page {
  width: min(520px, calc(100% - 32px));
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 16px;
}

.dashboard-heading h1,
.page-heading h1 {
  margin: 0;
  font-size: clamp(2rem, 4.7vw, 4rem);
  font-weight: 780;
  line-height: 0.95;
  letter-spacing: 0;
}

.page-heading:not(.dashboard-heading) h1 {
  font-size: clamp(1.8rem, 3vw, 2.65rem);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  padding: 0.55rem 0.88rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 780;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.button:hover {
  border-color: var(--hover-border);
  background: var(--hover-bg);
  transform: translateY(-1px);
}

.button-primary {
  border-color: var(--surface-strong);
  background: var(--surface-strong);
  color: var(--bg);
}

.button-primary:hover {
  border-color: var(--surface-strong-hover);
  background: var(--surface-strong-hover);
}

.button-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #ffffff;
}

.button-small {
  min-height: 2.05rem;
  padding: 0.35rem 0.62rem;
  font-size: 0.86rem;
}

.heading-actions,
.form-actions,
.filter-actions,
.table-actions,
.danger-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

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

.metric,
.filterbar,
.form-panel,
.detail-section,
.danger-zone,
.table-surface,
.auth-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.metric {
  display: grid;
  min-height: 118px;
  align-content: space-between;
  gap: 12px;
  padding: 17px;
}

.metric span,
label span,
.definition-list dt {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 780;
}

.metric strong {
  font-size: clamp(1.55rem, 3vw, 2.6rem);
  line-height: 0.95;
}

.metric em {
  color: var(--muted);
  font-style: normal;
  font-weight: 700;
}

.metric-hero {
  background: var(--surface-strong);
  color: var(--bg);
}

.metric-hero span {
  color: var(--metric-hero-muted);
}

.filterbar {
  display: grid;
  grid-template-columns: minmax(220px, 1.8fr) minmax(170px, 1fr) minmax(170px, 1fr) auto;
  gap: 0.9rem;
  align-items: end;
  padding: 1rem;
  margin-bottom: 1rem;
}

.ssl-filterbar {
  grid-template-columns: minmax(240px, 1fr) minmax(170px, 0.4fr) auto;
}

label {
  display: grid;
  gap: 0.36rem;
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.58rem 0.68rem;
  background: var(--input-bg);
  color: var(--text);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid var(--focus-ring);
}

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

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

.ssl-table {
  min-width: 1120px;
}

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

th {
  background: var(--surface-muted);
  color: var(--table-head-text);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.row-expired td {
  background: var(--row-alert-bg);
}

.table-link {
  display: inline-block;
  overflow-wrap: anywhere;
  font-weight: 850;
  text-decoration: none;
}

.table-link:hover {
  text-decoration: underline;
}

.subtext,
.stale-note {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.type-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  border-radius: 999px;
  padding: 0.18rem 0.62rem;
  font-size: 0.8rem;
  font-weight: 850;
}

.type-pill {
  background: var(--type-bg);
  color: var(--type-text);
}

.status-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.status-warning {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.status-critical {
  background: var(--critical-bg);
  color: var(--critical-text);
}

.status-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.status-expired {
  background: var(--expired-bg);
  color: var(--expired-text);
}

.status-muted,
.status-inactive {
  background: var(--muted-bg);
  color: var(--table-head-text);
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 0.45rem;
  align-items: center;
}

.copy-row input {
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
}

.copy-row-large {
  grid-template-columns: minmax(0, 1fr) auto;
}

.empty-state {
  display: grid;
  min-height: 230px;
  place-items: center;
  align-content: center;
  gap: 0.55rem;
  padding: 2rem;
  color: var(--muted);
  text-align: center;
}

.empty-state h1,
.empty-state h2,
.empty-state p {
  margin: 0;
}

.empty-state h1,
.empty-state h2 {
  color: var(--text);
}

.empty-actions {
  justify-content: center;
  margin-top: 0.65rem;
}

.form-panel,
.auth-panel {
  padding: 1.12rem;
}

.auth-panel {
  margin: 2rem auto;
}

.auth-panel h1 {
  margin: 0 0 1rem;
}

.auth-panel form {
  display: grid;
  gap: 0.9rem;
}

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

.full-width {
  grid-column: 1 / -1;
}

.check-row {
  align-self: end;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.55rem;
}

.check-row input {
  width: 1.1rem;
  min-height: auto;
}

.ssl-cert-row.is-disabled {
  opacity: 0.55;
}

.notification-levels {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  min-width: 0;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.notification-levels legend {
  padding: 0 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 780;
}

.notification-levels .check-row {
  align-self: center;
}

.field-error {
  color: var(--field-error);
  font-size: 0.82rem;
}

.form-actions {
  justify-content: flex-end;
  margin-top: 1rem;
}

.notice {
  margin-bottom: 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--notice-border);
  border-radius: var(--radius);
  background: var(--notice-bg);
  color: var(--notice-text);
  font-weight: 780;
}

.notice-error {
  border-color: var(--notice-error-border);
  background: var(--notice-error-bg);
  color: var(--notice-error-text);
}

.upload-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 0.9rem;
  align-items: end;
}

.text-template-form {
  display: grid;
  gap: 0.9rem;
}

.text-template-form textarea,
pre,
code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.text-template-form textarea {
  font-size: 0.92rem;
  line-height: 1.45;
}

.script-table {
  min-width: 720px;
}

.dashboard-regions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.dashboard-region {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.dashboard-region .section-title {
  margin: 0;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.compact-table {
  min-width: 680px;
}

.compact-table th,
.compact-table td {
  padding: 0.78rem 0.72rem;
}

.compact-empty {
  min-height: 270px;
}

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

.detail-section,
.danger-zone {
  padding: 1rem;
  margin-top: 1rem;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.section-title h2,
.danger-zone h2 {
  margin: 0;
  font-size: 1.08rem;
}

pre {
  overflow-x: auto;
  margin: 0.7rem 0 0;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--pre-bg);
  color: var(--pre-text);
}

code {
  font-size: 0.9rem;
}

.definition-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem 1rem;
  margin: 0;
}

.definition-list div {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border);
}

.definition-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.danger-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-color: var(--notice-error-border);
  background: var(--danger-zone-bg);
}

.ssl-workspace {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.ssl-list {
  min-width: 0;
}

.ssl-form-grid {
  grid-template-columns: 1fr;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 12px;
  align-items: start;
}

.settings-actions {
  margin-top: 1rem;
}

.settings-summary {
  margin-top: 0;
}

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

.port-check-grid h3 {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
}

.port-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.port-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2rem;
  padding: 0.34rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 760;
}

.port-chip strong {
  color: var(--text);
}

.port-chip.is-ok {
  border-color: var(--ok-border);
  background: var(--ok-bg);
  color: var(--ok);
}

.port-chip.is-error {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--error);
}

@media (max-width: 1440px) {
  .ssl-workspace {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 12px;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }

  .sidebar-actions {
    display: none;
  }

  .top-theme-toggle {
    display: inline-flex;
  }

  .topbar {
    padding-top: 14px;
  }

  .metric-grid,
  .filterbar,
  .detail-grid,
  .settings-grid,
  .port-check-grid,
  .dashboard-regions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .page {
    width: min(100% - 1rem, 1460px);
    padding-top: 1rem;
  }

  .topbar,
  .page-heading,
  .danger-zone,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .filterbar,
  .form-grid,
  .ssl-form-grid,
  .dashboard-regions,
  .settings-grid,
  .port-check-grid,
  .detail-grid,
  .definition-list,
  .upload-form,
  .copy-row,
  .copy-row-large {
    grid-template-columns: 1fr;
  }

  .heading-actions,
  .form-actions,
  .filter-actions,
  .table-actions,
  .settings-actions {
    align-items: stretch;
  }

  .button,
  .nav-item {
    width: 100%;
  }

  .sidebar {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    grid-auto-flow: row;
  }
}
