/* ============================================================
   Fleet Remote Support — operator console
   Professional, accessible, light + dark.
   ============================================================ */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --border-strong: #d4d9e0;
  --text: #171a1f;
  --text-muted: #667085;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef2ff;
  --online: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-md: 0 4px 12px rgba(16,24,40,.08), 0 2px 6px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.14);
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e14;
    --surface: #141922;
    --surface-2: #1b212c;
    --border: #262d3a;
    --border-strong: #333c4d;
    --text: #e6e9ef;
    --text-muted: #94a0b0;
    --brand: #6366f1;
    --brand-hover: #818cf8;
    --brand-soft: #1e2440;
    --online: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 6px 18px rgba(0,0,0,.45);
    --shadow-lg: 0 16px 40px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h2, h3 { margin: 0; font-weight: 600; }
[hidden] { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Login ---------- */
.login {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  display: flex; flex-direction: column; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-lg { margin-bottom: 4px; }
.logo {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  background: var(--brand); color: #fff;
  border-radius: 10px; box-shadow: var(--shadow-sm);
}
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { color: var(--text-muted); font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
input[type="text"], input[type="password"] {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
}
.login-error {
  margin: 0; font-size: 13px; color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  padding: 8px 10px; border-radius: var(--radius-sm);
}
.login-foot { margin: 0; text-align: center; font-size: 12px; color: var(--text-muted); }

/* ---------- App shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 16px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .logo { width: 30px; height: 30px; border-radius: 8px; }
.topbar .brand-title { font-size: 14px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border);
}
.pill-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-ok { color: var(--online); background: color-mix(in srgb, var(--online) 10%, transparent); border-color: color-mix(in srgb, var(--online) 25%, transparent); }
.pill-bad { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.pill-wait { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }

.layout { flex: 1; display: flex; min-height: 0; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 300px; flex: none;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 16px 10px;
}
.sidebar-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.count {
  font-size: 12px; font-weight: 700; color: var(--brand);
  background: var(--brand-soft); border-radius: 999px; padding: 1px 9px;
}
.search {
  position: relative; margin: 0 12px 8px;
}
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search input { padding-left: 34px; }

.device-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.device-card {
  display: flex; align-items: center; gap: 11px;
  padding: 10px; border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 2px;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.device-card:hover { background: var(--surface-2); }
.device-card.active { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 35%, transparent); }
.avatar {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%; font-weight: 700; font-size: 14px;
  background: var(--brand-soft); color: var(--brand);
  position: relative;
}
.avatar-online::after {
  content: ""; position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--online); border: 2px solid var(--surface);
}
.device-meta { min-width: 0; flex: 1; }
.device-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-sub { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12px; }
.batt { display: inline-flex; align-items: center; gap: 4px; }
.batt.low { color: var(--danger); }
.batt.mid { color: var(--warn); }
.badge-view {
  margin-left: auto; font-size: 11px; font-weight: 700; color: var(--brand);
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
  padding: 2px 7px; border-radius: 999px;
}

.side-empty {
  margin: auto; padding: 24px; text-align: center; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.side-empty p { margin: 8px 0 0; font-weight: 600; color: var(--text); }
.side-empty span { font-size: 12px; max-width: 200px; }

/* ---------- Stage ---------- */
.stage { flex: 1; min-width: 0; display: flex; }
.placeholder {
  margin: auto; text-align: center; max-width: 380px; padding: 24px;
  color: var(--text-muted); display: flex; flex-direction: column; align-items: center;
}
.placeholder-icon {
  width: 72px; height: 72px; display: grid; place-items: center;
  border-radius: 18px; background: var(--surface); border: 1px solid var(--border);
  color: var(--brand); margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.placeholder h3 { font-size: 17px; color: var(--text); margin-bottom: 6px; }
.placeholder p { margin: 0; }

/* ---------- Viewer ---------- */
.viewer { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.viewer-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.viewer-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.viewer-id .avatar { width: 34px; height: 34px; font-size: 13px; }
.viewer-id-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.viewer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; color: var(--online); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--online); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.metrics { display: flex; align-items: center; gap: 10px; margin-left: auto; color: var(--text-muted); font-size: 12px; }
.metric strong { color: var(--text); font-variant-numeric: tabular-nums; }
.metric-sep { width: 1px; height: 14px; background: var(--border-strong); }

.viewer-actions { display: flex; align-items: center; gap: 10px; }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button {
  border: 0; background: transparent; color: var(--text-muted);
  padding: 7px 11px; cursor: pointer; display: grid; place-items: center;
  border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: var(--surface); color: var(--text); }

.screen-stage {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 20px;
  background:
    radial-gradient(900px 500px at 50% 0%, color-mix(in srgb, var(--brand) 7%, transparent), transparent 70%),
    var(--bg);
}
.screen-panel {
  position: relative;
  max-width: 100%; max-height: 100%;
  background: #0a0a0a;
  border: 1px solid var(--border-strong);
  border-radius: 20px; padding: 8px;
  box-shadow: var(--shadow-lg);
  display: flex;
}
#screen {
  display: block; max-width: 100%; max-height: calc(100vh - 220px);
  border-radius: 12px; object-fit: contain;
  cursor: crosshair; user-select: none; touch-action: none;
  background: #000;
}
.screen-waiting {
  position: absolute; inset: 8px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; color: #cbd2dd; background: #0a0a0a;
}
.screen-waiting p { margin: 4px 0 0; font-weight: 600; color: #fff; }
.screen-waiting span { font-size: 12px; color: #8b94a3; max-width: 240px; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.18); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.screen-hint { margin: 0; color: var(--text-muted); font-size: 12px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  padding: 11px 14px; font-size: 13px; max-width: 320px;
  animation: slideIn .2s ease;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--online); }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .sidebar { width: 100%; position: absolute; inset: 56px 0 0; z-index: 20; }
  .app.viewing .sidebar { display: none; }
  .metrics { display: none; }
  #screen { max-height: calc(100vh - 190px); }
}
