:root {
  --bg: #0b1210;
  --bg-2: #101a17;
  --panel: rgba(22, 34, 30, 0.78);
  --panel-solid: #15211d;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8f1ee;
  --muted: #8ea39c;
  --accent: #25d366;
  --accent-2: #12b5a5;
  --accent-soft: rgba(37, 211, 102, 0.14);
  --warn: #f5b840;
  --danger: #ff5d6c;
  --info: #5aa9ff;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, rgba(37, 211, 102, 0.12), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(18, 181, 165, 0.12), transparent 60%), var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
code { background: rgba(255, 255, 255, 0.07); padding: 1px 6px; border-radius: 6px; font-size: 0.9em; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h3 { font-size: 1.02rem; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.big { width: 40px; height: 40px; opacity: 0.7; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* Layout */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px;
  padding: 22px 16px; border-right: 1px solid var(--border); background: rgba(10, 16, 14, 0.6); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand small { display: block; }
.brand-lg h1 { font-size: 1.4rem; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--muted);
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}
.nav a:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); transform: translateX(2px); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.main { padding: 26px clamp(16px, 3vw, 36px) 40px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
.topbar h2 { font-size: 1.5rem; }

.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.videos { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-top: 18px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); backdrop-filter: blur(12px); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; gap: 4px; transition: transform 0.25s var(--ease), border-color 0.25s; }
.stat:hover { transform: translateY(-3px); border-color: rgba(37, 211, 102, 0.3); }
.stat strong { font-size: 1.55rem; letter-spacing: -0.02em; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions.end { justify-content: flex-end; }
.callout { margin-top: 18px; padding: 14px 16px; border-radius: var(--radius-sm); background: rgba(90, 169, 255, 0.08); border: 1px solid rgba(90, 169, 255, 0.2); }
.callout p { margin: 6px 0 0; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.05); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; transition: transform 0.15s var(--ease), background 0.2s, box-shadow 0.2s, opacity 0.2s; white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.09); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04140c; border: 0; box-shadow: 0 6px 18px rgba(37, 211, 102, 0.28); }
.btn-primary:hover { background: linear-gradient(135deg, #3be27a, #19c7b6); box-shadow: 0 8px 24px rgba(37, 211, 102, 0.38); }
.btn-danger { color: var(--danger); border-color: rgba(255, 93, 108, 0.35); background: rgba(255, 93, 108, 0.08); }
.btn-danger:hover { background: rgba(255, 93, 108, 0.16); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); justify-content: flex-start; }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn-block { width: 100%; }
.icon-btn { padding: 8px; border-radius: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: rgba(0, 0, 0, 0.25); border: 1px solid var(--border);
  border-radius: 12px; padding: 11px 13px; transition: border-color 0.2s, box-shadow 0.2s; resize: vertical;
}
select { width: auto; padding: 7px 12px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: rgba(37, 211, 102, 0.6); box-shadow: 0 0 0 4px rgba(37, 211, 102, 0.12); }
.form-error { color: var(--danger); margin: 0; font-size: 0.9rem; }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { width: 42px; height: 24px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); position: relative; transition: background 0.25s var(--ease); flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.25s var(--ease); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

.segmented { display: inline-flex; padding: 4px; border-radius: 12px; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--border); margin-bottom: 16px; }
.segmented button { border: 0; background: transparent; color: var(--muted); padding: 8px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; transition: all 0.2s var(--ease); }
.segmented button.active { background: var(--accent-soft); color: var(--accent); }

/* Status chip */
.status-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 99px; font-size: 0.82rem; font-weight: 600; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border); color: var(--muted); }
.status-chip.lg { padding: 8px 14px; }
.status-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-chip[data-s="connected"] { color: var(--accent); background: var(--accent-soft); }
.status-chip[data-s="connected"] .dot { background: var(--accent); box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.6); animation: ping 2s infinite; }
.status-chip[data-s="connecting"], .status-chip[data-s="reconnecting"], .status-chip[data-s="qr"], .status-chip[data-s="pairing"] { color: var(--warn); background: rgba(245, 184, 64, 0.1); }
.status-chip[data-s="connecting"] .dot, .status-chip[data-s="reconnecting"] .dot, .status-chip[data-s="qr"] .dot, .status-chip[data-s="pairing"] .dot { background: var(--warn); animation: blink 1s infinite; }
.status-chip[data-s="logged_out"] { color: var(--danger); background: rgba(255, 93, 108, 0.1); }
.status-chip[data-s="logged_out"] .dot { background: var(--danger); }

/* Auth display */
.auth-box { min-height: 320px; display: grid; place-items: center; border-radius: var(--radius-sm); background: rgba(0, 0, 0, 0.2); border: 1px dashed var(--border); padding: 18px; }
.auth-box .placeholder { text-align: center; }
#qrImg { width: min(300px, 100%); border-radius: 14px; background: #fff; padding: 10px; animation: pop 0.45s var(--ease); }
.pair-code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: clamp(1.8rem, 6vw, 2.6rem); letter-spacing: 0.18em; font-weight: 700; padding: 18px 22px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); animation: pop 0.45s var(--ease); text-align: center; word-break: break-all; }
.connected-box { display: flex; flex-direction: column; align-items: center; gap: 8px; animation: pop 0.45s var(--ease); }
.pulse-ring { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); position: relative; }
.pulse-ring svg { width: 36px; height: 36px; }
.pulse-ring::before { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent); animation: ring 2s var(--ease) infinite; }
.steps { padding-left: 20px; margin: 18px 0 0; }
.steps li { margin-bottom: 4px; }

