:root {
  --bg: #12151b;
  --bg2: #181c24;
  --card: #1e232d;
  --line: #2c3240;
  --text: #e6e9ef;
  --muted: #8b93a5;
  --accent: #41b35d;
  --accent-dark: #2f8a46;
  --danger: #e05252;
  --warn: #e8a33d;
  --info: #4a9fe0;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
a { color: var(--accent); }
h3 { margin: 0 0 12px; font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600;
  text-decoration: none; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: #465066; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1a11; }
.btn.primary:hover { background: #4cc569; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { color: var(--danger); background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.huge { padding: 14px 42px; font-size: 18px; }

input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }

/* Login */
.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px; width: 100%; max-width: 360px; display: grid; gap: 12px;
}

/* Layout */
.app { display: flex; min-height: 100%; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--bg2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.brand.big { font-size: 22px; padding: 0; }
.logo {
  width: 22px; height: 22px; border-radius: 5px; background: var(--accent); display: inline-block;
  box-shadow: inset 5px 5px 0 -1px #123, inset -5px 5px 0 -1px #123;
}
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  color: var(--muted); text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 500;
}
nav a:hover { background: var(--card); color: var(--text); }
nav a.active { background: var(--card); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; padding: 8px; }
.mini-status { display: flex; align-items: center; gap: 8px; font-weight: 600; }

main { flex: 1; padding: 24px; min-width: 0; max-width: 1200px; }
.page { display: none; gap: 16px; }
.page.active { display: grid; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.row-between h3 { margin: 0; }

/* Status dot / pill */
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.s-online .dot, .dot.s-online { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot.s-starting, .dot.s-stopping { background: var(--warn); }
.dot.s-crashed { background: var(--danger); }
.state-pill {
  display: inline-block; padding: 6px 18px; border-radius: 999px; font-weight: 700; font-size: 16px;
  letter-spacing: .5px; text-transform: uppercase; background: var(--bg2); color: var(--muted); margin: 14px 0 4px;
}
.state-pill.s-online { background: rgba(65,179,93,.15); color: var(--accent); }
.state-pill.s-starting, .state-pill.s-stopping { background: rgba(232,163,61,.15); color: var(--warn); }
.state-pill.s-crashed { background: rgba(224,82,82,.15); color: var(--danger); }

/* Hero */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; padding: 28px; }
.hero-main { text-align: center; }
.address { font-size: 26px; font-weight: 800; cursor: pointer; word-break: break-all; }
.address:hover { color: var(--accent); }
.power { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; align-items: center; }
.hero-side { border-left: 1px solid var(--line); padding-left: 24px; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.motd { font-family: var(--mono); background: var(--bg); padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; min-height: 2.5em; }
.players-big { font-size: 28px; font-weight: 800; }
.player-heads { display: flex; flex-wrap: wrap; gap: 6px; }
.player-heads img { width: 28px; height: 28px; border-radius: 4px; image-rendering: pixelated; }

.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 24px; font-weight: 800; margin: 2px 0 6px; }
.stat canvas { width: 100%; height: 60px; display: block; }

table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.kv td:first-child { color: var(--muted); width: 40%; }
table.kv tr:last-child td { border-bottom: 0; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar > div { height: 100%; background: var(--accent); }

/* Console */
.console-card { display: grid; gap: 10px; }
.console-head { display: flex; justify-content: space-between; align-items: center; }
.console-head h3 { margin: 0; }
.console {
  background: #0b0d11; border-radius: 8px; padding: 12px; margin: 0; height: 60vh; overflow: auto;
  font: 12.5px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word;
}
.console .l-warn { color: var(--warn); }
.console .l-error { color: var(--danger); }
.console .l-system { color: var(--info); }
.console .l-input { color: var(--accent); }
.console .l-join { color: #9ad1a8; }
.console-input { display: flex; gap: 8px; align-items: center; }
.console-input .prompt { font-family: var(--mono); color: var(--accent); font-weight: 700; }
.console-input input { font-family: var(--mono); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }

/* Players */
.player-list { display: grid; gap: 6px; }
.player {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; background: var(--bg2);
}
.player img { width: 24px; height: 24px; border-radius: 3px; image-rendering: pixelated; }
.player .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.player .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.player select { width: auto; padding: 3px 6px; font-size: 12px; }
.inline-add { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-bottom: 10px; }
.inline-add input.reason { grid-column: 1 / -1; order: 3; }
.empty { color: var(--muted); font-style: italic; padding: 6px 2px; }

/* Options */
.opt-group { margin-bottom: 18px; }
.opt-group h4 { margin: 0 0 8px; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .8px; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px 18px; }
.opt { display: grid; gap: 4px; }
.opt label { font-weight: 600; }
.opt .help { font-size: 11px; color: var(--muted); }
.opt.bool { grid-template-columns: 1fr auto; align-items: center; background: var(--bg2); padding: 8px 12px; border-radius: 8px; }
.toggle { position: relative; width: 42px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span {
  position: absolute; inset: 0; background: var(--line); border-radius: 12px; cursor: pointer; transition: .15s;
}
.toggle span::after {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s;
}
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(18px); }
.opt.changed label { color: var(--warn); }
.raw-row { display: grid; grid-template-columns: minmax(160px, 1fr) 2fr auto; gap: 8px; margin-bottom: 6px; align-items: center; }
.raw-row code { font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }

/* Software */
.sw-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 12px 0; }
.sw-type { background: var(--bg2); border: 2px solid var(--line); border-radius: 10px; padding: 14px; cursor: pointer; }
.sw-type:hover { border-color: #465066; }
.sw-type.selected { border-color: var(--accent); }
.sw-type b { display: block; font-size: 15px; margin-bottom: 4px; }
.sw-install { display: grid; gap: 10px; max-width: 480px; }
.sw-install label { display: grid; gap: 4px; }
.progress { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* Files */
.breadcrumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-family: var(--mono); }
.breadcrumbs a { cursor: pointer; }
.fm-actions { display: flex; gap: 6px; flex-wrap: wrap; }
table.files { width: 100%; border-collapse: collapse; }
table.files th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.files td { padding: 7px 8px; border-bottom: 1px solid var(--line); }
table.files tr:hover td { background: var(--bg2); }
table.files td.actions { text-align: right; white-space: nowrap; }
table.files .fname { cursor: pointer; }
table.files .fname:hover { color: var(--accent); }
#fm-text {
  height: 60vh; font: 12.5px/1.45 var(--mono); resize: vertical; white-space: pre; tab-size: 4;
}

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px 18px; }
.form-grid label { display: grid; gap: 4px; font-weight: 600; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; grid-column: 1 / -1; }
.form-grid h3 { margin: 12px 0 0; }
.switch-label { display: flex; align-items: center; gap: 6px; }

/* Dialog & toasts */
dialog {
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px; max-width: 440px; padding: 24px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 380px;
}
.toast.err { border-left-color: var(--danger); }

/* Mobile */
@media (max-width: 800px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 4px 8px; }
  nav { flex-direction: row; flex-wrap: wrap; order: 3; width: 100%; }
  nav a { padding: 6px 10px; }
  .sidebar-foot { margin: 0 0 0 auto; display: flex; padding: 0; }
  main { padding: 16px; }
  .hero { grid-template-columns: 1fr; padding: 18px; }
  .hero-side { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 16px; }
  .btn.huge { padding: 12px 28px; }
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 20px; }
  table.files .col-mod { display: none; }
}
