:root[data-theme="dark"] {
  --bg: #0f141b;
  --glow1: rgba(254, 205, 25, 0.06);
  --glow2: rgba(45, 212, 191, 0.06);
  --card: #161d27;
  --border: #232c39;
  --border-strong: #33404f;
  --text: #e8edf4;
  --muted: #96a3b6;
  --faint: #657184;
  --accent: #2dd4bf;
  --accent-hi: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.15);
  --brand: #fecd19;
  --brand-soft: rgba(254, 205, 25, 0.15);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.15);
  --sky: #56c8f5;
  --sky-soft: rgba(86, 200, 245, 0.14);
  --input-bg: #101722;
  --term-bg: #0b111a;
  --term-text: #c3d2e4;
  --sidebar: #121820;
  --header-bg: rgba(15, 20, 27, 0.88);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 30px -18px rgba(0, 0, 0, 0.6);
}

:root[data-theme="light"] {
  --bg: #f5f7fb;
  --glow1: rgba(254, 205, 25, 0.16);
  --glow2: rgba(94, 234, 212, 0.2);
  --card: #ffffff;
  --border: #e9edf3;
  --border-strong: #d5dde7;
  --text: #182131;
  --muted: #657185;
  --faint: #9aa6b6;
  --accent: #0d9488;
  --accent-hi: #14b8a6;
  --accent-soft: #d6f3ef;
  --brand: #eab308;
  --brand-soft: #fdf4d3;
  --ok: #16a34a;
  --ok-soft: #dcfce9;
  --danger: #e5484d;
  --danger-soft: #ffe1e2;
  --warn: #d97706;
  --warn-soft: #fdeccd;
  --sky: #0284c7;
  --sky-soft: #e0f2fe;
  --input-bg: #f4f7fb;
  --term-bg: #141c28;
  --term-text: #c8d6e8;
  --sidebar: #ffffff;
  --header-bg: rgba(245, 247, 251, 0.9);
  --shadow: 0 1px 2px rgba(24, 33, 49, 0.05), 0 12px 30px -20px rgba(24, 33, 49, 0.18);
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  background-image:
    radial-gradient(820px 460px at 88% -140px, var(--glow1), transparent 62%),
    radial-gradient(680px 420px at -6% 8%, var(--glow2), transparent 58%);
  background-attachment: fixed;
  font: 14px/1.55 "DM Sans", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 550;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #042f2e;
}
:root[data-theme="light"] button.primary { color: #fff; }
button.danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}
button.warn {
  background: var(--warn-soft);
  border-color: transparent;
  color: var(--warn);
}
button.ghost { background: transparent; }

.mono { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
}
.badge .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.idle { background: var(--input-bg); color: var(--muted); border: 1px solid var(--border); }

.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 99px;
  background: var(--ok-soft);
  color: var(--ok);
}
.tag.manual { background: var(--brand-soft); color: var(--brand); }

.chip {
  font-size: 12px;
  color: var(--muted);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px 11px;
}

/* —— Login —— */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 390px;
  max-width: 100%;
  padding: 38px 34px 30px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.login-card .logo { width: 150px; margin: 0 auto 22px; color: var(--text); display: block; }
.login-card .logo svg { width: 100%; height: auto; display: block; }
.login-card h1 { text-align: center; font-size: 19px; letter-spacing: -0.01em; margin-bottom: 4px; font-weight: 650; }
.login-card .sub { text-align: center; margin-bottom: 22px; font-size: 13px; color: var(--muted); }
.login-card label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 7px;
}
.login-card input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .err { color: var(--danger); font-size: 13px; height: 20px; margin: 10px 0 4px; text-align: center; }
.login-card button.primary { width: 100%; padding: 11px 14px; margin-top: 8px; }
.login-card .foot { text-align: center; margin-top: 18px; font-size: 12px; color: var(--faint); }

/* —— App shell —— */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: 58px 1fr;
  min-height: 100vh;
}
.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand .logo { width: 88px; color: var(--text); display: flex; flex: none; }
.brand .logo svg { width: 100%; height: auto; }
.brand .divider { width: 1px; height: 24px; background: var(--border-strong); flex: none; }
.brand .meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brand .tagline {
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.theme-switch {
  display: flex;
  gap: 2px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
}
.theme-switch button {
  border: none;
  background: transparent;
  padding: 5px 9px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}
.theme-switch button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--sidebar);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 550;
}
.nav-btn:hover { background: var(--input-bg); color: var(--text); border: none; }
.nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-btn svg { width: 18px; height: 18px; flex: none; fill: currentColor; stroke: none; }

.main {
  padding: 22px 24px 48px;
  overflow: auto;
  min-width: 0;
}
.view-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.view-sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card h3 {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stat {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  min-height: 30px;
}
.stat small { font-size: 13px; font-weight: 500; color: var(--muted); }
.sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

.bar {
  height: 7px;
  border-radius: 99px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  margin-top: 12px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  border-radius: 99px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-hi));
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.bar.warn i { background: linear-gradient(90deg, #e0a53a, var(--warn)); }
.bar.crit i { background: linear-gradient(90deg, #e5484d, var(--danger)); }

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px dashed var(--border);
}
.kv:last-child { border-bottom: none; }
.kv span { color: var(--muted); }
.kv b { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 12px; font-weight: 600; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
}
th {
  color: var(--faint);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--input-bg); }

pre.term, .term {
  background: var(--term-bg);
  color: var(--term-text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  overflow: auto;
  max-height: 420px;
  min-height: 140px;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

.tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
}
.tabs button {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
}
.tabs button:hover { color: var(--text); border: none; background: transparent; }
.tabs button.active {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

textarea.env {
  width: 100%;
  min-height: 420px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--term-bg);
  color: var(--term-text);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  resize: vertical;
}
input.field {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  outline: none;
}
input.field:focus { border-color: var(--accent); }

.hint-box {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 14px;
}
.hint-box code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--accent);
}

.stormeter {
  display: flex;
  height: 12px;
  border-radius: 8px;
  overflow: hidden;
  margin: 4px 0 14px;
  border: 1px solid var(--border);
  background: var(--input-bg);
}
.stormeter i { height: 100%; }
.storleg { display: grid; gap: 9px; }
.storleg .r { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.storleg .sw { width: 11px; height: 11px; border-radius: 4px; flex: none; }
.storleg .r b {
  margin-left: auto;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}
.storleg .r span.h { color: var(--faint); font-size: 11px; }

.ssl-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px dashed var(--border);
}
.ssl-row:last-child { border-bottom: none; }
.ssl-row .d { display: flex; flex-direction: column; gap: 2px; }
.ssl-row .d small { color: var(--faint); font-size: 11px; }

.section-gap { margin-top: 18px; }

#toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 13px 18px;
  display: none;
  max-width: 420px;
  z-index: 100;
  font-size: 13px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
}

