:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #1f2937;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 16px;
  --nav-height: 68px;
}

* { 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, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(11, 17, 32, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.app-logo { width: 36px; height: 36px; border-radius: 10px; }
.topbar h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.2px; }
.subtitle { display: block; font-size: 11px; color: var(--text-muted); }

.live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
}
.live-pill.online { background: rgba(34, 197, 94, 0.14); color: var(--green); border: 1px solid rgba(34, 197, 94, 0.35); }
.live-pill.offline { background: rgba(239, 68, 68, 0.14); color: var(--red); border: 1px solid rgba(239, 68, 68, 0.35); }
.live-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.live-pill.online .dot { animation: pulse 1.6s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.main-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 14px 14px calc(var(--nav-height) + env(safe-area-inset-bottom) + 20px);
}

.tab-view { display: none; }
.tab-view.active { display: block; animation: fadeIn 0.16s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; text-align: center; }
.summary-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.summary-val { font-size: 22px; font-weight: 800; }
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }
.text-red { color: var(--red); }

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

/* Quick Actions Grid */
.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.action-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid #334155;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}
.action-tile:active { transform: scale(0.97); }
.action-tile span { font-size: 17px; }
.action-tile.danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

/* VPS Card */
.vps-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; cursor: pointer; transition: transform 0.12s;
}
.vps-card:active { transform: scale(0.99); }
.vps-card.offline { border-color: rgba(239, 68, 68, 0.45); opacity: 0.85; }
.vps-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.vps-name { margin: 0; font-size: 16px; font-weight: 700; }
.vps-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.status-badge { padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-badge.online { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.status-badge.offline { background: rgba(239, 68, 68, 0.15); color: var(--red); }

.metric-row { margin-bottom: 9px; }
.metric-top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }
.metric-label { color: var(--text-muted); }
.metric-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.progress-track { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.35s ease, background-color 0.25s ease; }
.fill-ok { background: linear-gradient(90deg, #0ea5e9, #38bdf8); }
.fill-warn { background: linear-gradient(90deg, #d97706, #f59e0b); }
.fill-danger { background: linear-gradient(90deg, #dc2626, #ef4444); }

.vps-net-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.net-speed { color: var(--text); font-weight: 600; }

/* Service Chips & Controls */
.svc-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.svc-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg);
}
.svc-chip.online { border-color: rgba(34, 197, 94, 0.35); color: var(--green); }
.svc-chip.error { border-color: rgba(245, 158, 11, 0.45); background: rgba(245, 158, 11, 0.12); color: var(--amber); }
.svc-chip.conflict, .svc-chip.down { border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.14); color: var(--red); }

.services-detail-list { display: flex; flex-direction: column; gap: 10px; }
.svc-row { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; }
.svc-row.conflict, .svc-row.down { border-color: rgba(239, 68, 68, 0.45); }
.svc-row.error { border-color: rgba(245, 158, 11, 0.45); }
.svc-row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.svc-row-name { font-weight: 700; font-size: 14px; }
.svc-row-meta { margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.svc-row-warn { margin-top: 6px; font-size: 12px; color: var(--red); word-break: break-word; }

.svc-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
}

.btn-mini {
  flex: 1;
  padding: 7px 8px;
  border-radius: 9px;
  border: 1px solid #334155;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-mini:active { transform: scale(0.96); }
.btn-mini.accent { border-color: rgba(56, 189, 248, 0.45); color: var(--accent); }
.btn-mini.danger { border-color: rgba(239, 68, 68, 0.45); color: #fca5a5; }
.btn-mini.success { border-color: rgba(34, 197, 94, 0.45); color: var(--green); }

/* Issues */
.issues-list { display: flex; flex-direction: column; gap: 8px; }
.issue-item {
  background: var(--bg); border: 1px solid var(--border); border-left: 3px solid var(--amber);
  border-radius: 10px; padding: 8px 10px; font-size: 12px;
}
.issue-item.conflict { border-left-color: var(--red); }
.issue-head { display: flex; justify-content: space-between; margin-bottom: 3px; font-weight: 700; }
.issue-msg { color: var(--text-muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; word-break: break-word; }

/* Charts */
.vps-pills { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 6px; scrollbar-width: none; }
.vps-pills::-webkit-scrollbar { display: none; }
.vps-pill {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); font-size: 13px; font-weight: 600; cursor: pointer;
}
.vps-pill.active { background: rgba(56, 189, 248, 0.16); border-color: var(--accent); color: var(--accent); }
.chart-wrap { position: relative; height: 190px; }
.badge-mono { font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent); }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.detail-item { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.detail-item span { display: block; font-size: 11px; color: var(--text-muted); }
.detail-item strong { font-size: 14px; font-weight: 700; }

/* Alerts */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-header h2 { margin: 0; font-size: 17px; }
.alert-item {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--amber);
  border-radius: 12px; padding: 12px; margin-bottom: 10px;
}
.alert-item.critical { border-left-color: var(--red); }
.alert-item.warning { border-left-color: var(--amber); }
.alert-item.recovery { border-left-color: var(--green); }
.alert-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.alert-title { font-weight: 700; font-size: 14px; }
.alert-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.alert-vps { font-size: 12px; color: var(--accent); margin-bottom: 4px; }
.alert-msg { font-size: 13px; color: var(--text-muted); }

/* Settings */
.hint { margin: 0 0 12px; font-size: 12.5px; color: var(--text-muted); }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 5px; }
.form-group input {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; outline: none;
}
.form-group input:focus { border-color: var(--accent); }
.field-hint { display: block; margin-top: 4px; font-size: 11.5px; color: var(--green); }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--surface-2); border-radius: 999px; cursor: pointer; transition: 0.2s; }
.slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.btn { border: none; border-radius: 12px; padding: 12px 16px; font-size: 14px; font-weight: 700; cursor: pointer; }
.btn-primary { background: var(--accent); color: #082f49; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid #334155; }
.btn-text-danger { background: none; border: none; color: var(--red); font-size: 13px; font-weight: 600; cursor: pointer; }
.full-width { width: 100%; }

.empty-state { text-align: center; padding: 40px 20px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty-icon { font-size: 36px; margin-bottom: 8px; }
.empty-state h3 { margin: 0 0 6px; font-size: 16px; }
.empty-state p { margin: 0; font-size: 13px; color: var(--text-muted); }

/* Bottom Nav */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(17, 24, 39, 0.94); backdrop-filter: blur(14px); border-top: 1px solid var(--border);
}
.nav-item {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; background: none; border: none; color: var(--text-muted); cursor: pointer;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 20px; }
.nav-label { font-size: 11px; font-weight: 600; }
.nav-badge {
  position: absolute; top: 7px; right: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--red); color: white; font-size: 10px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}

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

/* Modal Sheet (Logs & Top Output) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, 0.72);
  display: flex; align-items: flex-end; justify-content: center; padding: 12px;
}
.modal-sheet {
  width: 100%; max-width: 680px; max-height: 82vh;
  background: var(--surface); border: 1px solid #334155; border-radius: 20px;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 15px; }
.btn-icon {
  background: var(--surface-2); border: 1px solid #334155; color: var(--text);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-weight: 700;
}
.terminal-box {
  margin: 0; padding: 14px; background: #020617; color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; line-height: 1.5;
  overflow: auto; white-space: pre-wrap; word-break: break-word; flex: 1;
}

/* PIN Overlay */
.pin-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(11, 17, 32, 0.96);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.pin-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 24px; text-align: center;
}
.pin-icon { font-size: 36px; margin-bottom: 8px; }
.pin-card h2 { margin: 0 0 6px; }
.pin-card p { margin: 0 0 16px; font-size: 13px; color: var(--text-muted); }
.pin-card input {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 16px; text-align: center; margin-bottom: 12px;
}
.error-text { margin-top: 10px; color: var(--red); font-size: 13px; }
