:root {
  --bg: #0f1419;
  --bg-elevated: #171d25;
  --bg-soft: #1c2430;
  --border: #2a3441;
  --text: #e7ecf3;
  --muted: #8b97a8;
  --accent: #2f9e7b;
  --accent-hover: #3bb891;
  --danger: #c45c5c;
  --warn: #d2a24a;
  --info: #4e8fd9;
  --radius: 10px;
  --font: "IBM Plex Sans", "Source Han Sans SC", "Noto Sans SC", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a2a28 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a2233 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent-hover); text-decoration: none; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--accent);
  color: #04140f;
  font-weight: 600;
  border-radius: 8px;
  padding: 0.55rem 1rem;
}
button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 12px;
}
.field { margin-bottom: 0.9rem; }
.help { color: var(--muted); font-size: 12px; margin-top: 0.25rem; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(400px, 100%);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}
.login-card p { margin: 0 0 1.5rem; color: var(--muted); }

.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.sidebar {
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.brand {
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.05rem;
  padding: 0.5rem 0.65rem 1rem;
}
.brand small {
  display: block;
  color: var(--muted);
  font-weight: 400;
  margin-top: 0.2rem;
  font-size: 11px;
}
.nav-btn {
  text-align: left;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-weight: 500;
}
.nav-btn.active, .nav-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.sidebar .spacer { flex: 1; }
.main {
  padding: 1.5rem 1.75rem 2.5rem;
  max-width: 1100px;
}
.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.page-title h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.muted { color: var(--muted); }
.grid-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat .n {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.panel h3 {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  text-align: left;
  padding: 0.65rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}
.badge.ok { border-color: #2f9e7b55; color: #7ddec1; }
.badge.warn { border-color: #d2a24a55; color: #e6c07b; }
.badge.planned { border-color: #4e8fd955; color: #8eb7e8; }
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.row-actions button { padding: 0.35rem 0.65rem; font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.error {
  color: #ffb4b4;
  background: #3a1d1d;
  border: 1px solid #6a3030;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.85rem;
}
.msg-list { display: flex; flex-direction: column; gap: 0.65rem; max-height: 60vh; overflow: auto; }
.msg {
  max-width: 80%;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; background: #16352d; border-color: #2f9e7b44; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 0.25rem; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
}
.form-grid .full { grid-column: 1 / -1; }
.hidden { display: none !important; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar .spacer { display: none; }
  .grid-stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 1rem; }
}
