:root {
  --bg: #f4f8fa;
  --surface: #ffffff;
  --surface-soft: #eef7f9;
  --ink: #112d3a;
  --muted: #6d8590;
  --line: #dce8ec;
  --primary: #0e7490;
  --primary-dark: #09566b;
  --primary-soft: #dff5fa;
  --danger: #c2414b;
  --danger-soft: #fff0f1;
  --success: #147d64;
  --success-soft: #e7f8f2;
  --warning: #996515;
  --warning-soft: #fff7df;
  --shadow: 0 14px 38px rgba(17, 45, 58, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 4%, rgba(14, 116, 144, .12), transparent 28rem),
    linear-gradient(180deg, #f8fcfd 0%, var(--bg) 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 6px; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .15em; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px; }
.login-card {
  width: min(440px, 100%);
  padding: 38px;
  border: 1px solid rgba(255, 255, 255, .8);
  border-radius: 28px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}
.login-card h1 { margin: 18px 0 8px; font-size: 29px; letter-spacing: -.03em; }
.login-card .stack-form { margin-top: 30px; }
.brand-mark {
  width: 58px; height: 58px; display: grid; place-items: center;
  border-radius: 20px 10px 20px 10px;
  color: white; background: linear-gradient(145deg, #0e7490, #13a5b7);
  box-shadow: 0 10px 22px rgba(14, 116, 144, .22);
  font-size: 28px; font-weight: 900;
}
.brand-mark.small { width: 44px; height: 44px; border-radius: 15px 8px 15px 8px; font-size: 21px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 24px 18px;
  display: flex; flex-direction: column; gap: 30px;
  color: #dff5fa; background: linear-gradient(180deg, #0b3342 0%, #0d4558 100%);
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.sidebar-brand strong { display: block; font-size: 16px; color: white; }
.sidebar-brand span { display: block; margin-top: 2px; color: #9cc8d4; font-size: 12px; }
.nav-list { display: grid; gap: 7px; }
.nav-item {
  padding: 12px 14px; border: 0; border-radius: 12px; text-align: left;
  color: #b9d8e0; background: transparent; font-weight: 650;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: white; }
.nav-item.active { color: #073744; background: #dff5fa; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .12); }
.sidebar-footer .muted { color: #9cc8d4; font-size: 12px; }
.text-button { border: 0; padding: 4px; background: transparent; font-size: 12px; }
.danger-text { color: #ffb9bf; }

.main-content { width: min(1360px, 100%); margin: 0 auto; padding: 38px 42px 64px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-header h1 { margin: 0; font-size: 31px; letter-spacing: -.035em; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card {
  padding: 22px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: 0 9px 26px rgba(17, 45, 58, .045);
}
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 10px; font-size: 31px; letter-spacing: -.04em; }
.stat-card.accent { background: linear-gradient(145deg, #0e7490, #12a0ad); color: white; border-color: transparent; }
.stat-card.accent span { color: #cceef3; }

.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 11px 30px rgba(17, 45, 58, .045); }
.panel-header { padding: 20px 22px 14px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.panel-header h2, .toolbar h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.panel-header p, .toolbar p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.detail-list { margin: 0; padding: 6px 22px 22px; display: grid; grid-template-columns: 128px 1fr; gap: 14px 18px; }
.detail-list dt { color: var(--muted); font-size: 13px; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 650; }
.detail-list.compact { padding: 6px 0 0; }
.activity-list { padding: 0 22px 22px; display: grid; gap: 12px; }
.activity-item { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.activity-item:last-child { padding-bottom: 0; border-bottom: 0; }
.activity-item strong { font-size: 13px; }
.activity-item span { color: var(--muted); font-size: 12px; }
.empty-state { padding: 34px 22px; color: var(--muted); text-align: center; font-size: 13px; }

.toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 17px; }
.toolbar-actions, .form-actions { display: flex; gap: 10px; align-items: center; }
.button {
  min-height: 40px; padding: 9px 16px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 700; font-size: 13px; transition: .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--primary); box-shadow: 0 8px 18px rgba(14, 116, 144, .18); }
.button.primary:hover { background: var(--primary-dark); }
.button.ghost { color: var(--primary); background: var(--surface); border-color: var(--line); }
.button.danger { color: var(--danger); background: var(--danger-soft); }
.button.small { min-height: 32px; padding: 6px 10px; font-size: 12px; border-radius: 9px; }
.button.wide { width: 100%; }

.table-panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1120px; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; white-space: nowrap; }
th { color: var(--muted); background: #f8fbfc; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfdfe; }
.actions-col { text-align: right; }
.row-actions { display: flex; gap: 7px; justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.badge.on { color: var(--success); background: var(--success-soft); }
.badge.off { color: var(--muted); background: #edf1f3; }
.badge.expired { color: var(--warning); background: var(--warning-soft); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.settings-panel, .client-panel { max-width: 840px; }
.settings-panel .stack-form { padding: 8px 22px 24px; max-width: 620px; }
.stack-form { display: grid; gap: 17px; }
label { display: grid; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; outline: 0;
  padding: 11px 13px; color: var(--ink); background: #fbfdfe;
}
input:focus, select:focus, textarea:focus { border-color: #56b6c8; box-shadow: 0 0 0 3px rgba(14, 116, 144, .09); }
textarea { min-height: 240px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.65; }
.checkbox-row { display: flex; align-items: center; gap: 9px; }
.checkbox-row input { width: 17px; height: 17px; }
.form-error { min-height: 18px; margin: 0; color: var(--danger); font-size: 12px; }
.client-panel { padding-bottom: 24px; }
.client-panel .detail-list, .client-panel .notice, .code-block { margin-left: 22px; margin-right: 22px; }
.code-block { margin-top: 6px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; border-radius: 12px; background: #0b3342; color: #dff5fa; overflow-x: auto; }
.method { color: #6ee7d8; font-size: 11px; font-weight: 900; }
.notice { padding: 13px 15px; color: var(--muted); background: var(--surface-soft); border-radius: 12px; font-size: 12px; line-height: 1.7; }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(5, 28, 38, .45); backdrop-filter: blur(4px); }
.modal { width: min(560px, 100%); max-height: calc(100vh - 48px); overflow: auto; border-radius: 20px; background: var(--surface); box-shadow: 0 28px 70px rgba(0, 0, 0, .2); }
.modal-header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .97); }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 22px; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 10px; color: var(--muted); background: #f2f6f7; font-size: 22px; line-height: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.reveal-box { padding: 14px; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 12px; background: #f7fafb; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; user-select: all; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 30; min-width: 220px; max-width: 420px; padding: 13px 16px; border-radius: 12px; color: white; background: #123d4c; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: #9e3540; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
  .main-content { padding: 30px 28px 54px; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 18px; gap: 18px; }
  .nav-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .nav-item { text-align: center; padding: 10px 5px; font-size: 12px; }
  .sidebar-footer { display: none; }
  .main-content { padding: 24px 16px 48px; }
  .page-header { align-items: flex-start; }
  .page-header h1 { font-size: 25px; }
  .stats-grid { gap: 10px; }
  .stat-card { padding: 17px; }
  .stat-card strong { font-size: 26px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-actions { justify-content: flex-end; }
  .detail-list { grid-template-columns: 95px 1fr; }
}
