:root {
  --ink: #070b12;
  --ink-2: #0b111c;
  --surface: rgba(20, 28, 42, 0.62);
  --surface-solid: #121a28;
  --line: rgba(120, 160, 200, 0.14);
  --line-strong: rgba(120, 160, 200, 0.28);
  --text: #dce6f2;
  --muted: #7b8aa3;
  --teal: #2ff0c6;
  --teal-dim: rgba(47, 240, 198, 0.16);
  --amber: #ffb454;
  --coral: #ff6b8a;
  --violet: #8b9dff;
  --green: #4fe08a;
  --red: #ff5d6c;
  --radius: 16px;
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.85);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 12% -8%, rgba(47, 240, 198, 0.10), transparent 60%),
    radial-gradient(900px 600px at 98% 4%, rgba(139, 157, 255, 0.10), transparent 55%),
    radial-gradient(700px 600px at 60% 120%, rgba(255, 107, 138, 0.07), transparent 60%),
    linear-gradient(180deg, var(--ink-2), var(--ink));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.hidden { display: none !important; }

.muted { color: var(--muted); }

h1, h2 { font-family: "Chakra Petch", sans-serif; letter-spacing: 0.02em; margin: 0; }

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(380px, 92vw);
  padding: 40px 36px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(24, 34, 52, 0.86), rgba(12, 18, 28, 0.92));
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  text-align: center;
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-mark, .brand-mark { display: inline-flex; gap: 5px; }
.login-mark { margin-bottom: 18px; }
.login-mark span, .brand-mark span {
  display: block;
  width: 8px;
  border-radius: 4px;
  background: var(--teal);
  box-shadow: 0 0 14px var(--teal-dim);
}
.login-mark span { height: 30px; animation: pulse 1.4s ease-in-out infinite; }
.login-mark span:nth-child(2) { height: 22px; animation-delay: 0.18s; background: var(--violet); }
.login-mark span:nth-child(3) { height: 36px; animation-delay: 0.36s; background: var(--amber); }

.login-panel h1 { font-size: 30px; font-weight: 700; }
.login-panel h1 em { font-style: normal; color: var(--teal); margin-left: 6px; }
.login-sub { color: var(--muted); margin: 6px 0 26px; font-size: 13px; letter-spacing: 0.18em; text-transform: uppercase; }

.login-panel label {
  display: block;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  margin-bottom: 8px;
}

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: rgba(7, 11, 18, 0.7);
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
input:focus, textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-dim);
}

.login-panel button[type="submit"] {
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  border: 0;
  border-radius: 11px;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #04130f;
  background: linear-gradient(120deg, var(--teal), #6ef0d8);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}
.login-panel button[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px -10px rgba(47, 240, 198, 0.6);
}

.error-text { color: var(--red); font-size: 13px; margin: 14px 0 0; min-height: 18px; }

/* ---------- App shell ---------- */
.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 26px clamp(16px, 4vw, 38px) 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { align-items: flex-end; }
.brand-mark span { width: 5px; }
.brand-mark span:nth-child(1) { height: 16px; }
.brand-mark span:nth-child(2) { height: 26px; background: var(--violet); }
.brand-mark span:nth-child(3) { height: 20px; background: var(--amber); }
.brand h1 { font-size: 22px; font-weight: 600; }
.brand p { margin: 2px 0 0; font-size: 12px; font-family: "IBM Plex Mono", monospace; }

.top-actions { display: flex; align-items: center; gap: 12px; }

.status-pill {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 14px 6px 26px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  position: relative;
  white-space: nowrap;
}
.status-pill::before {
  content: "";
  position: absolute;
  left: 12px; top: 50%;
  width: 7px; height: 7px;
  margin-top: -3.5px;
  border-radius: 50%;
  background: var(--muted);
}
.status-pill.online { color: var(--teal); border-color: rgba(47, 240, 198, 0.4); }
.status-pill.online::before {
  background: var(--teal);
  box-shadow: 0 0 0 0 rgba(47, 240, 198, 0.55);
  animation: ping 1.8s ease-out infinite;
}

.ghost-btn, .primary-btn {
  font: inherit;
  font-size: 13px;
  padding: 9px 15px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: rgba(20, 30, 46, 0.6);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, transform 0.12s, color 0.15s;
}
.ghost-btn:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); }
.ghost-btn:active:not(:disabled) { transform: translateY(1px); }
.ghost-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ghost-btn.danger:hover:not(:disabled) { border-color: var(--red); color: var(--red); }
.primary-btn {
  border: 0;
  color: #04130f;
  background: linear-gradient(120deg, var(--teal), #6ef0d8);
  font-weight: 600;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; margin: 22px 0; }
.tab {
  font-family: "Chakra Petch", sans-serif;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--teal);
  background: var(--teal-dim);
  border-color: rgba(47, 240, 198, 0.32);
}

