/* Mobile-first: this panel is used almost entirely from a phone while Cam is away from home.
   Base styles target a narrow touch screen (big tap targets, stacked rows, full-width controls);
   the min-width query at the bottom is the only place that spreads things out for a desktop. */
:root {
  --bg: #0d0f14;
  --panel: #161a22;
  --panel-2: #1b212c;
  --fg: #eef1f6;
  --muted: #9aa4b2;
  --line: #232a36;
  --accent: #e5a00d;   /* Plex-ish amber */
  --accent-2: #f7c744;
  --ok: #4ade80;
  --warn: #fbbf24;
  --fail: #ff6b6b;
  --error: #ff6b6b;
  --tap: 48px;         /* minimum comfortable touch target */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2130 0%, var(--bg) 60%);
  color: var(--fg);
  /* Respect the notch / home indicator on phones. */
  padding: max(16px, env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom));
  font-size: 16px;   /* keeps iOS from zooming when focusing inputs */
}

#app { width: 100%; max-width: 720px; margin: 0 auto; }

.view[hidden] { display: none; }

/* ---- Login ---- */
#login { text-align: center; margin-top: 14vh; }
#login h1 { font-size: 2rem; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 24px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#password {
  padding: 15px 16px; font-size: 1.05rem; border: 1px solid #2a3240;
  background: var(--panel); color: var(--fg); border-radius: 12px; width: 100%;
  outline: none; min-height: var(--tap);
}
#password:focus { border-color: var(--accent); }

/* ---- Buttons ---- */
button { font-family: inherit; cursor: pointer; border-radius: 12px; font-weight: 600; min-height: var(--tap); }
button:disabled { opacity: .45; cursor: default; }
button:active:not(:disabled) { transform: translateY(1px); }
.primary, #login-btn {
  padding: 14px 20px; border: none; font-size: 1.02rem;
  background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: #1a1400;
}
.secondary { padding: 13px 16px; background: #2a3240; color: var(--fg); border: 1px solid #2a3240; font-size: 1rem; }
.secondary:active:not(:disabled) { background: #343d4d; }
.danger { padding: 13px 16px; background: #241819; color: var(--fail); border: 1px solid #4a2a2a; font-size: 1rem; }
.danger:active:not(:disabled) { background: #2a1717; }
.ghost { padding: 11px 14px; background: transparent; color: var(--muted); border: 1px solid var(--line); font-size: .95rem; min-height: 44px; }
.ghost:active:not(:disabled) { color: var(--fg); border-color: #3a4454; }

/* ---- Top bar ---- */
.bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 10px; }
.bar h1 { margin: 0; font-size: 1.35rem; }
.bar-right { display: flex; gap: 8px; }

/* ---- Tabs (phone-first: full-width, big tap targets) ---- */
.tabs {
  display: flex; gap: 6px; margin-bottom: 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 5px;
}
.tab {
  flex: 1; min-height: var(--tap); padding: 10px 12px; border: none; border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 1rem;
}
.tab.active { background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: #1a1400; }
.tab:not(.active):active { background: var(--panel-2); }
.tabpane[hidden] { display: none; }

/* ---- Status rows (locations / services) ---- */
.mon-group { margin-top: 14px; }
.mon-group:first-child { margin-top: 4px; }
.mon-group h3 {
  margin: 0 0 8px; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
}
.statuslist { display: flex; flex-direction: column; gap: 7px; }
.statusrow {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  border-radius: 10px; background: var(--panel-2);
}
.statusrow .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.statusrow.ok .dot { background: var(--ok); }
.statusrow.down .dot { background: var(--fail); }
.statusrow .sname { font-weight: 600; }
.statusrow .sdetail { margin-left: auto; color: var(--muted); font-size: .82rem; text-align: right; }
#mon-updated { margin-bottom: 4px; }

/* ---- Panels ---- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; margin-bottom: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 1.05rem; }

.badge {
  font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 5px 11px; border-radius: 999px; background: #2a3240; color: var(--muted); white-space: nowrap;
}
.badge.up { background: rgba(74,222,128,.15); color: var(--ok); }
.badge.down { background: rgba(255,107,107,.15); color: var(--fail); }

/* ---- Status grid: two columns even on a phone, one when very narrow ---- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; margin: 0; }
.grid div { min-width: 0; }
.grid dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.grid dd { margin: 0; font-size: 1rem; word-break: break-word; }

.gpu { margin-top: 14px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.gpu .tile {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; font-size: .88rem;
}
.gpu .tile b { color: var(--accent-2); }

/* ---- Launch form: labels stacked above full-width controls (thumb-friendly) ---- */
.form-row { display: flex; flex-direction: column; gap: 7px; margin-bottom: 15px; }
.form-row label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
#model, #maxlen {
  padding: 13px 14px; background: var(--panel-2); color: var(--fg);
  border: 1px solid #2a3240; border-radius: 12px; font-size: 1rem; outline: none; width: 100%;
  min-height: var(--tap);
}
#model:focus, #maxlen:focus { border-color: var(--accent); }
.hint { color: var(--muted); font-size: .82rem; }

/* Primary actions: full-width, stacked, Start most prominent. */
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.actions button { width: 100%; }
.sub-actions { margin-top: 12px; flex-direction: row; flex-wrap: wrap; }
.sub-actions button { flex: 1; min-width: 140px; width: auto; }

/* ---- Pre-flight checks ---- */
.checks { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; gap: 7px; }
.checks li { display: flex; align-items: baseline; gap: 10px; padding: 11px 12px; border-radius: 10px; background: var(--panel-2); }
.checks .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.checks .pass .dot { background: var(--ok); }
.checks .warn .dot { background: var(--warn); }
.checks .fail .dot { background: var(--fail); }
.checks .label { font-weight: 600; }
.checks .detail { color: var(--muted); font-size: .86rem; }

.msg { margin: 14px 0 0; padding: 12px; border-radius: 10px; background: var(--panel-2); font-size: .92rem; line-height: 1.45; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--fail); }
.msg[hidden] { display: none; }

.error { color: var(--error); margin-top: 14px; min-height: 1.2em; }

/* ---- Logs ---- */
.logs {
  background: #0a0c10; border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  margin: 0; font-size: .78rem; line-height: 1.55; color: #c8d0dc;
  max-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

/* Very narrow phones: collapse the status grid to one column. */
@media (max-width: 360px) {
  .grid, .gpu { grid-template-columns: 1fr; }
}

/* Desktop / tablet: spread out, row-based actions, wider status grid. */
@media (min-width: 640px) {
  body { padding: 24px 16px; }
  #login { margin-top: 12vh; }
  #login-form { flex-direction: row; justify-content: center; }
  #password { width: auto; flex: 1; min-width: 240px; }
  #login-btn { width: auto; }
  .bar h1 { font-size: 1.5rem; }
  .panel { padding: 18px 20px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .gpu { display: flex; flex-wrap: wrap; }
  .gpu .tile { min-width: 140px; }
  .form-row { flex-direction: row; align-items: center; }
  .form-row label { min-width: 150px; }
  #model { flex: 1; }
  #maxlen { width: 160px; }
  .actions { flex-direction: row; flex-wrap: wrap; }
  .actions button { width: auto; flex: 1; min-width: 150px; }
}
