:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e242c;
  --border: #2a313b;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --accent: #4caf50;
  --accent-2: #3d8b40;
  --danger: #e5534b;
  --warn: #d29922;
  --info: #388bfd;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", "Malgun Gothic", system-ui, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: normal; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }

button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent-2); border-color: var(--accent); }
button.danger { color: #fff; background: #8e2a25; border-color: var(--danger); }
button.ghost { background: transparent; }
button.small { padding: 3px 10px; font-size: 12px; }

input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--info); }
label { display: block; color: var(--muted); font-size: 12px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; }
label.inline input { width: auto; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.label { color: var(--muted); font-size: 12px; margin-bottom: 8px; font-weight: 600; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 18px; margin: 0; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 18px;
  background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
#tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#tabs button { background: transparent; border-color: transparent; }
#tabs button.active { background: var(--panel-2); border-color: var(--border); }

.badge { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.on { background: rgba(76,175,80,.15); color: #7ee787; border-color: var(--accent-2); }
.badge.off { background: rgba(229,83,75,.12); color: #ff9b95; border-color: #8e2a25; }
.badge.busy { background: rgba(56,139,253,.15); color: #79c0ff; border-color: var(--info); }

#banners { padding: 0 18px; }
.banner { margin-top: 12px; padding: 10px 14px; border-radius: var(--radius); display: flex; align-items: center; gap: 12px; }
.banner.info { background: rgba(56,139,253,.12); border: 1px solid var(--info); }
.banner.warn { background: rgba(210,153,34,.12); border: 1px solid var(--warn); }

main { padding: 18px; max-width: 1280px; margin: 0 auto; }
.tab { display: flex; flex-direction: column; gap: 14px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.controls.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row input, .row select { flex: 1; min-width: 140px; }

.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.charts { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.lists { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.mods { grid-template-columns: 2fr 1fr; }
@media (max-width: 800px) { .mods { grid-template-columns: 1fr; } }

.stat .value { font-size: 24px; font-weight: 600; }
.stat .sub { color: var(--muted); font-size: 12px; }
canvas { width: 100%; display: block; }

.chips { list-style: none; padding: 0; margin: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.chips li { background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 12px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li .actions { display: flex; gap: 4px; }
.list .empty { color: var(--muted); }

/* Console */
.console-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: transparent; }
.segmented button.active { background: var(--panel-2); }
.log {
  margin: 0; background: #0a0c0f; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; height: calc(100vh - 290px); min-height: 300px; overflow: auto;
  font: 12.5px/1.45 Consolas, "D2Coding", monospace; white-space: pre-wrap; word-break: break-all;
}
.log .warn { color: #e3b341; }
.log .err { color: #ff7b72; }
.log .cmd { color: #79c0ff; }
.log .resp { color: #a5d6ff; }
.command { display: flex; gap: 8px; }
.command input { font-family: Consolas, monospace; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions button { margin-left: 4px; }

/* Settings */
.section-title { font-size: 13px; font-weight: 700; margin: 6px 0 10px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px 16px; }
.field .key { font-family: Consolas, monospace; font-size: 12px; color: var(--text); }
.field .desc { color: var(--muted); font-size: 12px; margin: 2px 0 4px; min-height: 1em; }
.field input[readonly] { opacity: .6; }
#settings-fields { display: flex; flex-direction: column; gap: 14px; }

textarea#mods-text { min-height: 360px; font: 13px/1.5 Consolas, monospace; resize: vertical; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; }

/* Client mod pack */
#cp-status.warn { color: var(--warn); }
#cp-status.error { min-height: 0; }

/* Records */
#records-raw-select { width: auto; }
.ev-fail td:nth-child(3) { color: #ff7b72; font-weight: 600; }
.ev-ok td:nth-child(3) { color: #7ee787; }
.table td.wrap { white-space: normal; word-break: break-all; }

/* Guide */
.guide { display: grid; grid-template-columns: 240px 1fr; gap: 14px; align-items: start; }
@media (max-width: 800px) { .guide { grid-template-columns: 1fr; } }
.guide-nav { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 2px; padding: 8px; }
.guide-nav button { text-align: left; background: transparent; border-color: transparent; padding: 6px 10px; }
.guide-nav button.active { background: var(--panel-2); border-color: var(--border); }
.markdown { padding: 20px 28px; line-height: 1.7; overflow-wrap: anywhere; min-width: 0; }
.markdown h1 { font-size: 22px; margin: 0 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.markdown h2 { font-size: 18px; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 15px; margin: 22px 0 8px; }
.markdown h4 { font-size: 14px; margin: 18px 0 6px; }
.markdown p { margin: 8px 0; }
.markdown ul, .markdown ol { margin: 8px 0; padding-left: 24px; }
.markdown li { margin: 3px 0; }
.markdown li.task { list-style: none; margin-left: -20px; }
.markdown a { color: #79c0ff; text-decoration: none; cursor: pointer; }
.markdown a:hover { text-decoration: underline; }
.markdown code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font: 12.5px Consolas, monospace; }
.markdown pre { background: #0a0c0f; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
.markdown pre code { background: none; border: 0; padding: 0; white-space: pre; }
.markdown blockquote { margin: 10px 0; padding: 6px 14px; border-left: 4px solid var(--info); background: rgba(56,139,253,.08); border-radius: 0 8px 8px 0; }
.markdown table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.markdown th { background: var(--panel-2); }

/* Toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: 420px; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--info); padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.4); word-break: break-word; }
.toast.ok { border-left-color: var(--accent); }
.toast.err { border-left-color: var(--danger); }
