:root {
  color-scheme: light;
  --navy-950: #07172d;
  --navy-900: #0a2141;
  --navy-800: #10345f;
  --blue-700: #1258bc;
  --blue-600: #1872e5;
  --blue-100: #eaf3ff;
  --gold-500: #d9a329;
  --gold-100: #fff7df;
  --red-600: #d7373f;
  --red-100: #fff0f1;
  --green-700: #15734c;
  --green-100: #e8f8ef;
  --slate-950: #152033;
  --slate-700: #42526a;
  --slate-500: #718096;
  --slate-300: #cbd5e1;
  --slate-200: #dfe6ef;
  --slate-100: #edf2f7;
  --canvas: #f3f6fb;
  --card: #ffffff;
  --shadow: 0 12px 35px rgba(20, 45, 79, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--slate-950);
  background: var(--canvas);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-700); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
code {
  padding: 2px 6px;
  border-radius: 6px;
  color: #173b68;
  background: #edf4fc;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  word-break: break-all;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(24px, 3vw, 32px); line-height: 1.25; letter-spacing: -.02em; }
h2 { margin-bottom: 14px; font-size: 19px; line-height: 1.35; }
small { display: block; color: var(--slate-500); }
.muted, .form-help, .security-note { color: var(--slate-500); }
.eyebrow {
  margin: 0 0 6px;
  color: var(--gold-500);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .13em;
}

/* Login and one-time upgrade */
.auth-bg {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 28px 16px;
  background:
    radial-gradient(circle at 85% 10%, rgba(217, 163, 41, .18), transparent 28%),
    linear-gradient(135deg, var(--navy-950), var(--navy-800));
}
.auth-shell { width: min(100%, 480px); }
.auth-card {
  padding: clamp(26px, 6vw, 42px);
  border: 1px solid rgba(255, 255, 255, .65);
  border-radius: 24px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 30px 70px rgba(0, 8, 28, .35);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 20px;
  border-radius: 17px;
  color: var(--navy-950);
  background: linear-gradient(145deg, #ffe6a1, var(--gold-500));
  font-weight: 900;
  letter-spacing: -.05em;
  box-shadow: 0 10px 24px rgba(217, 163, 41, .3);
}
.auth-card label, .card label { display: block; margin: 13px 0 6px; font-weight: 700; color: #2e405a; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--slate-300);
  border-radius: 10px;
  color: var(--slate-950);
  background: #fff;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(24, 114, 229, .12); }
input[type="checkbox"] { width: 16px; min-height: auto; height: 16px; margin: 0; accent-color: var(--blue-600); }
.security-note { margin: 18px 0 0; text-align: center; font-size: 12px; }
.feature-list { padding-left: 20px; color: var(--slate-700); }
.feature-list li { margin: 8px 0; }

/* Shared controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid var(--slate-200);
  border-radius: 9px;
  color: #263a55;
  background: #f8fafc;
  font-weight: 750;
  transition: transform .15s, box-shadow .15s, background .15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(20, 45, 79, .1); }
.btn-primary { border-color: var(--blue-600); color: #fff; background: linear-gradient(135deg, var(--blue-600), #0d55bd); }
.btn-danger { border-color: #ffd5d8; color: var(--red-600); background: var(--red-100); }
.btn-small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 20px; }
.flash { margin-bottom: 18px; padding: 12px 14px; border-radius: 10px; font-weight: 650; }
.flash-success { color: var(--green-700); background: var(--green-100); border: 1px solid #c9edd9; }
.flash-error { color: var(--red-600); background: var(--red-100); border: 1px solid #ffd5d8; }
.badge, .soft-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.soft-badge { color: var(--slate-700); background: var(--slate-100); }
.badge-ok { color: var(--green-700); background: var(--green-100); }
.badge-off { color: var(--slate-700); background: var(--slate-100); }
.badge-warn, .badge-expired { color: #995b00; background: var(--gold-100); }
.text-warning { color: #a86200; font-weight: 700; }
.link-danger { padding: 4px 0; border: 0; color: var(--red-600); background: transparent; font-weight: 700; }

/* Application frame */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: 245px;
  padding: 22px 16px;
  color: #d9e8fa;
  background: linear-gradient(180deg, var(--navy-950), var(--navy-900));
  box-shadow: 10px 0 35px rgba(8, 30, 58, .12);
}
.side-brand { display: flex; align-items: center; gap: 12px; padding: 2px 8px 24px; color: #fff; }
.side-brand strong { display: block; font-size: 18px; }
.side-brand small { color: #8fb0d5; font-size: 11px; }
.small-mark { flex: 0 0 auto; width: 38px; height: 38px; margin: 0; border-radius: 11px; font-size: 12px; }
.side-nav { display: grid; gap: 5px; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: 10px; color: #aec5df; font-weight: 680; }
.side-nav a span { display: grid; place-items: center; width: 22px; color: #81a8d1; font-size: 18px; }
.side-nav a:hover, .side-nav a.active { color: #fff; background: rgba(255, 255, 255, .1); }
.side-nav a.active { box-shadow: inset 3px 0 0 var(--gold-500); }
.side-nav a.active span { color: #ffd56c; }
.side-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.1); color: #91acd0; font-size: 12px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #32ce83; box-shadow: 0 0 0 4px rgba(50, 206, 131, .12); }
.content-shell { min-height: 100vh; margin-left: 245px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 116px; padding: 24px clamp(24px, 4vw, 52px); border-bottom: 1px solid var(--slate-200); background: rgba(255,255,255,.93); }
.page-head h1 { margin: 0; }
.admin-chip { display: flex; align-items: center; gap: 12px; padding: 7px 7px 7px 14px; border: 1px solid var(--slate-200); border-radius: 999px; background: #fff; }
.admin-chip form { margin: 0; }
.admin-chip button { padding: 6px 10px; border: 0; border-radius: 999px; color: var(--slate-700); background: var(--slate-100); }
.mobile-topbar { display: none; }
.main-content { width: min(100%, 1540px); margin: 0 auto; padding: 30px clamp(20px, 4vw, 52px) 48px; }
.sidebar-overlay { display: none; }

/* Dashboard and cards */
.card {
  min-width: 0;
  margin-bottom: 20px;
  padding: 22px;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 4px 18px rgba(20, 45, 79, .04);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.card-head h2 { margin: 0; }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric-card {
  position: relative;
  overflow: hidden;
  min-height: 145px;
  padding: 21px;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  color: var(--slate-950);
  background: #fff;
  box-shadow: var(--shadow);
}
.metric-card::after { content: ""; position: absolute; right: -30px; bottom: -40px; width: 120px; height: 120px; border-radius: 50%; opacity: .12; background: currentColor; }
.metric-card span, .metric-card small { position: relative; z-index: 1; }
.metric-card strong { position: relative; z-index: 1; display: block; margin: 8px 0 2px; font-size: 38px; line-height: 1; }
.metric-card.blue { color: #1454a7; border-top: 4px solid #2780e8; }
.metric-card.gold { color: #986513; border-top: 4px solid var(--gold-500); }
.metric-card.red { color: #b62934; border-top: 4px solid #e65761; }
.metric-card.slate { color: #4c5d74; border-top: 4px solid #718096; }
.metric-card.violet { color: #6941a5; border-top: 4px solid #8b5fc2; }
.split-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .7fr); gap: 20px; }
.two-col, .security-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.accent-card { display: grid; grid-template-columns: minmax(220px, .65fr) minmax(260px, 1fr); gap: 22px; border-color: #efd787; background: linear-gradient(135deg, #fffdf6, var(--gold-100)); }
.info-card { background: linear-gradient(145deg, #f7fbff, #fff); }
.copy-row { display: flex; align-items: stretch; gap: 8px; }
.copy-row input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.copy-row .btn { flex: 0 0 auto; }
.activity-list { display: grid; gap: 1px; }
.activity-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--slate-100); }
.activity-item:last-child { border-bottom: 0; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red-600); box-shadow: 0 0 0 4px var(--red-100); }
.status-dot.ok { background: #25a269; box-shadow: 0 0 0 4px var(--green-100); }
.activity-meta { display: grid; justify-items: end; gap: 4px; }
.quick-action { display: flex; align-items: center; gap: 12px; margin-top: 10px; padding: 13px; border: 1px solid var(--slate-200); border-radius: 12px; color: var(--slate-950); }
.quick-action:hover { border-color: #a9c9ee; background: #f5faff; }
.quick-action > span { display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; border-radius: 10px; color: var(--blue-700); background: var(--blue-100); font-size: 20px; }
.empty-state { padding: 24px 12px; color: var(--slate-500); text-align: center; }

/* Forms and tables */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 18px; }
.full { grid-column: 1 / -1; }
.card-head-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.filter-bar { display: grid; grid-template-columns: minmax(240px, 1fr) 180px auto; gap: 10px; margin-bottom: 16px; }
.quick-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.quick-pills button, .renew-row button { padding: 5px 9px; border: 1px solid #cddff5; border-radius: 999px; color: var(--blue-700); background: #f4f9ff; font-size: 11px; font-weight: 700; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--slate-100); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 11px; border-bottom: 1px solid var(--slate-100); text-align: left; vertical-align: top; }
th { color: #5b6d83; background: #f8fafc; font-size: 11px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfdff; }
td small { max-width: 290px; margin-top: 4px; }
.actions-cell, .stack-actions > div, .renew-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions-cell form, .stack-actions form, .renew-row form { margin: 0; }
.stack-actions { min-width: 210px; }
.renew-row { margin: 6px 0; }
.permanent-badge { display: inline-flex; padding: 4px 10px; border-radius: 999px; color: #7a5200; background: linear-gradient(135deg, #fff7df, #ffe8a3); font-weight: 850; }
.permanent-row { display: flex !important; align-items: center; gap: 10px; margin-top: 18px !important; padding: 11px 12px; border: 1px solid #efd787; border-radius: 11px; background: var(--gold-100); cursor: pointer; }
.permanent-row input { flex: 0 0 auto; }
.permanent-row strong, .permanent-row small { display: block; }
.is-hidden { display: none !important; }
.delete-row { display: flex; align-items: center; gap: 8px; }
.confirm-label, .confirm-box { display: inline-flex !important; align-items: center; gap: 6px; margin: 0 !important; color: var(--slate-500) !important; font-size: 11px; font-weight: 650 !important; white-space: nowrap; }
.confirm-box { width: 100%; margin: 16px 0 !important; padding: 12px; border: 1px solid #f1d4d6; border-radius: 10px; color: var(--red-600) !important; background: var(--red-100); white-space: normal; }
.hash-code { font-size: 11px; }
.security-status { background: linear-gradient(145deg, var(--navy-900), #174b7e); color: #fff; }
.security-status h2, .security-status p, .security-status li { color: #fff; }
.security-status code { color: #173b68; background: #fff; }
.security-icon { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 18px; border-radius: 50%; color: #0e603d; background: #a9f1cb; font-size: 24px; font-weight: 900; }
.command-code { display: block; margin-top: 8px; padding: 10px; white-space: normal; }

/* Customer authorization modal */
.license-modal {
  width: min(760px, calc(100vw - 28px));
  max-height: min(88vh, 820px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: transparent;
  box-shadow: 0 30px 85px rgba(3, 17, 39, .35);
}
.license-modal::backdrop { background: rgba(4, 18, 38, .68); backdrop-filter: blur(3px); }
.modal-form { overflow: auto; max-height: min(88vh, 820px); padding: 24px; border: 1px solid rgba(255,255,255,.6); border-radius: 20px; background: #fff; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin: -24px -24px 18px; padding: 23px 24px 19px; color: #fff; background: linear-gradient(135deg, var(--navy-950), var(--navy-800)); }
.modal-head h2 { margin-bottom: 5px; color: #fff; font-size: 22px; }
.modal-head p { margin-bottom: 0; color: #b9cee7; }
.modal-head .eyebrow { color: #ffd56c; }
.modal-close { flex: 0 0 auto; width: 38px; height: 38px; padding: 0; border: 1px solid rgba(255,255,255,.18); border-radius: 10px; color: #fff; background: rgba(255,255,255,.08); font-size: 25px; line-height: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--slate-100); }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  body.menu-open { overflow: hidden; }
  .sidebar { transform: translateX(-105%); transition: transform .2s ease; }
  body.menu-open .sidebar { transform: translateX(0); }
  .sidebar-overlay { position: fixed; inset: 0; z-index: 20; background: rgba(5, 16, 31, .52); }
  body.menu-open .sidebar-overlay { display: block; }
  .content-shell { margin-left: 0; }
  .mobile-topbar { display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 16px; color: #fff; background: var(--navy-950); }
  .menu-button { width: 38px; height: 38px; border: 0; border-radius: 9px; color: #fff; background: rgba(255,255,255,.1); font-size: 20px; }
  .page-head { min-height: 100px; padding: 20px; }
  .admin-chip > span { display: none; }
  .main-content { padding: 20px 14px 36px; }
  .two-col, .security-grid, .accent-card { grid-template-columns: 1fr; }
  .license-modal { width: min(720px, calc(100vw - 24px)); }
}

@media (max-width: 620px) {
  h1 { font-size: 24px; }
  .page-head { align-items: flex-end; }
  .page-head .eyebrow { display: none; }
  .card { padding: 17px; border-radius: 13px; }
  .metric-grid { gap: 10px; }
  .metric-card { min-height: 122px; padding: 16px; }
  .metric-card strong { font-size: 32px; }
  .form-grid, .filter-bar { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .copy-row { flex-direction: column; }
  .table-wrap { overflow: visible; border: 0; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tr { padding: 10px 13px; border: 1px solid var(--slate-200); border-radius: 12px; background: #fff; }
  td { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--slate-200); }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); color: var(--slate-500); font-size: 11px; font-weight: 750; }
  td[colspan] { display: block; }
  td[colspan]::before { display: none; }
  .actions-cell, .stack-actions { display: block; min-width: 0; }
  .actions-cell::before, .stack-actions::before { margin-bottom: 7px; }
  .activity-item { grid-template-columns: auto minmax(0, 1fr); }
  .activity-meta { grid-column: 2; justify-items: start; }
  .card-head-actions { align-items: stretch; flex-direction: column; }
  .modal-form { padding: 18px; }
  .modal-head { margin: -18px -18px 16px; padding: 19px 18px; }
  .modal-actions { position: sticky; bottom: -18px; margin: 18px -18px -18px; padding: 13px 18px; background: #fff; }
}

@media (max-width: 420px) {
  .metric-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 26px 20px; }
}