/* ---------- Cards ---------- */
.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(12px);
  padding: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.card-head h2 {
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.chip {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  white-space: nowrap;
}

.big-pct {
  font-family: "Chakra Petch", sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.detail { font-family: "IBM Plex Mono", monospace; font-size: 12px; margin: 12px 0 0; line-height: 1.5; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* CPU gauge */
.gauge-wrap { position: relative; width: 150px; height: 150px; margin: 4px auto 6px; }
.gauge { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge circle { fill: none; stroke-width: 9; stroke-linecap: round; }
.gauge-track { stroke: rgba(120, 160, 200, 0.12); }
.gauge-fill {
  stroke: var(--teal);
  stroke-dasharray: 377;
  stroke-dashoffset: 377;
  filter: drop-shadow(0 0 6px rgba(47, 240, 198, 0.55));
  transition: stroke-dashoffset 0.6s cubic-bezier(0.16, 1, 0.3, 1), stroke 0.4s;
}
.gauge-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.gauge-center strong {
  font-family: "Chakra Petch", sans-serif;
  font-size: 34px; font-weight: 700;
  line-height: 1;
}
.gauge-center small {
  font-size: 9px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--muted);
  margin-top: 6px;
}

.spark { width: 100%; display: block; margin-top: 12px; }
.net-spark { margin-top: 4px; }

/* Memory meter */
.meter {
  height: 12px;
  border-radius: 999px;
  background: rgba(7, 11, 18, 0.75);
  border: 1px solid var(--line);
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--violet));
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1), background 0.4s;
}
.meter span.warn { background: linear-gradient(90deg, var(--amber), var(--coral)); }
.meter span.crit { background: linear-gradient(90deg, var(--coral), var(--red)); }

/* Network tags */
.net-lines { display: flex; gap: 18px; margin-top: 12px; font-family: "IBM Plex Mono", monospace; font-size: 12px; }
.net-tag { display: inline-flex; align-items: center; gap: 7px; }
.net-tag i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.net-tag.down i { background: var(--teal); box-shadow: 0 0 8px var(--teal-dim); }
.net-tag.up i { background: var(--coral); box-shadow: 0 0 8px rgba(255, 107, 138, 0.3); }

/* ---------- Split grid ---------- */
.split-grid {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 18px;
  margin-top: 18px;
}

.disk-list { display: flex; flex-direction: column; gap: 16px; }
.disk-item header {
  display: flex; align-items: baseline; justify-content: space-between;
  font-family: "IBM Plex Mono", monospace; font-size: 12px;
}
.disk-item header strong { font-family: "Chakra Petch", sans-serif; font-size: 13px; letter-spacing: 0.02em; }
.disk-item header span { color: var(--muted); }
.disk-item .meter { margin: 7px 0; }
.disk-item .meter span { background: linear-gradient(90deg, var(--teal), var(--violet)); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
}
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(120, 160, 200, 0.07);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px;
}
.data-table tbody tr { transition: background 0.12s; }
.data-table tbody tr:hover { background: rgba(47, 240, 198, 0.05); }
.data-table .muted { font-size: 11px; }

.state {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
}
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.state.online { color: var(--green); }
.state.online::before { background: var(--green); box-shadow: 0 0 8px rgba(79, 224, 138, 0.6); }
.state.stopped, .state.errored { color: var(--red); }
.state.stopped::before, .state.errored::before { background: var(--red); }

.usebar {
  display: block; height: 4px; border-radius: 3px; margin-top: 5px;
  background: rgba(7, 11, 18, 0.7);
  overflow: hidden;
}
.usebar i { display: block; height: 100%; background: var(--teal); border-radius: 3px; }

/* ---------- Files ---------- */
.file-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 18px;
}
.toolbar-spacer { flex: 1; }
.upload-button { position: relative; overflow: hidden; display: inline-flex; align-items: center; }
.upload-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.file-layout { display: grid; grid-template-columns: 1fr 290px; gap: 18px; align-items: start; }
.file-path {
  display: flex; gap: 8px; align-items: baseline;
  font-family: "IBM Plex Mono", monospace; font-size: 12px;
  padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.file-path strong { color: var(--teal); }
.file-message { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--muted); min-height: 18px; padding: 8px 0; }
.file-message.error { color: var(--red); }
.file-table-wrap { max-height: 60vh; overflow: auto; }
.file-row { cursor: pointer; }
.file-row.selected { background: var(--teal-dim) !important; }
.file-name { color: var(--text); }

.detail-panel h2 { font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
.selected-name { font-family: "Chakra Petch", sans-serif; font-size: 16px; word-break: break-all; margin: 0 0 14px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-panel dl { margin: 0; display: grid; gap: 4px; }
.detail-panel dt { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-top: 10px; }
.detail-panel dd { margin: 0; font-family: "IBM Plex Mono", monospace; font-size: 12px; word-break: break-all; }

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
  max-width: 92vw;
}
dialog::backdrop { background: rgba(4, 7, 12, 0.72); backdrop-filter: blur(3px); }
dialog form { padding: 24px; }
dialog h2 { font-size: 16px; margin-bottom: 16px; }
dialog label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); margin-bottom: 8px; }
dialog menu { display: flex; justify-content: flex-end; gap: 10px; margin: 20px 0 0; padding: 0; }
.editor-dialog form { width: min(760px, 92vw); }
.editor-dialog textarea { min-height: 52vh; font-family: "IBM Plex Mono", monospace; font-size: 13px; resize: vertical; }

/* ---------- Animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { transform: scaleY(0.7); opacity: 0.6; } 50% { transform: scaleY(1); opacity: 1; } }
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(47, 240, 198, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(47, 240, 198, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 240, 198, 0); }
}

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: 1fr; }
  .split-grid { grid-template-columns: 1fr; }
  .file-layout { grid-template-columns: 1fr; }
}

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

/* ---------- Backup ---------- */
.backup-actions { display: flex; gap: 0.4rem; justify-content: flex-end; flex-wrap: wrap; }
.backup-actions .ghost-btn { padding: 0.3rem 0.7rem; }
#backupView code { font-family: "IBM Plex Mono", monospace; font-size: 0.85em; padding: 0.05rem 0.3rem; border-radius: 4px; background: rgba(255, 255, 255, 0.06); }
