:root {
  color-scheme: dark;
  --canvas: #0d0f12;
  --surface: #15181e;
  --surface-raised: #1c2028;
  --border: #262b35;
  --border-strong: #373f4d;
  --text: #eceef2;
  --muted: #98a2b3;
  --accent: #e07a2f;
  --accent-hover: #c96821;
  --ok: #38b27b;
  --err: #e05a5a;
  --warn: #e0a838;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--canvas);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

.hidden { display: none !important; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; }
code { color: #d5dae2; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Dark theme autofill preservation */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:autofill {
  -webkit-text-fill-color: var(--text) !important;
  -webkit-box-shadow: 0 0 0 1000px var(--canvas) inset !important;
  box-shadow: 0 0 0 1000px var(--canvas) inset !important;
  caret-color: var(--text) !important;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-box { width: 100%; max-width: 380px; padding: 1.75rem; }
.login-head { margin-bottom: 1.25rem; }
.login-head h1 { margin: 0 0 0.25rem; font-size: 1.5rem; letter-spacing: -0.02em; }

/* App Shell */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 1.25rem;
}

.brand-block {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
}
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; color: var(--text); }
.brand-meta { font-size: 0.8rem; color: var(--muted); }

.node-picker label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.nav-list { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 40px;
  padding: 0 0.75rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  transition: background-color 0.12s, color 0.12s;
}
.nav-btn:hover { background: var(--surface-raised); color: var(--text); }
.nav-btn.active {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--border-strong);
  border-left: 2px solid var(--accent);
}
.nav-ico { width: 18px; height: 18px; flex-shrink: 0; }
.nav-num { margin-left: auto; font-size: 0.8rem; font-variant-numeric: tabular-nums; color: var(--muted); }

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.sidebar-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mobile-header { display: none; }
.main-inner { padding: 1.5rem 2rem; max-width: 1420px; width: 100%; }

.view-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.view-head h2 { margin: 0 0 0.2rem; font-size: 1.35rem; letter-spacing: -0.02em; }
.view-head p { margin: 0; }
.head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Panels & Asymmetric Grids */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
}
.panel-title-row h3 { margin: 0; font-size: 1rem; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  margin-bottom: 1.25rem;
}
.metric-cell {
  padding: 0.9rem 1.1rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.metric-label { font-size: 0.78rem; color: var(--muted); }
.metric-val { font-size: 1.3rem; font-weight: 600; margin-top: 0.15rem; font-variant-numeric: tabular-nums; }

.asymmetric-grid {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: 1rem;
}

/* Unified Master-Detail Apps Container */
.empty-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 3rem 1.5rem;
}
.empty-panel p { margin: 0; }

.apps-split {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  min-height: 460px;
}
.apps-list-col {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.apps-col-head {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.apps-list { display: flex; flex-direction: column; }
.app-row-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.app-row-btn:hover { background: var(--surface-raised); }
.app-row-btn.active { border-left-color: var(--accent); background: var(--surface-raised); }
.app-row-sub { font-size: 0.78rem; color: var(--muted); }
.apps-detail-col { padding: 1.25rem 1.5rem; }

/* Toolbars & Segmented Controls */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}
.prefix-bar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.prefix-bar input[type="text"] { width: 165px; }
.inline-check { display: inline-flex; flex-direction: row; align-items: center; gap: 0.4rem; margin: 0; color: var(--text); cursor: pointer; }

.segmented {
  display: inline-flex;
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 2px;
}
.seg-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface-raised); color: var(--text); }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 0.75rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th { color: var(--muted); font-size: 0.78rem; font-weight: 600; }
tbody tr:hover { background: var(--surface-raised); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.actions-col, td.actions-col { text-align: right; white-space: nowrap; }

/* Direct Semantic States */
.state-ok { color: var(--ok); font-weight: 600; font-size: 0.85rem; }
.state-err { color: var(--err); font-weight: 600; font-size: 0.85rem; }
.state-warn { color: var(--warn); font-weight: 600; font-size: 0.85rem; }
.state-muted { color: var(--muted); font-size: 0.85rem; }

/* Forms & Inputs */
label { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.85rem; color: var(--muted); font-size: 0.85rem; }
input, select, textarea {
  min-height: 40px;
  background: var(--canvas);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
input[type="checkbox"] { min-height: auto; width: 16px; height: 16px; accent-color: var(--accent); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.25rem 1rem; }
.checkbox-row { display: flex; gap: 1.5rem; flex-wrap: wrap; margin: 0.5rem 0 1.25rem; }
.checkbox-row label { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--text); margin-bottom: 0; cursor: pointer; }
.form-actions { display: flex; gap: 0.6rem; justify-content: flex-end; flex-wrap: wrap; }

/* Sharp Technical Buttons */
.btn {
  min-height: 40px;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  padding: 0 0.95rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.btn:hover { background: #262c37; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d0f12; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--surface-raised); border-color: #6b2929; color: var(--err); }
.btn.danger:hover { background: #361818; }
.btn.sm { min-height: 32px; padding: 0 0.65rem; font-size: 0.8rem; }
.btn.full { width: 100%; }
.btn.icon-circle { width: 34px; height: 34px; min-height: 34px; padding: 0; border-radius: 9999px; }

.muted { color: var(--muted); }
.error-line { color: var(--err); margin-bottom: 0.75rem; min-height: 1.2rem; font-size: 0.85rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--surface-raised);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.75rem 1.1rem;
  border-radius: 2px;
  z-index: 100;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}
.modal { width: 100%; max-width: 680px; max-height: 85vh; overflow-y: auto; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding-top: 0.85rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
}
pre.logs {
  background: var(--canvas);
  border: 1px solid var(--border);
  padding: 0.85rem;
  border-radius: 2px;
  overflow-x: auto;
  max-height: 420px;
  font-size: 0.8rem;
  line-height: 1.45;
  margin: 0;
}

@media (max-width: 900px) {
  .asymmetric-grid, .apps-split { grid-template-columns: 1fr; }
  .apps-list-col { border-right: none; border-bottom: 1px solid var(--border); }
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 60;
    transition: left 0.18s ease-out;
  }
  .sidebar.open { left: 0; }
  .mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .main-inner { padding: 1rem; }
  input, select, textarea { font-size: 16px !important; min-height: 44px; }
  .btn { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
