:root {
  --bg: #0c1014;
  --panel: #12181f;
  --panel-2: #171e27;
  --line: #243040;
  --line-soft: #1c2632;
  --text: #e6edf5;
  --muted: #7f8fa3;
  --accent: #3ecf9a;
  --accent-dim: #249e74;
  --danger: #e06c75;
  --ok: #6bcf8e;
  --sidebar: 248px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --r: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.4;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.brand {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
}
.error { color: var(--danger); }
.ok { color: var(--ok); }

button, input {
  font: inherit;
  color: inherit;
}
button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  line-height: 1.2;
}
button:hover { border-color: #35506a; }
button.primary {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #062218;
  font-weight: 600;
}
button.ghost, .icon-btn {
  background: transparent;
  border-color: transparent;
  padding: 0.3rem 0.45rem;
}
button.ghost:hover, .icon-btn:hover {
  background: var(--panel-2);
  border-color: var(--line);
}
.icon-btn { color: var(--muted); }

label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 12px;
}
input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
}
input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

/* Login */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(700px 400px at 20% 0%, #14261f 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.1rem;
  display: grid;
  gap: 0.65rem;
}
.login-card h1 { margin: 0; font-size: 1.25rem; }

/* Shell */
.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem 0.6rem;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  padding: 0.15rem 0.35rem;
}
.sidebar-head .meta {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
}
.sidebar-close { display: none; }
.sidebar-search {
  margin: 0 0.2rem;
  padding: 0.4rem 0.55rem;
  font-size: 12.5px;
}
.sidebar-nav {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.1rem;
}
.sidebar-foot {
  border-top: 1px solid var(--line-soft);
  padding-top: 0.4rem;
  display: grid;
  gap: 0.1rem;
}

.nav-parent, .nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.38rem 0.5rem;
  color: var(--muted);
}
.nav-parent {
  font-weight: 600;
  color: var(--text);
  font-size: 12.5px;
}
.nav-parent .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}
.nav-parent .chev {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  transition: transform 0.12s ease;
}
.nav-parent.open .chev { transform: rotate(90deg); color: var(--accent); }
.nav-parent:hover, .nav-item:hover {
  background: var(--panel-2);
  color: var(--text);
}
.nav-parent.active, .nav-item.active {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-2));
  border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
  color: var(--accent);
}
.nav-item.danger:hover { color: var(--danger); border-color: #5a3036; }

.nav-children {
  display: none;
  flex-direction: column;
  gap: 0.05rem;
  margin: 0 0 0.25rem 0.55rem;
  padding-left: 0.45rem;
  border-left: 1px solid var(--line);
}
.nav-children.open { display: flex; }
.nav-children .nav-item {
  font-size: 12.5px;
  padding: 0.32rem 0.5rem;
}

.content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(180deg, #10161c 0%, var(--bg) 180px);
}
.content-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line-soft);
  min-height: 52px;
}
.title-wrap { min-width: 0; flex: 1; }
.content-top h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.content-top .sub {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }
.menu-btn { display: none; }
.main-panel {
  flex: 1;
  overflow: auto;
  padding: 0.85rem 1rem 1.4rem;
}

/* Compact surfaces */
.stack { display: grid; gap: 0.55rem; }
.grid-svc {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.5rem;
}
.sec {
  display: grid;
  gap: 0.4rem;
}
.sec-h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.35rem;
}
.sec-h h2 {
  margin: 0;
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
}
.sec-h .hint { color: var(--muted); font-size: 11px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.panel-pad { padding: 0.7rem 0.8rem; }

.svc-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  background: transparent;
  width: 100%;
  text-align: left;
  border-left: none;
  border-right: none;
  border-top: none;
  border-radius: 0;
}
.svc-row:last-child { border-bottom: none; }
.svc-row:hover { background: var(--panel-2); }
.svc-row strong { display: block; font-size: 13px; font-weight: 600; }
.svc-row .url {
  margin-top: 0.12rem;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}
.svc-row .ports {
  margin-top: 0.2rem;
  font-family: var(--mono);
  font-size: 10.5px;
  color: #6d829a;
}
.svc-row .actions { display: flex; gap: 0.3rem; }

/* Detail */
.detail-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: space-between;
  align-items: start;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-2);
}
.detail-head h2 {
  margin: 0;
  font-size: 1rem;
}
.detail-head .note {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 12px;
  max-width: 52ch;
}
.kv {
  width: 100%;
  border-collapse: collapse;
}
.kv tr + tr td, .kv tr + tr th {
  border-top: 1px solid var(--line-soft);
}
.kv th, .kv td {
  padding: 0.38rem 0.75rem;
  text-align: left;
  vertical-align: middle;
  font-size: 12.5px;
}
.kv th {
  width: 132px;
  color: var(--muted);
  font-weight: 500;
  background: color-mix(in srgb, var(--panel-2) 55%, transparent);
}
.kv td {
  font-family: var(--mono);
  font-size: 12px;
}
.kv .cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.kv .cell span {
  word-break: break-all;
  min-width: 0;
}
.btn-xs {
  padding: 0.18rem 0.4rem;
  font-size: 11px;
  flex-shrink: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.55rem 0.75rem 0.15rem;
}
.chip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: #9db0c4;
}

.cred-grid {
  display: grid;
  gap: 0;
}
.cred {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--line-soft);
}
.cred:first-child { border-top: none; }
.cred .label { font-weight: 600; font-size: 12.5px; }
.cred .extra { color: var(--muted); font-size: 11px; margin-top: 0.1rem; }
.cred .fields { display: grid; gap: 0.15rem; min-width: 0; }
.cred .field {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 11.5px;
}
.cred .field .k { color: var(--muted); }
.cred .field .v { word-break: break-all; }
.cred .field .v.masked { letter-spacing: 0.1em; }
.cred .ops { display: flex; gap: 0.25rem; flex-wrap: wrap; justify-content: end; }

.env-block + .env-block { border-top: 1px solid var(--line); }
.env-block .env-title {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
}
.env-block .env-title strong { font-weight: 600; }
.env-row {
  display: grid;
  grid-template-columns: minmax(110px, 190px) 1fr auto;
  gap: 0.4rem;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-top: 1px solid var(--line-soft);
}
.env-row:first-of-type { border-top: none; }
.env-row code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
}
.env-row input {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 0.3rem 0.45rem;
}

.empty {
  padding: 1.2rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--r);
}
.settings-card {
  max-width: 380px;
  display: grid;
  gap: 0.55rem;
  padding: 0.85rem;
}
.note-box {
  margin-top: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1px dashed var(--line);
  border-radius: var(--r);
  color: var(--muted);
  font-size: 12px;
  max-width: 520px;
}

.cat-block { margin-bottom: 0.75rem; }
.cat-block > .sec-h { margin-bottom: 0.35rem; }

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}
.file-btn {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
}
.file-btn:hover { border-color: #35506a; }
.backup-list { display: grid; gap: 0.45rem; }
.backup-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
}
.backup-row .actions { display: flex; flex-wrap: wrap; gap: 0.3rem; }
button.danger, .nav-item.danger { color: var(--danger); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 15;
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar), 86vw);
    z-index: 20;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
  }
  .app-shell.sidebar-open .sidebar { transform: none; }
  .app-shell.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar-close, .menu-btn { display: inline-flex; }
  .cred { grid-template-columns: 1fr; }
  .env-row { grid-template-columns: 1fr; }
  .svc-row { grid-template-columns: 1fr; }
  .kv th { width: 96px; }
}
