:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #263244;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #0ea5e9;
  --primary-2: #0284c7;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12.5px; }
.error-text { color: #fca5a5; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* Login */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
}
.login-logo {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, #0f766e, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card input {
  width: 100%;
  margin: 16px 0 12px;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  text-align: center;
  letter-spacing: 4px;
}

/* App Shell */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px)) 10px calc(14px + env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-left strong { display: block; font-size: 16px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  min-width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
}

.main-content {
  padding: 14px calc(14px + env(safe-area-inset-right, 0px)) 14px calc(14px + env(safe-area-inset-left, 0px));
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.tab-view { display: none; }
.tab-view.active { display: block; }

/* Cards & KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
}
.kpi-card.highlight { border-color: rgba(14, 165, 233, 0.45); background: linear-gradient(180deg, rgba(14,165,233,0.12), var(--surface)); }
.kpi-label { font-size: 12px; color: var(--muted); display: block; }
.kpi-val { font-size: 24px; display: block; margin: 2px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-head h2 { margin: 0; font-size: 15.5px; }

/* Daemons */
.daemon-list { display: grid; gap: 8px; }
.daemon-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 9px 12px;
}
.daemon-name { font-weight: 600; font-size: 13.5px; display: block; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok { background: rgba(16, 185, 129, 0.16); color: #34d399; }
.badge.warn { background: rgba(245, 158, 11, 0.16); color: #fbbf24; }
.badge.danger { background: rgba(239, 68, 68, 0.16); color: #f87171; }
.badge.info { background: rgba(14, 165, 233, 0.16); color: #38bdf8; }
.badge.neutral { background: var(--surface-2); color: var(--muted); }

/* Buttons */
.btn {
  min-height: 42px;
  padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.full { width: 100%; }
.btn.primary { background: var(--primary-2); }
.btn.ok { background: #059669; }
.btn.secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.warn { background: #b45309; }
.btn.danger { background: #b91c1c; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.pc-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.full-span { grid-column: 1 / -1; }

.screenshot-box {
  margin-top: 12px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.screenshot-box img { width: 100%; display: block; }

/* Pills & Search */
.pill-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 2px;
}
.pill {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.pill.active {
  background: var(--primary-2);
  border-color: var(--primary);
  color: #fff;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.search-row input, .ai-form select, .ai-form textarea, .modal-edit-box textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

/* Stack list items */
.stack-list { display: grid; gap: 10px; }
.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px;
}
.item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.item-title { font-weight: 700; font-size: 14.5px; word-break: break-word; }
.item-meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.item-actions .btn { min-height: 36px; padding: 6px 12px; font-size: 13px; }

/* AI form */
.ai-form { display: grid; gap: 8px; }
.ai-form label { font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav-item {
  position: relative;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}
.nav-item.active { color: var(--primary); }
.nav-ico { font-size: 18px; }
.nav-badge {
  position: absolute;
  top: 0;
  right: 22%;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(2, 6, 23, 0.78);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  width: 100%;
  max-width: 760px;
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 16px);
  background: var(--surface);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.modal-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal-head strong { display: block; font-size: 15px; }
.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
  font-size: 14px;
}
.modal-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  margin: 0;
  background: var(--bg);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.pdf-page-img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
  background: #fff;
}
.doc-table-wrap { overflow-x: auto; margin: 8px 0; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.doc-table th, .doc-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.doc-table th { background: var(--surface-2); }

.modal-edit-box {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.modal-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.modal-footer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.modal-footer .btn { flex: 1; }

/* Toast */
.toast {
  position: fixed;
  top: calc(70px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #334155;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
  max-width: 90vw;
  text-align: center;
}
