:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #182230;
  --border: #232f3f;
  --text: #e6edf3;
  --text-dim: #8b98a8;
  --accent: #4da3ff;
  --up: #33d17a;
  --down: #f5566d;
  --warn: #f5c542;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(11,15,20,0.9);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 600; }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--down);
  box-shadow: 0 0 0 3px rgba(245,86,109,0.15);
  transition: background .3s, box-shadow .3s;
}
.dot.connected {
  background: var(--up);
  box-shadow: 0 0 0 3px rgba(51,209,122,0.15);
}

.topbar-meta { color: var(--text-dim); font-size: 13px; }

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: 15px; font-weight: 600; color: var(--text-dim); margin: 0; text-transform: uppercase; letter-spacing: .04em; }

.btn-add, .btn-primary {
  background: var(--accent);
  color: #06121f;
  border: none;
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.btn-add:hover, .btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: relative;
}

.card-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.card-title strong { font-size: 14px; }
.card-sub { color: var(--text-dim); font-size: 12px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}
.badge.up { background: rgba(51,209,122,0.15); color: var(--up); }
.badge.down { background: rgba(245,86,109,0.15); color: var(--down); }
.badge.unknown { background: rgba(245,197,66,0.15); color: var(--warn); }

.metric-row { display: flex; justify-content: space-between; font-size: 13px; margin: 4px 0; color: var(--text-dim); }
.metric-row span.val { color: var(--text); font-weight: 600; }

.bar-track { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.danger { background: var(--down); }

.card-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  opacity: 0.5;
}
.card-delete:hover { opacity: 1; color: var(--down); }

.empty-hint {
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
}

/* Alerts */
.alert-log {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.alert-log li {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.alert-log li.down { border-left: 3px solid var(--down); }
.alert-log li.recovered { border-left: 3px solid var(--up); }
.alert-time { color: var(--text-dim); font-size: 11px; white-space: nowrap; }

/* Toasts */
.toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--down);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  min-width: 240px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  animation: slide-in .2s ease-out;
}
.toast.recovered { border-left-color: var(--up); }
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Modal */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 320px;
}
.modal h3 { margin-top: 0; font-size: 15px; }
.modal label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.modal input, .modal select {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.field-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin: -4px 0 10px;
}

/* Context menu (right-click) */
.context-menu {
  position: fixed;
  z-index: 200;
  display: none;
  list-style: none;
  margin: 0;
  padding: 6px;
  min-width: 200px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
}
.context-menu.open { display: block; }
.context-menu li {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.context-menu li:hover { background: rgba(77,163,255,0.15); }
.context-menu li.danger { color: var(--down); }
.context-menu li.danger:hover { background: rgba(245,86,109,0.15); }
.context-menu li.menu-sep {
  height: 1px;
  margin: 6px 4px;
  padding: 0;
  background: var(--border);
  cursor: default;
}
.context-menu li.menu-sep:hover { background: var(--border); }

/* Wider modal for logs/terminal */
.modal-wide { width: min(720px, 92vw); }

.modal-head-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.autorefresh-toggle {
  display: flex !important;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 !important;
}
.autorefresh-toggle input { width: auto; margin: 0; }

.logs-box {
  background: #05080c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  max-height: 50vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 10px 0;
}

.terminal-box {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  height: 420px;
  margin: 10px 0;
}

.btn-icon {
  padding: 6px 10px;
  line-height: 1;
  font-size: 15px;
}

/* Terminal fullscreen toggle — expands the modal box itself to fill the
   viewport; the backdrop is already a fixed full-screen flex container so
   this just needs to take over all of it. */
#terminal-modal-box.modal-fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}
#terminal-modal-box.modal-fullscreen .terminal-box {
  flex: 1;
  height: auto;
}

/* ---------- SFTP file browser ---------- */

.sftp-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sftp-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  color: var(--text-dim);
  margin: 8px 0;
}
.sftp-breadcrumb .crumb {
  cursor: pointer;
  color: var(--accent);
  padding: 2px 4px;
  border-radius: 4px;
}
.sftp-breadcrumb .crumb:hover { background: rgba(77,163,255,0.15); }
.sftp-breadcrumb .sep { color: var(--text-dim); }

.sftp-dropzone {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #05080c;
  max-height: 48vh;
  overflow: auto;
}

.sftp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.sftp-table thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.sftp-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.sftp-table tbody tr:hover { background: rgba(77,163,255,0.08); }
.sftp-table .sftp-name {
  cursor: default;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
.sftp-table .sftp-name.is-dir { cursor: pointer; color: var(--accent); }
.sftp-table .sftp-name.is-dir:hover { text-decoration: underline; }
.sftp-table .sftp-size, .sftp-table .sftp-mtime { color: var(--text-dim); }
.sftp-table .sftp-row-actions { text-align: right; white-space: nowrap; }
.sftp-table .sftp-row-actions button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
}
.sftp-table .sftp-row-actions button:hover { color: var(--accent); }
.sftp-table .sftp-row-actions button.danger:hover { color: var(--down); }
.sftp-empty-hint { padding: 20px; text-align: center; color: var(--text-dim); font-size: 13px; }

