:root {
  color-scheme: dark;
  --bg: #0b1120;
  --bg-alt: #0f172a;
  --panel: #111c31;
  --panel-2: #16233c;
  --line: #22304d;
  --text: #e5edff;
  --muted: #8da2c4;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #fb7185;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .25);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(1200px 600px at 15% -10%, #1b2a52 0%, transparent 60%),
              radial-gradient(900px 500px at 100% 0%, #10303f 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  line-height: 1.5;
}

[hidden] { display: none !important; }

h1, h2, h3, p { margin: 0 0 .6rem; }
h1 { font-size: 1.55rem; letter-spacing: -.02em; }
h2 { font-size: 1.35rem; letter-spacing: -.02em; }
h3 { font-size: 1rem; font-weight: 650; }

code, pre, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .86em;
}

code { background: #1b2945; padding: .1rem .35rem; border-radius: 5px; color: #b6c8ff; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); font-weight: 400; font-size: .85rem; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .55rem .9rem;
  font: inherit;
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:hover { background: #1e2f50; border-color: #35507e; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #4f46e5); border-color: transparent; color: #fff; }
.btn-primary:hover { background: linear-gradient(135deg, #7376ff, #5b52f0); }
.btn-danger { background: #3a1726; border-color: #7f2947; color: #ffc4d3; }
.btn-danger:hover { background: #541d34; }
.btn-ghost { background: transparent; }
.btn-sm { padding: .35rem .6rem; font-size: .78rem; }
.btn-block { width: 100%; display: block; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(100%, 420px);
  background: linear-gradient(180deg, rgba(22, 35, 60, .95), rgba(15, 23, 42, .95));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: .9rem; margin-bottom: 1.6rem; }
.brand p { color: var(--muted); font-size: .85rem; margin: 0; }
.brand-logo { width: 46px; height: 46px; border-radius: 11px; }
.form-error { color: var(--err); font-size: .85rem; margin-top: .8rem; }
.hint-text { color: var(--muted); font-size: .78rem; margin-top: 1.2rem; line-height: 1.6; }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: rgba(9, 15, 30, .82);
  border-right: 1px solid var(--line);
  padding: 1.2rem .9rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .6rem;
  padding: .4rem .6rem 1.4rem;
  font-weight: 700;
  letter-spacing: -.01em;
}
.sidebar-brand .brand-logo { width: 30px; height: 30px; border-radius: 8px; }
.nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: .7rem;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: .62rem .75rem;
  border-radius: 9px;
  font: inherit;
  font-size: .9rem;
  font-weight: 550;
  cursor: pointer;
}
.nav-item:hover { background: #14213a; color: var(--text); }
.nav-item.active { background: #1b2b50; color: #fff; border-color: #2f477a; }
.nav-icon { width: 1.2rem; text-align: center; color: var(--accent-2); font-size: 1rem; }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; padding: .8rem .4rem 0; border-top: 1px solid var(--line); }
.badge { font-size: .72rem; color: var(--muted); background: #1b2945; padding: .15rem .45rem; border-radius: 6px; }

.main { flex: 1; min-width: 0; padding: 1.6rem 1.8rem 3rem; max-width: 1500px; width: 100%; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; }
.topbar p { color: var(--muted); font-size: .85rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 4px rgba(251, 191, 36, .12); }
.status-dot.online { background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 211, 153, .12); }
.status-text { color: var(--muted); font-size: .82rem; }

/* ---------- cards & grids ---------- */
.card { background: linear-gradient(180deg, rgba(19, 30, 52, .9), rgba(15, 23, 42, .9)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 1.2rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.card-head h3 { margin: 0; }
.card-body { padding: 1.2rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.2rem; }
.grid-2 .card { margin-bottom: 0; }
.view { display: flex; flex-direction: column; gap: 1.2rem; }
.view > .card { margin-bottom: 0; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; }
.stat {
  background: linear-gradient(160deg, #16233c, #101a30);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.stat .label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; }
.stat .value { font-size: 1.9rem; font-weight: 750; letter-spacing: -.03em; margin-top: .35rem; line-height: 1; }
.stat .sub { color: var(--muted); font-size: .76rem; margin-top: .5rem; }
.stat.ok .value { color: var(--ok); }
.stat.err .value { color: var(--err); }
.stat.accent .value { color: var(--accent-2); }

/* ---------- chart ---------- */
.hourly { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 4px; align-items: end; min-height: 130px; }
.hcol { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hcol meter { width: 100%; height: 88px; }
.hcol span { font-size: .6rem; color: var(--muted); }
meter { appearance: none; border: 0; background: #1b2945; border-radius: 5px; overflow: hidden; }
meter::-webkit-meter-bar { background: #1b2945; border-radius: 5px; }
meter::-webkit-meter-optimum-value { background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-radius: 5px; }
meter::-moz-meter-bar { background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-radius: 5px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.table th, .table td { text-align: left; padding: .65rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: rgba(99, 102, 241, .05); }
.table .actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.tag { display: inline-block; font-size: .7rem; padding: .15rem .45rem; border-radius: 5px; background: #1b2945; color: var(--muted); }
.tag.ok { background: rgba(52, 211, 153, .12); color: var(--ok); }
.tag.err { background: rgba(251, 113, 133, .13); color: var(--err); }
.tag.off { background: rgba(148, 163, 184, .12); color: #94a3b8; }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }

/* ---------- forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; }
input[type="text"], input[type="password"], input[type="number"], input:not([type]), select, textarea {
  width: 100%;
  background: #0d1628;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: .6rem .7rem;
  font: inherit;
  font-size: .88rem;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
input:disabled { opacity: .55; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.nested { gap: .7rem; }
.field { min-width: 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .85rem; margin: 0; }
legend { padding: 0 .4rem; font-size: .85rem; font-weight: 600; }
.setting { margin-bottom: 1.25rem; }
.setting > p { margin-top: .35rem; }
.switch-label { display: inline-block; margin-right: .8rem; }
.switch { width: 18px !important; height: 18px !important; accent-color: var(--accent); vertical-align: middle; }
.order-list { display: flex; flex-direction: column; gap: .5rem; }
.order-row { display: flex; align-items: center; gap: .5rem; }
.order-row code { flex: 1; }
.toolbar { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; }
.toolbar select { width: auto; min-width: 160px; }
.pagination { display: flex; align-items: center; gap: .7rem; justify-content: flex-end; margin-top: 1rem; }

/* ---------- code ---------- */
.code-block {
  background: #0a1222;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: .9rem;
  overflow: auto;
  max-height: 340px;
  color: #c7d6f5;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.code-head { display: flex; align-items: center; justify-content: space-between; margin: 1rem 0 .5rem; font-size: .85rem; font-weight: 600; }
.preview { margin-bottom: 1rem; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.preview img { display: block; max-width: 100%; max-height: 320px; }

/* ---------- modal ---------- */
#modal-root { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 7, 18, .75); backdrop-filter: blur(3px); }
.modal { position: relative; width: min(100%, 520px); max-height: 90vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-close { background: transparent; border: 0; color: var(--muted); font-size: 1.5rem; cursor: pointer; line-height: 1; }
.modal-body { padding: 1.2rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: 0 1.2rem 1.2rem; }
.secret-box { background: #0a1222; border: 1px dashed #3a517f; border-radius: 9px; padding: .8rem; word-break: break-all; font-size: .85rem; color: var(--accent-2); }

/* ---------- toast ---------- */
.toast-root { position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 60; display: flex; flex-direction: column; gap: .6rem; }
.toast { background: #172740; border: 1px solid #35507e; border-radius: 9px; padding: .7rem .95rem; font-size: .85rem; box-shadow: var(--shadow); animation: slide .2s ease; }
.toast.success { border-color: #1f7a5c; }
.toast.error { border-color: #8f2d4a; }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- docs ---------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.doc-item { border: 1px solid var(--line); border-radius: 10px; padding: .9rem; }
.doc-item strong { display: block; color: var(--accent-2); font-size: .8rem; margin-bottom: .3rem; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { width: 68px; flex-basis: 68px; padding: 1rem .4rem; }
  .sidebar-brand span, .nav-item:not(.nav-icon), .sidebar-foot .badge { font-size: 0; }
  .sidebar-brand { justify-content: center; }
  .nav-item { justify-content: center; }
  .nav-icon { width: auto; font-size: 1.15rem; }
}
@media (max-width: 640px) {
  .main { padding: 1.1rem 1rem 2rem; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .hourly { gap: 2px; }
  .hcol span { display: none; }
}
