:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #18212b;
  --muted: #687481;
  --line: #dce2e8;
  --accent: #137a5b;
  --accent-dark: #0d6248;
  --danger: #b42318;
  --warning: #9a6700;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; letter-spacing: 0; }
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.topbar { height: 64px; background: #18212b; color: white; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand div { display: grid; gap: 2px; }
.brand small { color: #aeb9c3; font-size: 11px; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; background: var(--accent); color: white; border-radius: 6px; font-weight: 750; }
.brand-mark.small { width: 34px; height: 34px; font-size: 12px; }

.layout { width: min(1480px, calc(100% - 40px)); margin: 24px auto 56px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.metrics article { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 17px 18px; display: grid; gap: 6px; min-height: 112px; }
.metrics span, .metrics small { color: var(--muted); }
.metrics strong { font-size: 28px; font-weight: 700; }

.tabs { display: flex; border-bottom: 1px solid var(--line); gap: 22px; }
.tab { border: 0; background: transparent; padding: 12px 2px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-color: var(--accent); font-weight: 650; }
.tab-panel { display: none; padding-top: 22px; }
.tab-panel.active { display: block; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
h1, h2, h3, p { margin-top: 0; }
h2 { font-size: 19px; margin-bottom: 4px; }
h3 { margin-bottom: 4px; }
.section-heading p, dialog p { color: var(--muted); margin-bottom: 0; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 650; background: #f9fafb; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
td strong { display: block; margin-bottom: 4px; }
td small { display: block; color: var(--muted); max-width: 360px; overflow-wrap: anywhere; }
.empty { color: var(--muted); text-align: center; padding: 32px; }
.status { display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 999px; background: #edf0f2; color: var(--muted); }
.status.ok { background: #e6f4ef; color: var(--accent-dark); }
.ok-text { color: var(--accent); }
.error-text { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 250px; }
.actions form { display: flex; gap: 4px; }
.actions button, .copy-field button, button.ghost, button:not(.primary):not(.tab):not(.icon) { border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 5px; padding: 7px 9px; }
.actions input[type="number"] { width: 58px; border: 1px solid var(--line); border-radius: 5px; padding: 6px; }
.actions .danger, button.danger { color: var(--danger); }
.primary { border: 1px solid var(--accent); color: white; background: var(--accent); border-radius: 5px; padding: 9px 14px; font-weight: 650; }
.primary:hover { background: var(--accent-dark); }
.ghost { background: transparent !important; color: #dfe6ec !important; border-color: #46515d !important; }
.copy-field { display: flex; min-width: 340px; }
.copy-field input { min-width: 0; flex: 1; border: 1px solid var(--line); border-right: 0; border-radius: 5px 0 0 5px; padding: 7px 8px; color: var(--muted); }
.copy-field button { border-radius: 0 5px 5px 0; }

.alert { border: 1px solid var(--line); background: white; border-left-width: 4px; border-radius: 5px; padding: 12px 14px; margin-bottom: 18px; }
.alert.success { border-left-color: var(--accent); }
.alert.error { border-left-color: var(--danger); }

dialog { width: min(680px, calc(100% - 28px)); border: 0; border-radius: 7px; padding: 0; box-shadow: 0 22px 70px rgba(20, 30, 40, .24); }
dialog::backdrop { background: rgba(18, 27, 35, .56); }
.dialog-form { padding: 22px; }
.dialog-form header, .dialog-form footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.dialog-form footer { justify-content: flex-end; margin-top: 20px; }
.dialog-form label, .stack label { display: grid; gap: 7px; margin-top: 16px; color: #3c4854; font-weight: 600; }
.dialog-form input:not([type="checkbox"]), .stack input { width: 100%; border: 1px solid #cbd4dc; border-radius: 5px; padding: 10px 11px; background: white; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
fieldset { border: 1px solid var(--line); margin-top: 18px; padding: 8px 14px 14px; border-radius: 5px; }
legend { padding: 0 5px; color: var(--muted); }
.check { display: flex !important; align-items: center; gap: 8px !important; font-weight: 500 !important; }
.check small { margin-left: auto; color: var(--muted); }
.icon { border: 0; background: transparent; font-size: 24px; color: var(--muted); width: 34px; height: 34px; }
.log-list { background: white; border: 1px solid var(--line); border-radius: 6px; }
.log-list div { display: grid; grid-template-columns: 150px 180px 1fr; gap: 14px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.log-list div:last-child { border-bottom: 0; }
.log-list time, .log-list span { color: var(--muted); }

.login-page { min-height: 100vh; background: #eef2f4; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 22px; }
.login-panel { width: min(420px, 100%); background: white; border: 1px solid var(--line); border-radius: 7px; padding: 30px; }
.login-panel h1 { margin: 20px 0 6px; font-size: 23px; }
.login-panel > p { color: var(--muted); }
.stack { display: grid; margin-top: 20px; }
.stack .primary { margin-top: 20px; }

@media (max-width: 900px) {
  .layout { width: min(100% - 24px, 1480px); margin-top: 14px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .section-heading { align-items: flex-start; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 14px; }
  .metrics { grid-template-columns: 1fr; }
  .section-heading { display: grid; }
  .section-heading .primary { width: 100%; }
  .log-list div { grid-template-columns: 1fr; gap: 3px; }
}
.subscription-dialog { width: min(680px, calc(100vw - 32px)); }
.subscription-detail { padding: 14px 0; border-top: 1px solid #e2e8f0; }
.subscription-detail h4 { margin: 0 0 8px; font-size: 14px; }
.qr-code { width: 148px; height: 148px; margin-top: 8px; padding: 6px; background: #fff; border: 1px solid #d7dee7; }
.qr-code img, .qr-code canvas { display: block; width: 100%; height: 100%; }