.sftp-drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(77,163,255,0.12);
  border: 2px dashed var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  pointer-events: none;
}
.sftp-dropzone.drag-over .sftp-drop-overlay { display: flex; }

.sftp-transfers {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
}
.sftp-transfer {
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
.sftp-transfer .sftp-transfer-label {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.sftp-transfer .sftp-transfer-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.sftp-transfer .sftp-transfer-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
}
.sftp-transfer.error .sftp-transfer-fill { background: var(--down); }
.sftp-transfer.done .sftp-transfer-fill { background: var(--up); }

/* ---------- Login gate ---------- */

.hidden { display: none !important; }

.login-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-screen.open { display: flex; }

.login-box {
  width: min(320px, 90vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  text-align: center;
}
.login-box h1 { font-size: 18px; margin: 0 0 4px; }
.login-box label {
  display: block;
  text-align: left;
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-dim);
}
.login-box input {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.login-box .login-submit { width: 100%; margin-top: 16px; }
.login-error {
  min-height: 16px;
  color: var(--down);
  font-size: 12px;
  margin: 8px 0 0;
}

.btn-topbar { margin-left: 10px; }

/* Resource usage block inside container/service cards */
.resource-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.resource-line { margin-bottom: 8px; }
.resource-line:last-child { margin-bottom: 0; }
.resource-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 3px;
}
.resource-label .val { color: var(--text); font-weight: 600; }
.resource-note {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
}

/* ===== Android Device Cards ===== */

.android-card .badge-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.badge.android-bat {
  font-size: 0.72rem;
  padding: 2px 7px;
  background: var(--badge-unknown-bg, #333);
  color: var(--badge-unknown-fg, #ccc);
  border-radius: 999px;
  white-space: nowrap;
}

.badge.android-bat.charging {
  background: #1a3a1a;
  color: #4ade80;
}

.badge.android-bat.bat-low {
  background: #3a1a1a;
  color: #f87171;
}

.android-battery-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted, #888);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border, #2a2a2a);
}

.android-wifi-row {
  font-size: 0.8rem;
  color: var(--text-muted, #888);
  margin-top: 4px;
}

.android-os {
  margin-top: 6px;
  font-size: 0.75rem;
  opacity: 0.6;
}

.android-model {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.85;
}

/* Badge variants referenced by android rendering */
.badge.up    { background: #1a3a1a; color: #4ade80; }
.badge.down  { background: #3a1a1a; color: #f87171; }
.badge.unknown { background: #2a2a1a; color: #facc15; }

/* ---------- Google SSO login button ---------- */

.login-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 4px;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.login-divider::before, .login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: #fff;
  color: #3c4043;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-google:hover { filter: brightness(0.97); }

.topbar-identity {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ---------- Admin modal: Google SSO allowlist + stats ---------- */

.admin-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.admin-tab {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-tab-panel { max-height: 55vh; overflow-y: auto; }

.admin-inline-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.admin-inline-form input {
  flex: 1;
  padding: 7px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 18px;
}
.admin-table thead th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.admin-table .danger-link {
  background: none;
  border: none;
  color: var(--down);
  cursor: pointer;
  font-size: 12px;
}
.admin-empty-hint { color: var(--text-dim); font-size: 12px; padding: 8px; }

.admin-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  margin-bottom: 8px;
}

/* ---------- Pi system info (HW / OS / IP / Tailscale / df -h) ---------- */
.badge.pi-model { background: rgba(77,163,255,0.15); color: var(--accent); margin-left: 4px; vertical-align: middle; }
.badge.off { background: var(--panel-2); color: var(--text-dim); }

.sysinfo { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 13px; }
.sysinfo code { background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.info-row { display: flex; gap: 10px; align-items: flex-start; margin: 5px 0; }
.info-label { flex: 0 0 66px; color: var(--text-dim); }
.info-val { flex: 1; min-width: 0; color: var(--text); font-weight: 600; word-break: break-word; }
.info-val .card-sub { font-weight: 400; }
.info-val.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.info-head { margin: 10px 0 2px; color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.chip {
  font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--border); white-space: nowrap;
  user-select: all; /* one click selects the whole address, easy to copy */
}
.chip b { color: var(--text-dim); font-weight: 600; margin-right: 3px; }
.chip.tailscale { border-color: rgba(77,163,255,0.5); }
.chip.virtual { opacity: .55; }

.ts-link { color: var(--accent); text-decoration: none; }
.ts-link:hover { text-decoration: underline; }
.ts-entry { margin-top: 3px; font-weight: 500; }

.disk-row { gap: 10px; margin-top: 8px; }
.disk-row > span:first-child { min-width: 0; word-break: break-all; color: var(--text); }
.disk-detail { margin-top: 2px; word-break: break-word; }
