@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  color-scheme: dark;
  --background: #09090b;
  --foreground: #fafafa;
  --card: #0a0a0c;
  --card-foreground: #fafafa;
  --popover: #0f0f12;
  --border: #27272a;
  --input: #27272a;
  --ring: #d4d4d8;
  --muted: #18181b;
  --muted-foreground: #a1a1aa;
  --primary: #fafafa;
  --primary-foreground: #18181b;
  --secondary: #1f1f23;
  --secondary-foreground: #fafafa;
  --accent-hover: #1f1f23;
  --destructive: #dc2626;
  --destructive-foreground: #fef2f2;
  --success: #22c55e;
  --warning: #eab308;
  --radius: 0.625rem;
  --radius-md: calc(var(--radius) - 2px);
  --radius-sm: calc(var(--radius) - 4px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
svg { display: block; flex-shrink: 0; }
.icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
::selection { background: rgba(255,255,255,.15); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ================= login ================= */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(600px circle at 50% 0%, rgba(255,255,255,.05), transparent 60%),
    var(--background);
}
.login-card {
  width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.login-card h1 { font-size: 16px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
.login-card .sub { color: var(--muted-foreground); font-size: 13px; margin-bottom: 24px; }
.login-card .field { margin-bottom: 14px; }
.login-card button { width: 100%; margin-top: 4px; }
.login-card .err { color: var(--destructive); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* ================= shell ================= */
#app-view { display: flex; height: 100vh; width: 100%; overflow: hidden; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 18px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -.01em;
}
.brand .status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(34,197,94,.15); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted-foreground);
  user-select: none;
}
.nav-item .icon { color: var(--muted-foreground); }
.nav-item:hover { background: var(--secondary); color: var(--foreground); }
.nav-item:hover .icon { color: var(--foreground); }
.nav-item.active { background: var(--secondary); color: var(--foreground); }
.nav-item.active .icon { color: var(--foreground); }
.sidebar .spacer { flex: 1; }
.sidebar .divider { height: 1px; background: var(--border); margin: 8px 4px; }

.main { flex: 1; overflow-y: auto; }
.main-inner { padding: 28px 40px 80px; max-width: 1180px; }
.page { display: none; }
.page.active { display: block; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0 0 4px; font-size: 20px; font-weight: 600; letter-spacing: -.015em; }
.page-head .sub { color: var(--muted-foreground); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
}
.card h3 { font-size: 14px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
.card .card-desc { font-size: 12.5px; color: var(--muted-foreground); margin: 0 0 16px; }
.card-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-actions { display: flex; gap: 8px; align-items: center; }

/* ================= buttons ================= */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--primary);
  color: var(--primary-foreground);
  transition: opacity .1s, background-color .1s;
  white-space: nowrap;
}
button:hover { opacity: .88; }
button:active { opacity: .75; }
button:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: not-allowed; }
button .icon { width: 14px; height: 14px; }

button.secondary { background: var(--secondary); color: var(--secondary-foreground); }
button.outline { background: transparent; border-color: var(--border); color: var(--foreground); }
button.outline:hover { background: var(--secondary); opacity: 1; }
button.ghost { background: transparent; color: var(--foreground); }
button.ghost:hover { background: var(--secondary); opacity: 1; }
button.destructive { background: var(--destructive); color: var(--destructive-foreground); }
button.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }

/* ================= inputs ================= */
input[type=text], input[type=password], input[type=number], input[type=file], textarea {
  width: 100%;
  height: 34px;
  background: transparent;
  border: 1px solid var(--input);
  color: var(--foreground);
  padding: 0 11px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
}
input::placeholder, textarea::placeholder { color: var(--muted-foreground); }
input:focus, textarea:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px rgba(212,212,216,.1); }
input[type=file] { padding: 6px 8px; font-size: 12.5px; line-height: 20px; }
textarea {
  height: auto;
  padding: 10px 11px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  resize: vertical;
}
label { display: block; font-size: 12.5px; font-weight: 500; color: var(--foreground); margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.hint { font-size: 11.5px; color: var(--muted-foreground); margin-top: 5px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }

/* ================= custom select ================= */
.select { position: relative; }
.select-trigger {
  width: 100%;
  height: 34px;
  background: transparent;
  border: 1px solid var(--input);
  color: var(--foreground);
  border-radius: var(--radius-md);
  padding: 0 11px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.select-trigger:hover { background: var(--secondary); }
.select-trigger .icon { color: var(--muted-foreground); transition: transform .12s; }
.select.open .select-trigger .icon { transform: rotate(180deg); }
.select-content {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--popover);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.select-content.hidden { display: none; }
.select-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  color: var(--foreground);
}
.select-item:hover { background: var(--secondary); }
.select-item .icon { color: var(--foreground); opacity: 0; width: 14px; height: 14px; }
.select-item.selected .icon { opacity: 1; }

/* ================= custom checkbox ================= */
.checkbox-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.checkbox-row label { margin: 0; font-weight: 400; cursor: pointer; }
.checkbox {
  width: 18px; height: 18px;
  border-radius: 5px;
  border: 1px solid var(--input);
  background: transparent;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.checkbox .icon { width: 12px; height: 12px; color: var(--primary-foreground); opacity: 0; stroke-width: 3; }
.checkbox[aria-checked="true"] { background: var(--primary); border-color: var(--primary); }
.checkbox[aria-checked="true"] .icon { opacity: 1; }

/* ================= status pill ================= */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border);
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.online { color: var(--success); }
.pill.offline { color: var(--destructive); }
.pill.unknown { color: var(--warning); }

/* ================= stats ================= */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.stat-box { background: var(--card); padding: 14px 16px; }
.stat-box .label { font-size: 11.5px; color: var(--muted-foreground); margin-bottom: 6px; }
.stat-box .value { font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.bar { height: 5px; border-radius: 4px; background: var(--secondary); overflow: hidden; margin-top: 9px; }
.bar > div { height: 100%; background: var(--foreground); }

/* ================= table ================= */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted-foreground); font-weight: 500; font-size: 12px; }
tr:last-child td { border-bottom: none; }

/* ================= logs ================= */
pre#logs {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  max-height: 520px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  font-family: "Cascadia Code", Consolas, monospace;
  margin: 0;
}

/* ================= toast ================= */
.toast-wrap { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast {
  background: var(--popover); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 11px 14px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  min-width: 260px; max-width: 340px;
  display: flex; align-items: center; gap: 9px;
  animation: slidein .15s ease-out;
}
.toast .icon { flex-shrink: 0; }
.toast.ok .icon { color: var(--success); }
.toast.err .icon { color: var(--destructive); }
@keyframes slidein { from { transform: translateY(6px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ================= modal ================= */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; width: 380px; box-shadow: 0 16px 48px rgba(0,0,0,.6);
}
.modal h4 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.modal p { color: var(--muted-foreground); font-size: 13px; line-height: 1.55; margin: 0 0 18px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; }

.hidden { display: none !important; }
.file-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.file-row input[type=file] { flex: 1; min-width: 200px; }
.file-row input[type=number] { width: 90px; flex-shrink: 0; }
code { background: var(--muted); padding: 1px 6px; border-radius: 4px; font-size: 12px; font-family: "Cascadia Code", Consolas, monospace; }

@media (max-width: 860px) {
  #app-view { flex-direction: column; height: auto; overflow: visible; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; height: auto; padding: 10px; }
  .sidebar .spacer, .sidebar .divider, .brand { display: none; }
  .main { overflow: visible; }
  .main-inner { padding: 20px; }
}