/* —— File explorer —— */
.fx {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 14px;
  align-items: start;
  height: calc(100vh - 180px);
  min-height: 460px;
}
.fx-side, .fx-main { padding: 12px; height: 100%; display: flex; flex-direction: column; min-height: 0; }
.fx-main { padding: 0; overflow: hidden; }

.fx-toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.fx-up { flex: none; padding: 8px 11px; font-size: 15px; line-height: 1; }
.fx-filter { flex: 1; min-width: 0; }

.fx-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  padding-bottom: 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.fx-crumb {
  border: none;
  background: transparent;
  padding: 2px 6px;
  border-radius: 7px;
  color: var(--accent);
  font-size: 12px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.fx-crumb:hover { background: var(--input-bg); border: none; }
.fx-crumb.cur { color: var(--text); font-weight: 650; }
.fx-sep { color: var(--faint); font-size: 12px; }

.fx-list { overflow-y: auto; flex: 1; margin: 0 -6px; padding: 0 2px; }
.fx-empty { color: var(--muted); font-size: 13px; padding: 18px 8px; text-align: center; }
.fx-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 7px 9px;
  border-radius: 9px;
  color: var(--text);
  font-weight: 500;
}
.fx-item:hover { background: var(--input-bg); border: none; }
.fx-item.active { background: var(--accent-soft); color: var(--accent); }
.fx-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.fx-link { color: var(--faint); }
.fx-size {
  flex: none;
  color: var(--faint);
  font-size: 11px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.fx-item.active .fx-size { color: var(--accent); }

.fi { width: 17px; height: 17px; flex: none; }
.fi.dir { fill: var(--brand); }
.fi.file { fill: var(--faint); }
.fi.lang-js, .fi.lang-ts { fill: var(--sky); }
.fi.lang-json, .fi.lang-yaml, .fi.lang-toml { fill: var(--warn); }
.fi.lang-css, .fi.lang-html { fill: var(--accent); }
.fi.lang-md { fill: var(--muted); }
.fi.lang-env, .fi.lang-sh { fill: var(--ok); }
.fi.lang-prisma, .fi.lang-sql { fill: #8fa6ff; }

.fx-fhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.fx-fmeta { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.fx-fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-fsize { color: var(--faint); font-size: 11px; flex: none; }
.fx-dl {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 550;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
}
.fx-dl:hover { border-color: var(--accent); }

.fx-view { flex: 1; min-height: 0; display: flex; }
.fx-codewrap { flex: 1; overflow: auto; background: var(--term-bg); }
.fx-codetbl {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
}
.fx-codetbl td { border: none; padding: 0; white-space: pre; }
.fx-ln {
  text-align: right;
  padding: 0 12px 0 16px !important;
  color: var(--faint);
  user-select: none;
  position: sticky;
  left: 0;
  background: var(--term-bg);
  border-right: 1px solid var(--border) !important;
  vertical-align: top;
}
.fx-code { padding: 0 16px 0 14px !important; color: var(--term-text); }
.fx-codetbl tr:hover td { background: rgba(127, 127, 127, 0.08); }
.fx-notice { padding: 22px; color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .fx { grid-template-columns: 1fr; height: auto; }
  .fx-side { max-height: 46vh; }
  .fx-main { min-height: 55vh; }
}

/* —— Console —— */
.con-warn { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.con-card .row { margin-bottom: 12px; }
.con-label { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.con-cwd { flex: 1; min-width: 0; max-width: 360px; }
.con-out { min-height: 300px; max-height: 52vh; margin-bottom: 12px; }
.con-out .con-cmd { color: var(--accent-hi); font-weight: 600; }
.con-out .con-ok { color: var(--ok); }
.con-out .con-err { color: var(--danger); }
.con-input { display: flex; align-items: center; gap: 8px; }
.con-input .con-prompt {
  color: var(--accent);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
}
.con-input .field {
  flex: 1;
  min-width: 0;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

/* —— File editor —— */
.fx-editor {
  width: 100%;
  height: 100%;
  min-height: 300px;
  border: none;
  outline: none;
  resize: none;
  padding: 12px 16px;
  background: var(--term-bg);
  color: var(--term-text);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre;
}
.fx-editing { color: var(--warn); font-size: 12px; font-weight: 600; align-self: center; }

.mobile-nav { display: none; }

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 58px auto 1fr;
  }
  .sidebar {
    display: none;
  }
  .mobile-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--sidebar);
  }
  .mobile-nav .nav-btn { width: auto; flex: none; white-space: nowrap; }
  .span-2 { grid-column: auto; }
  .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 16px 14px 40px; }
}
