:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6ea;
  --text: #1c2128;
  --text-2: #6a737d;
  --accent: #f6821f;          /* Cloudflare orange */
  --accent-2: #2563eb;
  --green: #1a9c4c;
  --red: #d83a3a;
  --amber: #c98a00;
  --blue: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #181b20; --surface-2: #21252b; --border: #2b3036;
    --text: #e6e8eb; --text-2: #9aa3ad; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--accent-2); text-decoration: none; }
h1,h2,h3 { margin: 0 0 .5em; font-weight: 650; }
code, pre { font-family: var(--mono); }

.boot { display: grid; place-items: center; height: 100vh; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 40px; width: 100%; max-width: 400px; text-align: center; }
.login-card .logo { font-size: 26px; font-weight: 750; letter-spacing: -.5px; }
.login-card .logo span { color: var(--accent); }
.login-card p { color: var(--text-2); margin: 8px 0 28px; }
.gbtn { display: inline-flex; align-items: center; gap: 10px; width: 100%; justify-content: center; padding: 11px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; }
.gbtn:hover { background: var(--surface-2); }
.gbtn img { width: 18px; height: 18px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; align-items: start; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-size: 19px; font-weight: 750; letter-spacing: -.4px; padding: 6px 10px 18px; }
.brand span { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text-2); font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--accent); }
.nav a .ic { width: 17px; text-align: center; }
.side-foot { border-top: 1px solid var(--border); padding-top: 12px; font-size: 12px; color: var(--text-2); }
.side-foot .who { font-weight: 600; color: var(--text); margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; }
.side-foot .row { display: flex; gap: 8px; align-items: center; }
.side-foot .updated { margin-top: 10px; font-size: 11px; color: var(--text-2); opacity: .8; }

.main { padding: 26px 32px; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .sub { color: var(--text-2); font-size: 13px; margin-top: 3px; }

/* ---------- Cards / grid ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px,1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 150ms cubic-bezier(0.4, 0, 0.2, 1), border-color 150ms ease; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 6px 16px rgba(16,24,40,.08); }
.card .label { color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card .val { font-size: 26px; font-weight: 700; margin-top: 6px; }
.card .val.sm { font-size: 18px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 150ms cubic-bezier(0.4, 0, 0.2, 1), border-color 150ms ease; }
.panel:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); box-shadow: 0 4px 12px rgba(16,24,40,.05); }
.panel h2 { font-size: 15px; }
.panel .panel-sub { color: var(--text-2); font-size: 12px; margin: -6px 0 14px; }
.dash-two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { .dash-two { grid-template-columns: 1fr; } }
/* Bounded canvas container — prevents Chart.js responsive infinite-height growth. */
.chart-box { position: relative; height: 300px; }
.chart-box.sm { height: 240px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 13px; cursor: pointer; transition: all 120ms ease; }
.btn:hover { background: var(--surface-2); transform: translateY(-0.5px); }
.btn:active { transform: translateY(0.5px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 4px 10px rgba(246, 130, 31, 0.2); }
.btn.primary:active { transform: translateY(0px); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field .hint { color: var(--text-2); font-size: 12px; margin-top: 4px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 13px; font-family: inherit; transition: all 150ms ease; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(246, 130, 31, 0.15); }
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); }
.toggle { display: flex; align-items: center; gap: 10px; }
.toggle input { width: auto; }
.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.inline .field { flex: 1; min-width: 160px; margin-bottom: 0; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
th { color: var(--text-2); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--surface-2); }
td.mono, .mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-2); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 650; white-space: nowrap; }
.badge.green { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.badge.red { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.badge.amber { background: color-mix(in srgb, var(--amber) 16%, transparent); color: var(--amber); }
.badge.blue { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.badge.gray { background: var(--surface-2); color: var(--text-2); }

/* ---------- Toast / modal ---------- */
#toast-root { position: fixed; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent-2); border-radius: 8px; padding: 11px 15px; box-shadow: 0 6px 20px rgba(0,0,0,.12); min-width: 240px; animation: slidein .2s ease; }
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }
#modal-root .overlay { position: fixed; inset: 0; background: rgba(10,14,20,.45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 90; padding: 20px; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); padding: 24px; width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; animation: modal-fade 180ms cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes modal-fade { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h3 { font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Misc ---------- */
.nowrap { white-space: nowrap; }
.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.lang-toggle button { border: none; background: var(--surface); color: var(--text-2); padding: 4px 9px; cursor: pointer; font-size: 12px; font-weight: 600; }
.lang-toggle button.on { background: var(--accent); color: #fff; }
.codeblock { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; overflow-x: auto; font-size: 12.5px; }
.codeblock pre { margin: 0; white-space: pre; }
.codeblock .copy { position: absolute; top: 8px; right: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { border: none; background: none; padding: 8px 14px; cursor: pointer; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 14px; }
.empty { text-align: center; color: var(--text-2); padding: 40px 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; }
.tag-input .tag { background: var(--surface-2); border-radius: 6px; padding: 3px 8px; font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.tag-input .tag b { cursor: pointer; color: var(--text-2); }
.tag-input input { border: none; flex: 1; min-width: 120px; padding: 4px; }
.kpill { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 2px 7px; border-radius: 6px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; position: static; height: auto; overflow: visible; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 18px; }
}