/* Upload */
.upload { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 18px; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 28px; min-height: 220px; border: 2px dashed rgba(37, 211, 102, 0.35); border-radius: var(--radius); cursor: pointer; transition: all 0.25s var(--ease); background: rgba(37, 211, 102, 0.03); }
.dropzone:hover, .dropzone.drag { background: rgba(37, 211, 102, 0.09); border-color: var(--accent); transform: scale(1.01); }
.upload-fields { display: flex; flex-direction: column; gap: 12px; }
.progress { position: relative; height: 26px; border-radius: 99px; background: rgba(0, 0, 0, 0.3); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.2s; }
.progress span { position: relative; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }

.video-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; animation: fadeUp 0.45s var(--ease) both; transition: transform 0.25s var(--ease), border-color 0.25s; }
.video-card:hover { transform: translateY(-4px); border-color: rgba(37, 211, 102, 0.3); }
.video-card video { width: 100%; aspect-ratio: 16 / 9; background: #000; display: block; object-fit: contain; }
.video-card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.video-card .title { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.video-card .title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-card .actions { margin-top: auto; padding-top: 8px; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 0.72rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.warn { background: rgba(245, 184, 64, 0.12); color: var(--warn); }
.badge.danger { background: rgba(255, 93, 108, 0.12); color: var(--danger); }
.badge svg { width: 12px; height: 12px; }

/* Logs */
.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 65vh; overflow: auto; }
.log-list.compact { max-height: 340px; }
.log-list li { display: grid; grid-template-columns: auto auto 1fr; gap: 10px; align-items: baseline; padding: 9px 12px; border-radius: 10px; background: rgba(0, 0, 0, 0.18); border-left: 3px solid var(--info); font-size: 0.88rem; animation: slideIn 0.35s var(--ease) both; }
.log-list li[data-level="warn"] { border-left-color: var(--warn); }
.log-list li[data-level="error"] { border-left-color: var(--danger); }
.log-list li[data-success="1"] { border-left-color: var(--accent); }
.log-list time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.78rem; white-space: nowrap; }
.log-list .cat { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.log-list .msg { word-break: break-word; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table td.wrap { white-space: normal; word-break: break-all; }

/* Dialog + toasts */
.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-solid); color: var(--text); width: min(480px, 92vw); padding: 22px; box-shadow: var(--shadow); }
.dialog[open] { animation: pop 0.3s var(--ease); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 50; }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--panel-solid); border: 1px solid var(--border); box-shadow: var(--shadow); max-width: 360px; animation: toastIn 0.35s var(--ease); border-left: 3px solid var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.out { animation: toastOut 0.3s var(--ease) forwards; }

.view { animation: fadeUp 0.4s var(--ease); }
.fade-up { animation: fadeUp 0.55s var(--ease); }
.empty { padding: 40px 0; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; display: inline-block; }
.shake { animation: shake 0.4s; }
.skeleton { background: linear-gradient(90deg, rgba(255,255,255,.04), rgba(255,255,255,.09), rgba(255,255,255,.04)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 10px; min-height: 40px; }

/* Auth page */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; overflow: hidden; }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 22px; padding: 30px; box-shadow: var(--shadow); backdrop-filter: blur(16px); display: flex; flex-direction: column; gap: 22px; position: relative; z-index: 1; }
.bg-orbs span { position: fixed; border-radius: 50%; filter: blur(60px); opacity: 0.35; animation: float 14s ease-in-out infinite; }
.bg-orbs span:nth-child(1) { width: 380px; height: 380px; background: #25d366; top: -120px; left: -80px; }
.bg-orbs span:nth-child(2) { width: 320px; height: 320px; background: #12b5a5; bottom: -100px; right: -60px; animation-delay: -5s; }
.bg-orbs span:nth-child(3) { width: 220px; height: 220px; background: #5aa9ff; top: 40%; left: 60%; animation-delay: -9s; opacity: 0.18; }

.bottom-nav { display: none; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: none; } }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.6); } 80%, 100% { box-shadow: 0 0 0 8px rgba(37, 211, 102, 0); } }
@keyframes ring { 0% { transform: scale(1); opacity: 0.8; } 100% { transform: scale(1.6); opacity: 0; } }
@keyframes blink { 50% { opacity: 0.3; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes float { 50% { transform: translate(40px, 30px) scale(1.08); } }

/* Responsive */
@media (max-width: 1100px) {
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 18px 14px calc(92px + env(safe-area-inset-bottom)); }
  .grid.two, .upload { grid-template-columns: 1fr; }
  .topbar h2 { font-size: 1.25rem; }
  .bottom-nav {
    display: flex; position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 40;
    justify-content: space-around; padding: 6px; border-radius: 18px; background: rgba(16, 26, 23, 0.92); border: 1px solid var(--border);
    backdrop-filter: blur(16px); box-shadow: var(--shadow);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 8px; border-radius: 12px; color: var(--muted); font-size: 0.68rem; flex: 1; transition: all 0.2s var(--ease); }
  .bottom-nav a.active { color: var(--accent); background: var(--accent-soft); }
  .toasts { left: 14px; right: 14px; bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  .log-list li { grid-template-columns: auto 1fr; }
  .log-list li .msg { grid-column: 1 / -1; }
}
@media (max-width: 420px) {
  .grid.stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat strong { font-size: 1.2rem; }
  .card { padding: 16px; }
  .actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
