/* The HTML `hidden` attribute uses user-agent specificity (`display: none`)
   which any CSS rule with `display: <anything>` silently overrides. Restate
   it globally with !important so any element marked `hidden` actually hides. */
[hidden] { display: none !important; }

/* ============ Stage-2 health banner + tokens ============ */
.health-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: #fef2f2;
  color: #991b1b;
  border-bottom: 1px solid #fecaca;
  font-size: 13px;
  font-weight: 500;
}
.health-banner svg { width: 16px; height: 16px; flex-shrink: 0; }

.tokens-section { display: flex; flex-direction: column; gap: 10px; }
.tokens-section-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px 14px;
  align-items: center;
  margin-bottom: 6px;
}
.tokens-section-head h4 { margin: 0; font-size: 14px; }
.tokens-section-head .muted { font-size: 12px; }

.tokens-list { display: flex; flex-direction: column; gap: 8px; }
.token-card {
  display: grid;
  grid-template-columns: 90px 1fr 110px 130px 120px;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  background: var(--surface-2, #f9fafb);
  font-size: 13px;
}
.token-card.revoked { opacity: 0.5; background: var(--surface-3, #f3f4f6); }
.token-card .tk-meta { display: flex; flex-direction: column; gap: 2px; }
.token-card code {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-muted, #6b7280);
  word-break: break-all;
}
.token-card .tk-label {
  font-size: 12px;
  color: var(--text, #111827);
  font-weight: 500;
}
.token-card .tk-actions { display: flex; gap: 4px; justify-content: flex-end; }
.tk-kind-app { background:#dbeafe; color:#1e40af; padding:3px 8px; border-radius:99px; font-size:11px; font-weight:600; }
.tk-kind-ext { background:#dcfce7; color:#166534; padding:3px 8px; border-radius:99px; font-size:11px; font-weight:600; }

@media (max-width: 900px) {
  .token-card { grid-template-columns: 1fr; }
  .tokens-section-head { grid-template-columns: 1fr; }
}

:root {
  --primary: #ff6a00;
  --primary-dark: #e65e00;
  --primary-light: #ff8a1c;
  --primary-soft: #fff2e6;
  --gold: #ff8a1c;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --surface-3: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --success: #16a34a;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fff8e0;
  --info: #2563eb;
  --info-soft: #eef4ff;
  --sidebar-width: 220px;
  --topbar-height: 52px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.18);
  --glow: 0 6px 20px rgba(255, 106, 0, 0.28);
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(15, 23, 42, 0.08);
  --backdrop: rgba(15, 23, 42, 0.5);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --transition: 0.18s ease;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --primary: #ff6a00;
  --primary-dark: #e65e00;
  --primary-light: #ff8a1c;
  --primary-soft: rgba(255, 106, 0, 0.14);
  --gold: #ff8a1c;
  --bg: #050505;
  --surface: #111111;
  --surface-2: #161616;
  --surface-3: #1d1d1d;
  --border: #262626;
  --border-strong: #3a3a3a;
  --text: #ffffff;
  --text-muted: #9ca3af;
  --text-light: #6b7280;
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.16);
  --warning: #ff8a1c;
  --warning-soft: rgba(255, 138, 28, 0.16);
  --info: #ff8a1c;
  --info-soft: rgba(255, 138, 28, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 28px 60px rgba(0, 0, 0, 0.7);
  --glow: 0 0 0 1px rgba(255, 106, 0, 0.25), 0 8px 30px rgba(255, 106, 0, 0.22);
  --glass-bg: rgba(20, 20, 20, 0.62);
  --glass-border: rgba(255, 255, 255, 0.08);
  --backdrop: rgba(0, 0, 0, 0.72);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Tahoma",
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
button,
input,
select,
textarea {
  font: inherit;
}

/* Native <select> dropdowns: force readable colors so the option list never
   blends into the background (the .btn class otherwise bleeds a light text
   color onto the OS popup, making items invisible in dark mode). */
select,
select.btn {
  color: var(--text);
}
select option,
select optgroup {
  background-color: var(--surface);
  color: var(--text);
}
select option:checked,
select option:hover {
  background-color: var(--primary-soft);
  color: var(--text);
}
a {
  color: inherit;
}

/* ================ App layout ================ */
.app {
  display: flex;
  min-height: 100vh;
}

/* ================ Sidebar ================ */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: margin-left var(--transition);
}
.app.sidebar-collapsed .sidebar {
  margin-left: calc(var(--sidebar-width) * -1);
}

.sidebar-brand {
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary) 0%, #f4793f 100%);
  color: white;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(238, 77, 45, 0.3);
}
.brand-logo svg {
  width: 20px;
  height: 20px;
}
/* Bitmap logo variant — used by SYDEAR Bot branding.
   The artwork already carries its own alpha channel, so the container must
   NOT paint a background: that is what used to draw a frame around the
   logo and hide the mark. */
.brand-logo-img {
  background: none;
  padding: 0;
  box-shadow: none;
}
.brand-logo-img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 0;
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
}
.brand-title {
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-nav {
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  width: 100%;
  transition: all var(--transition);
  position: relative;
}
.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--primary);
}
.nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.extension-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.ext-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  flex-shrink: 0;
}
.ext-dot.online {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
}
.ext-dot.offline {
  background: var(--danger);
}
.ext-text {
  flex: 1;
  min-width: 0;
}
.ext-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--text);
}
.ext-status {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* ================ Main ================ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ================ Topbar ================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Compact status cluster — groups realtime, bots count, control state
   into one visually unified pill row instead of 3 floating badges. */
.status-cluster {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* Topbar notification bell + badge */
.notif-bell { position: relative; }
.notif-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface, #111);
}
.topbar-create { white-space: nowrap; }

/* Notification modal */
.modal-notif .modal-card-sm { max-width: 420px; }
.notif-head-actions { display: inline-flex; align-items: center; gap: 6px; }
.notif-body { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.notif-empty { text-align: center; color: var(--text-secondary, #9ca3af); padding: 24px 8px; }
.notif-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2, rgba(255,255,255,0.04));
  border: 1px solid var(--border, rgba(255,255,255,0.08));
}
.notif-item .notif-dot {
  flex: 0 0 auto;
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--text-muted, #9ca3af);
}
.notif-item.notif-noai .notif-dot,
.notif-item.notif-failed .notif-dot,
.notif-item.notif-credit .notif-dot,
.notif-item.notif-captcha .notif-dot { background: #ff6a6a; }
.notif-item.notif-offline .notif-dot { background: #ffb648; }
.notif-item .notif-content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.notif-item .notif-card {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--primary-light, #ff8a1c);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notif-item .notif-text { font-size: 13px; word-break: break-word; }

/* Extension scrape stats on the bot card */
.ext-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.ext-stats .ext-stat {
  flex: 1 1 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 8px;
  border-radius: 10px;
  background: var(--surface-2, rgba(255,255,255,0.04));
  border: 1px solid var(--border, rgba(255,255,255,0.08));
}
.ext-stats .ext-stat-num {
  font-family: "Sora", sans-serif;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text, #fff);
}
.ext-stats .ext-stat-lbl { font-size: 10.5px; color: var(--text-muted, #9ca3af); }
.ext-stats .ext-stat.is-done .ext-stat-num { color: var(--success, #4ade80); }
.ext-stats .ext-stat.is-fail .ext-stat-num { color: #ff7a7a; }
.ext-stats .ext-stat.is-wait .ext-stat-num { color: var(--primary-light, #ff8a1c); }
.ext-stats .ext-stat.is-skip .ext-stat-num { color: var(--text-muted, #9ca3af); }

/* Plain-language usable-links summary under the ext queue stats. */
.ext-usable {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-2, rgba(255,255,255,0.04));
  border: 1px solid var(--border, rgba(255,255,255,0.08));
}
.ext-usable-main { font-size: 12.5px; color: var(--text, #fff); }
.ext-usable-ok { color: var(--success, #4ade80); font-size: 14px; }
.ext-usable-sub { margin-top: 3px; font-size: 11px; color: var(--text-muted, #9ca3af); }
.notif-item .notif-del { flex: 0 0 auto; opacity: 0.6; }
.notif-item .notif-del:hover { opacity: 1; }
.status-cluster .pill { border-radius: 999px; padding: 2px 9px; font-size: 11.5px; }
.status-cluster .realtime-indicator {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  background: transparent; border: none;
}
.status-cluster .realtime-indicator::before { display: none !important; }
.status-cluster .rt-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-light);
  transition: all .25s;
}
.status-cluster .realtime-indicator.on .rt-dot {
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.18);
  animation: rtPulseSmall 1.6s ease-in-out infinite;
}
.status-cluster .realtime-indicator.on { color: var(--success); }
@keyframes rtPulseSmall {
  0%, 100% { box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.18); }
  50%      { box-shadow: 0 0 0 5px rgba(22, 163, 74, 0.0); }
}

.user-chip {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

@media (max-width: 760px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .status-cluster .pill,
  .status-cluster .realtime-indicator { padding: 2px 7px; font-size: 11px; }
  .user-chip { display: none !important; }
}
.topbar-spacer {
  flex: 1;
}
.sidebar-toggle {
  display: none;
}

/* ================ Buttons ================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  transition: all 0.14s;
  white-space: nowrap;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.4);
}
.btn svg {
  width: 14px;
  height: 14px;
}
.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary-dark);
}
.btn-primary:hover {
  background: var(--primary-dark);
}
.btn-danger {
  color: var(--danger);
  border-color: #fecaca;
}
.btn-danger:hover {
  background: var(--danger-soft);
}
.btn-icon-only {
  padding: 8px;
}
.btn-icon-only svg {
  width: 16px;
  height: 16px;
}
.btn-control {
  background: linear-gradient(135deg, #16a34a 0%, #22c55e 100%);
  color: white;
  border: none;
  padding: 8px 16px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.25);
}
.btn-control:hover {
  background: linear-gradient(135deg, #15803d 0%, #16a34a 100%);
}
.btn-control[data-state="running"] {
  background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.25);
}
.btn-control[data-state="running"]:hover {
  background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%);
}
.btn-control[data-state="loading"] {
  background: var(--text-light);
  pointer-events: none;
}

/* ================ Pills ================ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-muted);
  white-space: nowrap;
}
.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.pill-primary {
  background: var(--primary-soft);
  color: var(--primary);
}
.pill-success {
  background: var(--success-soft);
  color: var(--success);
}
.pill-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.pill-warning {
  background: var(--warning-soft);
  color: var(--warning);
}
.pill-info {
  background: var(--info-soft);
  color: var(--info);
}
.pill-muted {
  background: var(--surface-3);
  color: var(--text-muted);
}
.pill-skip {
  background: repeating-linear-gradient(
    45deg,
    var(--surface-3),
    var(--surface-3) 4px,
    var(--border) 4px,
    var(--border) 8px
  );
  color: var(--text-muted);
  font-style: italic;
}
/* "ทำงานเสร็จแล้ว" — running + queue drained.
   Visually celebratory but calmer than the running green so operators can
   spot it across a wall of cards. */
.pill-done {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #78350f;
  border-color: #f59e0b !important;
}
.pill-done .dot {
  background: #f59e0b !important;
}

/* The "เรียบร้อย" button replaces the "หยุด" warning button when work is
   complete. Calm gold instead of red so finishing feels like a celebration,
   not an emergency. */
.btn-done {
  background: linear-gradient(135deg, #fde68a, #fbbf24);
  color: #78350f;
  border-color: #d97706 !important;
  box-shadow: 0 0 0 2px #fde68a inset, 4px 4px 0 0 #d97706 !important;
}
.btn-done:hover {
  background: linear-gradient(135deg, #fcd34d, #f59e0b);
}

/* ================ Search ================ */
.search {
  position: relative;
  width: 260px;
}
.search input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  transition: all 0.14s;
}
.search input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.18);
}
.search svg {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-light);
}

/* ================ Content ================ */
.content {
  padding: 16px 16px;
  flex: 1;
  overflow: auto;
}
.view {
  display: none;
  animation: fade 0.18s;
}
.view.active {
  display: block;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ================ Stats ================ */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.stat-icon svg {
  width: 18px;
  height: 18px;
}
.stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.stat-value {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* ================ Panels ================ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 12px;
}
.panel-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.panel-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.panel-body {
  padding: 12px 14px;
}
.panel-head h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
}

/* ================ Dashboard recent activity ================ */
.activity-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px dashed var(--border);
}
.activity-row:last-child {
  border-bottom: none;
}
.activity-row .ar-id {
  font-weight: 600;
  font-size: 12px;
  color: var(--text);
}
.activity-row .ar-meta {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-light);
}

/* ================ Queue stats bars ================ */
.queue-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.qs-row {
  display: grid;
  grid-template-columns: 80px 1fr 50px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.qs-label {
  color: var(--text-muted);
  font-weight: 500;
}
.qs-bar {
  height: 8px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.qs-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--text-light);
  border-radius: 4px;
  transition: width 0.3s;
}
.qs-fill.running {
  background: var(--info);
}
.qs-fill.done {
  background: var(--success);
}
.qs-fill.failed {
  background: var(--danger);
}
.qs-fill.skipped {
  background: linear-gradient(
    135deg,
    var(--text-light) 25%,
    transparent 25%,
    transparent 50%,
    var(--text-light) 50%,
    var(--text-light) 75%,
    transparent 75%
  );
  background-size: 8px 8px;
  background-color: var(--border);
}
.qs-num {
  font-weight: 700;
  text-align: right;
}

/* ================ Queue page ================ */
.queue-controls {
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
}
.qc-section h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
}
#queue-input {
  width: 100%;
  height: 100px;
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
  resize: vertical;
}
#queue-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.1);
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.setting-row {
  margin-bottom: 12px;
}
.setting-row > label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
}
.setting-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.number-input {
  display: inline-flex;
  align-items: center;
  gap: 0;
}
.number-input input {
  width: 70px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 0;
  padding: 7px 6px;
  font-weight: 700;
  font-size: 14px;
}
.number-input .btn-icon-only:first-child {
  border-radius: 8px 0 0 8px;
  border-right: none;
}
.number-input .btn-icon-only:last-child {
  border-radius: 0 8px 8px 0;
  border-left: none;
}
.number-input input:focus {
  outline: none;
  border-color: var(--primary);
}

.text-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, Consolas, monospace;
}

/* Queue list (table-like) */
.queue-table {
  display: flex;
  flex-direction: column;
}
.queue-row {
  display: grid;
  grid-template-columns: 50px 1fr 110px 90px 130px 70px;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.queue-row:hover {
  background: var(--surface-2);
}
.queue-row.is-active {
  background: var(--primary-soft);
  border-left: 3px solid var(--primary);
}
.queue-row .qr-id {
  font-weight: 700;
  color: var(--text-muted);
}
.queue-row .qr-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.queue-row .qr-url .qr-shop {
  font-weight: 600;
  color: var(--text);
}
.queue-row .qr-url .qr-link {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.queue-row .qr-progress {
  font-size: 11px;
  color: var(--text-muted);
}
.queue-row .qr-pages {
  font-weight: 600;
  text-align: center;
}
.queue-row .qr-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.queue-table-head {
  display: grid;
  grid-template-columns: 50px 1fr 110px 90px 130px 70px;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

/* ================ Products page ================ */
.layout-products {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 14px;
  align-items: start;
}
.panel-list {
  max-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
}
.panel-detail {
  min-height: 480px;
  max-height: calc(100vh - 100px);
  overflow: auto;
}
.products {
  flex: 1;
  overflow: auto;
  padding: 8px;
}
.product-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface);
  transition: all 0.15s;
  position: relative;
}
.product-card:hover {
  border-color: var(--primary);
  background: var(--surface-2);
}
.product-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.12);
}
.product-card .pc-id {
  font-weight: 600;
  font-size: 13px;
  word-break: break-all;
}
.product-card .pc-url {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.product-card .pc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}
.product-card .pc-time {
  font-size: 10px;
  color: var(--text-light);
  margin-left: auto;
}

/* Detail in products view */
.detail-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.detail-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.detail-url {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}
.detail-url a {
  color: var(--info);
  text-decoration: none;
}
.detail-url a:hover {
  text-decoration: underline;
}
.detail-head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.detail-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.detail-stats {
  display: flex;
  gap: 28px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
}
.detail-stats .ds-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}
.detail-stats .ds-value {
  font-size: 16px;
  font-weight: 700;
}
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
}
.tab {
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border: none;
  background: transparent;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.12s;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-body {
  padding: 14px 22px 22px;
}

.captures-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.captures-table th {
  text-align: left;
  padding: 8px 10px;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
.captures-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.captures-table tr:hover td {
  background: var(--surface-2);
}
.captures-table .actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.reviews {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.review {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.review-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.review-author {
  font-weight: 600;
  font-size: 13px;
}
.review-stars {
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 1px;
}
.review-comment {
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.45;
}
.review-media {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.review-media a {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-3);
}
.review-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.review-media a:hover img {
  transform: scale(1.05);
}

/* ================ Empty state ================ */
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
}
.empty-illustration {
  margin: 0 auto 14px;
  width: 80px;
  height: 80px;
  color: var(--text-light);
  opacity: 0.5;
}
.empty-illustration svg {
  width: 100%;
  height: 100%;
}
.empty-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.empty-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ================ Modal ================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease;
}
.modal-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}
.modal-root .modal {
  pointer-events: auto;
}
.modal.closing .modal-backdrop,
.modal.closing .modal-card {
  animation: fadeOut 0.13s ease forwards;
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.2s ease;
  border: 1px solid var(--border);
}
.modal-card-sm {
  max-width: 460px;
}
.modal-card-md {
  max-width: 640px;
}
.modal-card-lg {
  max-width: 900px;
}
.modal-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--surface-2);
}
.modal-foot .btn {
  min-width: 92px;
  justify-content: center;
}
.dialog-body-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
}
.cooldown-box {
  margin-top: 16px;
  padding: 16px;
  border-radius: 14px;
  text-align: center;
  background:
    radial-gradient(120% 120% at 50% 0%,
      rgba(255, 106, 0, 0.14), rgba(255, 106, 0, 0.04) 60%, transparent);
  border: 1px solid rgba(255, 106, 0, 0.28);
}
.cooldown-label {
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary, #9ca3af);
  margin-bottom: 6px;
}
.cooldown-clock {
  font-family: "Sora", ui-monospace, monospace;
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #ff8a1c;
  text-shadow: 0 0 18px rgba(255, 106, 0, 0.45);
}
.dev-settings-divider {
  margin: 16px 0 4px;
  padding-top: 14px;
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--primary, #ff8a1c);
}
.dev-settings-form .dev-check {
  margin-top: 10px;
}
.ar-dev-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.ar-dev-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.ar-dev-row:hover {
  border-color: var(--primary, #ff8a1c);
  background: rgba(255, 138, 28, 0.06);
}
.ar-dev-row:has(input:checked) {
  border-color: var(--primary, #ff8a1c);
  background: rgba(255, 138, 28, 0.1);
}
.ar-dev-row input {
  margin: 0;
  flex: 0 0 auto;
}
.ar-dev-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.badge.tk-exp-soon {
  background: rgba(255, 170, 30, 0.16);
  color: #ffb648;
  border: 1px solid rgba(255, 170, 30, 0.4);
}
.badge.tk-exp-bad {
  background: rgba(255, 70, 70, 0.16);
  color: #ff7a7a;
  border: 1px solid rgba(255, 70, 70, 0.42);
}

/* ---- App status strip (credit card + issues) ---- */
.app-status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 16px;
}
.ass-credit {
  flex: 0 0 auto;
  min-width: 240px;
  padding: 12px 16px;
  border-radius: 14px;
  background:
    radial-gradient(120% 120% at 0% 0%,
      rgba(255, 106, 0, 0.12), rgba(255, 255, 255, 0.02) 60%);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.ass-credit.is-frozen {
  border-color: rgba(255, 70, 70, 0.42);
  background: radial-gradient(120% 120% at 0% 0%,
    rgba(255, 70, 70, 0.14), rgba(255, 255, 255, 0.02) 60%);
}
.ass-credit-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.ass-credit-num {
  font-family: "Sora", sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #ff8a1c;
  font-variant-numeric: tabular-nums;
}
.ass-credit.is-frozen .ass-credit-num { color: #ff7a7a; }
.ass-credit-total { font-size: 12px; color: var(--text-secondary, #9ca3af); }
.ass-credit-bar {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  margin: 8px 0 6px;
  overflow: hidden;
}
.ass-credit-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #ff6a00, #ff8a1c);
}
.ass-credit-reset { font-size: 11.5px; color: var(--text-secondary, #9ca3af); }
.ass-credit-reset b { color: #fff; font-variant-numeric: tabular-nums; }
.ass-issues {
  flex: 1 1 220px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: center;
}
.ass-issue {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid transparent;
  align-self: center;
}
.ass-issue.ass-ok {
  color: var(--success, #4ade80);
  background: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.3);
}
.ass-issue.ass-credit,
.ass-issue.ass-failed,
.ass-issue.ass-captcha {
  color: #ff7a7a;
  background: rgba(255, 70, 70, 0.12);
  border-color: rgba(255, 70, 70, 0.32);
}
.ass-issue.ass-offline {
  color: #ffb648;
  background: rgba(255, 170, 30, 0.12);
  border-color: rgba(255, 170, 30, 0.32);
}
.ass-issue.ass-noai {
  color: #ff7a7a;
  background: rgba(255, 70, 70, 0.12);
  border-color: rgba(255, 70, 70, 0.32);
}
.badge.tk-no-ai {
  background: rgba(255, 70, 70, 0.16);
  color: #ff7a7a;
  border: 1px solid rgba(255, 70, 70, 0.42);
}
.modal-dialog .modal-body {
  padding: 18px 22px;
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.55;
}
.modal-dialog .modal-body b {
  color: var(--text);
  font-weight: 700;
}
.modal-dialog .modal-body p {
  margin: 0 0 8px;
}
.modal-dialog .modal-body p:last-child {
  margin: 0;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}
.modal-body {
  padding: 16px 20px;
  overflow: auto;
}
.modal-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.json-pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 8px;
  font-size: 11.5px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  overflow: auto;
  max-height: 60vh;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
.json-pre .k {
  color: #f9a8d4;
}
.json-pre .s {
  color: #86efac;
}
.json-pre .n {
  color: #fde68a;
}
.json-pre .b {
  color: #93c5fd;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ================ Toast ================ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  min-width: 220px;
  animation: slideIn 0.2s ease;
}
.toast.success {
  border-left: 3px solid var(--success);
}
.toast.danger {
  border-left: 3px solid var(--danger);
}
.toast.info {
  border-left: 3px solid var(--info);
}
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
.toast.fade-out {
  animation: fadeOut 0.3s ease forwards;
}
@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

.muted {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}

/* ================ Theme toggle ================ */
.theme-toggle {
  width: 36px;
  height: 36px;
  position: relative;
}
.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  width: 16px;
  height: 16px;
  position: absolute;
  inset: 0;
  margin: auto;
  transition: transform 0.25s ease, opacity 0.2s ease;
}
:root[data-theme="light"] .theme-toggle .icon-moon,
:root:not([data-theme="dark"]) .theme-toggle .icon-moon {
  opacity: 0;
  transform: rotate(-40deg) scale(0.7);
}
:root[data-theme="dark"] .theme-toggle .icon-sun {
  opacity: 0;
  transform: rotate(40deg) scale(0.7);
}
:root[data-theme="dark"] .theme-toggle .icon-moon {
  opacity: 1;
  transform: rotate(0) scale(1);
  color: var(--gold);
}
:root[data-theme="light"] .theme-toggle .icon-sun {
  opacity: 1;
  transform: rotate(0) scale(1);
  color: var(--warning);
}

/* ================ Switch (toggle) ================ */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 24px;
  transition: background 0.2s ease;
}
.switch .slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.switch input:checked + .slider {
  background: var(--primary);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.toggle-row > label.switch {
  margin-top: 2px;
}
.toggle-label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toggle-label code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

/* ================ Skipped queue row ================ */
.queue-row.is-skipped {
  opacity: 0.65;
}
.queue-row.is-skipped .qr-url .qr-shop {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* ================ Reviews v2 (flat list per product) ================ */
.reviews-section {
  padding: 14px 22px 24px;
}
.reviews-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.reviews-head h3 {
  margin: 0;
  font-size: 15px;
}
.reviews-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.review-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.15s;
}
.review-card:hover {
  box-shadow: var(--shadow);
}
.review-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.rc-author-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.rc-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f4793f, var(--primary));
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.rc-author {
  font-weight: 600;
  font-size: 13px;
}
.rc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  margin-top: 2px;
}
.rc-stars {
  color: var(--gold);
  letter-spacing: 1px;
  font-size: 13px;
}
.rc-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}
.rc-comment {
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.review-reply {
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.review-reply b {
  color: var(--primary);
}
.rc-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 6px;
}
.rc-images a {
  display: block;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-3);
  aspect-ratio: 1 / 1;
}
.rc-images img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.rc-images a:hover img {
  transform: scale(1.05);
}
.rc-videos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.rc-video {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: black;
  display: flex;
  flex-direction: column;
}
.rc-video video {
  width: 100%;
  display: block;
  background: black;
  max-height: 240px;
}
.rc-video-meta {
  background: var(--surface-2);
  padding: 6px 8px;
  font-size: 11px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
}
.rc-video-meta a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.rc-video-meta a:hover {
  text-decoration: underline;
}

/* ================ Responsive ================ */
@media (max-width: 1100px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .queue-controls {
    grid-template-columns: 1fr;
  }
  .layout-products {
    grid-template-columns: 1fr;
  }
  .panel-list {
    max-height: 360px;
  }
  .queue-row,
  .queue-table-head {
    grid-template-columns: 40px 1fr 90px 60px 70px;
  }
  .queue-row .qr-progress,
  .queue-table-head > *:nth-child(5) {
    display: none;
  }
}
/* Off-canvas sidebar backdrop — only materialises on mobile (see below). */
.sidebar-backdrop { display: none; }

/* ============================================================
   Mobile / tablet  ≤ 900px
   The sidebar becomes an off-canvas drawer that slides in from
   the left over a dimmed backdrop. Content uses the full width.
   ============================================================ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 60;
    width: min(82vw, 300px);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
  }
  /* Drawer open. `sidebar-collapsed` no longer hides on mobile — the
     drawer is hidden by default and revealed only with `sidebar-open`. */
  .app.sidebar-open .sidebar {
    transform: translateX(0);
    margin-left: 0;
  }
  .app.sidebar-collapsed .sidebar { margin-left: 0; }

  .sidebar-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: var(--backdrop);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.15s ease;
  }

  .sidebar-toggle { display: inline-flex !important; }

  /* Topbar: keep the hamburger + title readable, trim the rest. */
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar h2 { font-size: 13px; }
  .status-cluster #bots-summary-text { display: none; }
  .search { width: 150px; }

  .content { padding: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }

  /* All card grids collapse to a single column. */
  .bots-grid,
  .tk-app-grid,
  .dev-grid { grid-template-columns: 1fr; }

  /* Section headers stack their title + actions. */
  .tokens-section-head { flex-wrap: wrap; }
  .panel-head { flex-wrap: wrap; }
}

/* ============================================================
   Phones  ≤ 600px — tighter spacing, full-width modals & buttons.
   ============================================================ */
@media (max-width: 600px) {
  :root { --topbar-height: 50px; }

  .content { padding: 10px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 10px; }
  .stat-value { font-size: 17px; }

  /* Hide the live/connecting status pills to save room; the realtime
     dot stays as the single connectivity hint. */
  .status-cluster #status-text { display: none; }
  .search { display: none; }

  /* Modals become near full-screen bottom-anchored sheets. */
  .modal { padding: 0; align-items: flex-end; }
  .modal-card,
  .modal-card-sm,
  .modal-card-md,
  .modal-card-lg {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
  }
  .modal-head { padding: 12px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 12px 16px; flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; min-width: 0; }

  /* Touch-friendly controls. */
  .nav-item { padding: 11px 12px; font-size: 14px; }
  .btn { min-height: 40px; }
  .btn-icon-only { min-height: 38px; min-width: 38px; }
  input, select, textarea, .input { font-size: 16px; } /* avoid iOS zoom */
}

@media (max-width: 460px) {
  .stats { grid-template-columns: 1fr; }
  .topbar h2 { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================ Bots view ============================ */
.bots-toolbar {
  margin-bottom: 16px;
}
.bots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 12px;
}
.bot-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
  position: relative;
}
/* hover effect removed — card stays static when pointed at */
.bc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.bc-name-block {
  min-width: 0;
  flex: 1;
}
.bc-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bc-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.bc-dot.on {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.18);
  animation: pulse-dot 2s infinite;
}
.bc-dot.off {
  background: var(--danger);
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.18); }
  50% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0.08); }
}
.bc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-alt, rgba(0,0,0,0.04));
}
.badge-owner {
  color: #1d4ed8;
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.35);
}
.badge-legacy {
  color: #92400e;
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.4);
}
.bc-head-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.bc-token {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}
.bc-token-label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.bc-token-value {
  flex: 1;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bc-active {
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(59, 109, 255, 0.08);
  color: var(--info);
  border: 1px solid rgba(59, 109, 255, 0.2);
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  /* Fixed height (single line, ellipsis) so a running card never grows taller
     than an idle one — keeps every bot card the same height. */
  height: 35px;
  overflow: hidden;
  white-space: nowrap;
}
.bc-active > .muted:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Idle placeholder: same footprint, dimmed + dashed so it reads as "no job". */
.bc-active.is-idle {
  background: transparent;
  border-style: dashed;
  border-color: var(--border);
  color: var(--text-muted);
  justify-content: center;
}
.bc-active code {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  background: rgba(59, 109, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

/* Captcha pause banner — high-visibility, demands operator action. */
.bc-captcha {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 106, 0, 0.1);
  border: 1px solid rgba(255, 106, 0, 0.45);
  box-shadow: 0 0 0 1px rgba(255, 106, 0, 0.12), 0 8px 24px rgba(255, 106, 0, 0.15);
  color: var(--text);
  animation: bc-captcha-pulse 2s ease-in-out infinite;
}
@keyframes bc-captcha-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 106, 0, 0.12), 0 8px 24px rgba(255, 106, 0, 0.12); }
  50% { box-shadow: 0 0 0 1px rgba(255, 106, 0, 0.35), 0 8px 30px rgba(255, 106, 0, 0.3); }
}
.bc-captcha-ico {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  color: var(--primary);
  margin-top: 1px;
}
.bc-captcha-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.bc-captcha-title { font-weight: 700; font-size: 13px; color: var(--primary-dark, var(--primary)); }
:root[data-theme="dark"] .bc-captcha-title { color: var(--primary-light, var(--primary)); }
.bc-captcha-msg { font-size: 12px; line-height: 1.4; color: var(--text-secondary, var(--text)); }
.bc-captcha-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 2px; font-size: 11px; }
.bc-captcha-link { color: var(--primary); font-weight: 600; text-decoration: none; }
.bc-captcha-link:hover { text-decoration: underline; }
.bc-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.bc-stat {
  text-align: center;
}
.bcs-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.bcs-lbl {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.bc-stat.running .bcs-num { color: var(--info); }
.bc-stat.done .bcs-num { color: var(--success); }
.bc-stat.failed .bcs-num { color: var(--danger); }
.bc-stat.skipped .bcs-num { color: var(--text-muted); }

/* Plain-language "usable links" summary under the queue stats. */
.bc-usable {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
  border: 1px solid var(--border);
}
.bc-usable-main {
  font-size: 12.5px;
  color: var(--text);
}
.bc-usable-ok {
  color: var(--success);
  font-size: 14px;
}
.bc-usable-sub {
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   App-token card variant
   Same skeleton as .bot-card, but instead of the 5-column queue
   stat strip we surface created / expiry / last-seen info.
   ============================================================ */
.app-token-card .bc-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.app-token-card .bc-info {
  text-align: center;
  min-width: 0;
}
.app-token-card .bci-lbl {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.app-token-card .bci-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-token-card .bc-info.is-soon .bci-val { color: var(--warning); }
.app-token-card .bc-info.is-expired .bci-val { color: var(--danger); }

/* Secondary line under the card title: which real device connected via the
   app (so the operator's chosen name AND the device are both visible). */
.bc-subname {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
}
.bc-subname svg {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  opacity: 0.8;
}
.bc-subname span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Live stats strip on the full-size App card (clips / target / flows). */
.app-token-card .app-stats {
  grid-template-columns: repeat(3, 1fr);
}
/* Key/value detail list (AI, device, app version, flows, last update). */
.app-kv {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0 2px;
}
.app-kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
}
.app-kv-k {
  color: var(--text-muted);
  flex: 0 0 auto;
}
.app-kv-v {
  font-weight: 600;
  color: var(--text);
  text-align: right;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Quick remote-control row on the card — sits above the manage/view footer. */
.app-token-card .dev-quick-actions {
  margin-top: 0;
}
.app-token-card .dev-quick-actions .btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 8px;
  font-size: 12px;
}
.app-token-card .tk-card-actions {
  margin-top: auto;
  padding-top: 6px;
}

/* Paired Extension token strip inside the unified bot card. */
.tk-kind-ext { background:#ede9fe; color:#5b21b6; padding:3px 8px; border-radius:99px; font-size:11px; font-weight:600; }
.tk-legacy { background:#fef3c7; color:#92400e; padding:3px 8px; border-radius:99px; font-size:11px; font-weight:600; }
.ext-strip {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--border, #d7d7e0);
  border-radius: 10px;
  background: rgba(124, 58, 237, 0.045);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ext-strip-empty {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  background: transparent;
}
.ext-strip-icon { font-size: 15px; }
.ext-strip-head {
  display: flex;
  align-items: center;
  gap: 7px;
}
.ext-strip-title { font-size: 12.5px; font-weight: 600; }
.ext-strip-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  flex-wrap: wrap;
}
.ext-state { color: var(--text-muted); font-weight: 600; }
.ext-state.is-on { color: var(--success); }
.ext-strip .btn { align-self: flex-start; }
.pair-tok-label { display:block; font-size:12.5px; font-weight:600; margin-bottom:4px; }
.modal-view-token .pair-tok-label + textarea { margin-bottom: 6px; }

/* Manage modal: App + Extension token lines (both viewable in one place). */
.tk-token-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.tk-token-line + .tk-token-line { border-top: 1px solid var(--border, #ececf2); }
.tk-token-tag {
  flex: 0 0 auto;
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  background: #dbeafe;
  color: #1e40af;
}
.tk-token-tag-ext { background: #ede9fe; color: #5b21b6; }
.tk-token-line .tk-token-value {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tk-token-line-empty { padding: 4px 0; }

.app-token-card.is-revoked {
  opacity: 0.65;
}
.app-token-card.is-revoked .bot-office { filter: grayscale(0.85); }
.app-token-card.is-revoked .bc-token-value { text-decoration: line-through; }

/* Optimistic remove: card collapses out the moment "ลบ" is confirmed,
   then revokeToken() actually removes the node 220ms later (matches the
   transition duration here). */
.app-token-card.is-removing {
  opacity: 0;
  transform: scale(0.94) translateY(-4px);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}

/* ----- Gemini key row on the App Token card -----
   Mirrors the .bc-token row directly above it so the two sit visually
   together as "credentials this device carries". The `.is-empty` state
   shows a dashed border so it's obvious that nothing is set yet. */
.bc-gemini {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}
.bc-gemini.is-empty {
  background: transparent;
  border-style: dashed;
  border-color: var(--border-strong, var(--border));
}
.bc-gemini-value {
  flex: 1;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.5px;
}
.bc-gemini.is-empty .bc-gemini-value {
  color: var(--text-muted);
  font-style: italic;
  letter-spacing: 0;
}
/* Tiny chips next to the masked key showing model + prompt-set status. */
.bc-gemini-model,
.bc-gemini-cfg {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.bc-gemini-model {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--primary) 28%, transparent);
}
.bc-gemini-cfg {
  background: color-mix(in srgb, var(--success) 14%, transparent);
  color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 28%, transparent);
}
.bc-gemini { flex-wrap: wrap; }
.ai-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.ai-chip {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.ai-chip.on {
  background: color-mix(in srgb, var(--success) 14%, transparent);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}
.ai-chip.off { color: var(--text-muted); border-style: dashed; opacity: 0.7; }

/* AI provider key fields inside the create/edit modal. */
.ai-providers { display: flex; flex-direction: column; gap: 10px; }
.ai-provider-block {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  background: var(--surface-2, transparent);
}
.ai-provider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.ai-provider-name { font-weight: 600; font-size: 12.5px; }
.ai-key-err {
  display: none;
  margin-top: 5px;
  font-size: 11px;
  color: var(--danger);
}
.ai-key-err.show { display: block; }
.text-input.input-error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 1px var(--danger);
}
.ai-provider-getkey { font-size: 11px; color: var(--primary); text-decoration: none; }
.ai-provider-getkey:hover { text-decoration: underline; }
.ai-provider-picks { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-provider-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  font-size: 12.5px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.ai-provider-pick.is-active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  font-weight: 600;
}
.ai-provider-pick input { accent-color: var(--primary); }

/* Device binding row (1 token = 1 device). */
.bc-bind {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  border: 1px solid var(--border);
}
.bc-bind.is-bound {
  background: color-mix(in srgb, var(--info) 10%, transparent);
  border-color: color-mix(in srgb, var(--info) 28%, transparent);
}
.bc-bind.is-unbound {
  background: transparent;
  border-style: dashed;
  border-color: var(--border-strong, var(--border));
}
.bc-bind-value {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bc-bind.is-unbound .bc-bind-value {
  color: var(--text-muted);
  font-style: italic;
}

/* ----- App Token create/edit modal form fields ----- */
.modal-body .form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.modal-body .form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.modal-body .form-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.modal-body .form-hint code {
  font-size: 11px;
  padding: 1px 4px;
  background: var(--surface-3);
  border-radius: 3px;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
}
/* Textarea variant of .text-input — used for the System Instruction
   and Prompt Template fields in the App Token modal. */
.modal-body textarea.text-input {
  width: 100%;
  resize: vertical;
  min-height: 64px;
  font-family: inherit;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-body textarea.app-gemini-prompt {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 12px;
}

/* ===== Remote Control device cards ===== */
.dev-grid > .empty { grid-column: 1 / -1; }
.dev-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--surface-2, var(--surface));
  border: 1px solid var(--border);
  border-radius: 12px;
}
.dev-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dev-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
}
.dev-dot.is-online {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 25%, transparent);
}
.dev-dot.is-offline { background: var(--text-muted); opacity: 0.5; }
.dev-name {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dev-state {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--st, var(--text-muted));
  background: color-mix(in srgb, var(--st, #888) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--st, #888) 30%, transparent);
}
.dev-progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3, rgba(127,127,127,0.15));
  overflow: hidden;
}
.dev-progress-bar {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}
.dev-progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}
.dev-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12.5px;
}
.dev-msg {
  font-size: 12px;
  color: var(--text);
  padding: 6px 8px;
  background: var(--surface-3, rgba(127,127,127,0.1));
  border-radius: 6px;
}
.dev-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.dev-actions .btn {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  padding: 7px 8px;
  justify-content: center;
}
.dev-actions .btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== In-card device block (Remote Control + Recorded Flows merged into
   each App Token card). Sits between the token info grid and the card
   actions. ===== */
.tk-device-block {
  margin-top: 4px;
  padding: 10px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tk-device-block.is-empty {
  border-style: dashed;
  gap: 4px;
}
.tk-dev-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tk-dev-count { margin-left: auto; font-size: 11.5px; }
.tk-dev-meta { font-size: 12px; color: var(--text); }
.tk-dev-hint { font-size: 11px; color: var(--text-muted); }
.tk-dev-flows {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text);
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.tk-dev-flows svg { color: var(--primary); flex-shrink: 0; }

/* Compact one-line device summary shown on the (shortened) token card. */
.tk-dev-mini-slot { margin-top: 2px; }
.tk-dev-mini {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.tk-dev-mini.is-empty { flex-direction: row; align-items: center; gap: 8px; }
.tk-dev-mini-top { display: flex; align-items: center; gap: 8px; }
.tk-dev-mini .tk-dev-count { margin-left: auto; font-size: 11.5px; }

/* Binding badges on the compact card head. */
.badge.tk-bound {
  background: color-mix(in srgb, var(--info) 16%, transparent);
  color: var(--info);
  border: 1px solid color-mix(in srgb, var(--info) 30%, transparent);
  padding: 2px 7px; border-radius: 99px; font-size: 11px; font-weight: 600;
}
.badge.tk-unbound {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong, var(--border));
  padding: 2px 7px; border-radius: 99px; font-size: 11px; font-weight: 600;
}

/* View-token modal: big selectable field for manual copy on non-HTTPS. */
.view-token-field {
  width: 100%;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-all;
  white-space: pre-wrap;
  resize: none;
  user-select: all;
  -webkit-user-select: all;
}

/* Manage modal: let the detail body scroll if it gets tall. */
.modal-token-detail .modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-token-detail .app-token-detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== Sectioned "manage app token" modal layout ===== */
.tk-modal-head { align-items: flex-start; }
.tk-modal-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tk-modal-title h3 { margin: 0; line-height: 1.2; }
.tk-modal-sub { font-size: 12px; color: var(--text-muted); }

.tk-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 10px);
  background: var(--surface-2, var(--surface));
  padding: 12px;
}
:root[data-theme="dark"] .tk-section {
  background: var(--glass-bg, rgba(255,255,255,0.03));
  border-color: var(--glass-border, var(--border));
}
.tk-section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.tk-section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-secondary, var(--text));
  margin-right: auto;
}
.tk-chip-ok {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--success) 14%, transparent);
  color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 28%, transparent);
}

/* Token row */
.tk-token-row { display: flex; align-items: center; gap: 8px; }
.tk-token-value {
  flex: 1;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0.5px;
  background: var(--surface-3, rgba(0,0,0,0.04));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* AI provider list */
.tk-ai-list { display: flex; flex-direction: column; gap: 8px; }
.tk-ai-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-3, transparent);
  font-size: 12.5px;
}
.tk-ai-row.is-empty { border-style: dashed; opacity: 0.75; }
.tk-ai-row.is-active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}
.tk-ai-name { font-weight: 600; flex: 0 0 auto; min-width: 86px; }
.tk-ai-active {
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--primary);
  color: #fff;
  flex: 0 0 auto;
}
.tk-ai-detail {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}
.tk-ai-detail code {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 11.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tk-ai-model {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--primary) 26%, transparent);
}

/* Device binding row */
.tk-bind-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.tk-bind-row.is-bound {
  border-color: color-mix(in srgb, var(--info) 30%, transparent);
  background: color-mix(in srgb, var(--info) 8%, transparent);
  color: var(--info);
}
.tk-bind-row.is-unbound { border-style: dashed; color: var(--text-muted); }
.tk-bind-value {
  flex: 1;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Meta info grid */
.tk-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.tk-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-3, rgba(0,0,0,0.03));
  border: 1px solid var(--border);
}
.tk-meta-lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); }
.tk-meta-val { font-size: 12.5px; font-weight: 600; color: var(--text); }
.tk-meta.is-expired .tk-meta-val { color: var(--danger); }
.tk-meta.is-soon .tk-meta-val { color: var(--warning, #d97706); }

/* Footer actions */
.tk-footer {
  display: flex;
  gap: 8px;
  padding-top: 2px;
}
.tk-footer .btn { flex: 1 1 0; justify-content: center; }

.btn.btn-sm { padding: 5px 10px; font-size: 12px; gap: 5px; flex: 0 0 auto; }

/* The device runtime block already has its own frame; drop it inside a section
   so we don't get a box-in-a-box. */
.tk-section > .tk-device-block {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
}

@media (max-width: 600px) {
  .tk-meta-grid { grid-template-columns: 1fr; }
  .tk-ai-name { min-width: 70px; }
}
.dev-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-top: 6px;
  cursor: pointer;
}
.dev-check input { width: 16px; height: 16px; }

@media (max-width: 600px) {
  .app-token-card .bc-info-grid { grid-template-columns: 1fr 1fr; }
}

.tk-app-grid > .empty {
  grid-column: 1 / -1;
}

.bc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  /* Stick the action bar to the bottom so when grid stretches cards to equal
     height (tallest in the row), every card's buttons line up. */
  margin-top: auto;
}
.bc-actions .btn {
  /* Grow to fill the row but never shrink below a readable width — this is
     what makes the row wrap into tidy lines instead of squashing the labels
     until they overlap. */
  flex: 1 1 auto;
  min-width: 96px;
  font-size: 12px;
  padding: 7px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
}
.bc-actions .btn svg {
  flex: 0 0 auto;
}
/* Icon-only buttons stay compact instead of stretching to an equal share. */
.bc-actions .btn-icon-only {
  flex: 0 0 auto;
  min-width: 0;
}
/* "ประวัติการใช้" sits full-width on its own row beneath the equal buttons. */
.bc-actions [data-bot-action="usage"] {
  flex: 0 0 100%;
}

/* Token-display block inside the "new bot" modal */
.token-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.token-code {
  flex: 1;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
  user-select: all;
}

/* Prompt input (single-line) */
.prompt-input,
.text-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.prompt-input:focus,
.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.15);
}

/* Add-links textarea inside modal */
.links-textarea {
  width: 100%;
  min-height: 180px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}
.links-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.15);
}

/* Mini queue list (inside view-bot-queue modal) */
.queue-mini-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 60vh;
  overflow: auto;
}
.queue-mini-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.2fr) 100px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}
.queue-mini-row:hover {
  border-color: var(--border-strong);
}
.qmr-id {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qmr-progress {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 720px) {
  .bots-grid {
    grid-template-columns: 1fr;
  }
  .queue-mini-row {
    grid-template-columns: 1fr 80px auto;
  }
  .queue-mini-row .qmr-progress {
    display: none;
  }
}

/* ============ Realtime / SSE indicator ============ */
.realtime-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--bg-soft);
}
.realtime-indicator::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}
.realtime-indicator.on::before {
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
  animation: rt-pulse 1.6s ease-out infinite;
}
.realtime-indicator.on {
  color: #22c55e;
}
@keyframes rt-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Bot card brief flash when a queue progress event arrives */
.bot-card.flash {
  animation: bot-card-flash 0.6s ease-out;
}
@keyframes bot-card-flash {
  0%   { box-shadow: 0 0 0 0 rgba(79, 124, 255, 0.4); }
  60%  { box-shadow: 0 0 0 6px rgba(79, 124, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(79, 124, 255, 0); }
}

/* ============ 8-bit office stage on every bot card ============
   Sleeping ↔ Working states drive the visual:
     .is-sleeping = bot stopped — character slumped at desk + Z's
     .is-working  = bot running — character at desk + Boss walking in
   Each card picks a deterministic worker from window.Sydear8bit.CHARACTERS
   so the same bot keeps the same employee across renders.            */
.bot-card { position: relative; }

.bot-office {
  position: relative;
  width: 100%;
  height: 88px;
  margin: 6px 0 8px 0;
  background:
    /* horizon */
    linear-gradient(180deg,
      #fde68a 0%,
      #fcd34d 28%,
      #fb923c 48%,
      #b45309 64%,
      #422006 65%,
      #1c1917 100%);
  border: 2px solid #1f2937;
  box-shadow:
    inset 0 0 0 2px #fef3c7,
    inset 0 -10px 0 0 rgba(0, 0, 0, 0.12);
  image-rendering: pixelated;
  overflow: hidden;
  user-select: none;
  z-index: 1;
}
.ofx-floor {
  position: absolute;
  inset: auto 0 0 0;
  height: 14px;
  background:
    repeating-linear-gradient(90deg,
      #44403c 0, #44403c 4px,
      #292524 4px, #292524 8px);
  border-top: 2px solid #0f172a;
}

.ofx-worker {
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 64px;
  height: 76px;
  transform: translateX(-50%);
  z-index: 2;
}
.bot-office.is-working .ofx-worker { animation: ofx-worker-bob 0.55s steps(2) infinite; }
.bot-office.is-sleeping .ofx-worker { animation: ofx-sleep-breath 2.4s ease-in-out infinite; }

.ofx-boss {
  position: absolute;
  right: 4px;
  bottom: 6px;
  width: 50px;
  height: 70px;
  z-index: 3;
  animation: ofx-boss-walk 6s ease-in-out infinite;
}
.bot-office.is-working .ofx-boss { animation: ofx-boss-walk 6s ease-in-out infinite; }

.ofx-label {
  position: absolute;
  top: 4px;
  left: 6px;
  display: flex;
  gap: 6px;
  align-items: center;
  font-family: "Press Start 2P", "Sarabun", system-ui, sans-serif;
  font-size: 8px;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 0 #1f2937;
  color: #fef3c7;
  z-index: 4;
}
.ofx-name { padding: 1px 4px; background: rgba(15, 23, 42, 0.75); border: 1px solid #fef3c7; }
.ofx-mood {
  padding: 1px 4px;
  border: 1px solid #1f2937;
  font-size: 7px;
}
.ofx-mood-work    { background: #bbf7d0; color: #14532d; }
.ofx-mood-happy   { background: #bbf7d0; color: #14532d; }
.ofx-mood-hungry  { background: #fde68a; color: #78350f; }
.ofx-mood-angry   { background: #fecaca; color: #7f1d1d; animation: ofx-shake 0.3s steps(2) infinite; }
.ofx-mood-sleepy  { background: #bae6fd; color: #075985; }
.ofx-mood-sleep   { background: #cbd5e1; color: #1e293b; }

.ch-svg { width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
.ch-bubble  { animation: ofx-bubble-bob 1.2s ease-in-out infinite; transform-origin: 14px 3px; }
.ch-z       { animation: ofx-z-rise 1.6s ease-in-out infinite; transform-origin: 14px 4px; }
.ch-z2      { animation-delay: 0.6s; opacity: 0.7; }

@keyframes ofx-worker-bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-1px); }
}
@keyframes ofx-sleep-breath {
  0%, 100% { transform: translateX(-50%) scaleY(1); }
  50%      { transform: translateX(-50%) scaleY(0.97); }
}
@keyframes ofx-boss-walk {
  /* Boss enters from the right, watches the worker for a few seconds, leaves. */
  0%   { transform: translateX(60px); opacity: 0; }
  10%  { transform: translateX(0);     opacity: 1; }
  70%  { transform: translateX(0);     opacity: 1; }
  85%  { transform: translateX(60px); opacity: 0; }
  100% { transform: translateX(60px); opacity: 0; }
}
@keyframes ofx-bubble-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-1px); }
}
@keyframes ofx-z-rise {
  0%   { transform: translate(0, 0); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translate(2px, -8px); opacity: 0; }
}
@keyframes ofx-shake {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(1px); }
}

/* Pop-in when the bot starts running — like a "Boss arrives, worker wakes". */
.bot-office.is-working { animation: ofx-stage-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes ofx-stage-pop {
  0%   { transform: scale(0.96); filter: brightness(1.4); }
  100% { transform: scale(1);    filter: brightness(1); }
}

@media (prefers-reduced-motion: reduce) {
  .bot-office .ofx-worker,
  .bot-office .ofx-boss,
  .bot-office .ch-bubble,
  .bot-office .ch-z { animation: none !important; }
}

@media (max-width: 480px) {
  .bot-office { height: 76px; }
  .ofx-worker { width: 56px; height: 64px; }
  .ofx-boss { width: 42px; height: 60px; }
}

/* ============================================================
   Premium futuristic theme  ·  cyber-luxury (orange / black / white)
   ------------------------------------------------------------
   Layered on top of the base tokens. Deep matte-black canvas with a
   soft ambient orange glow, glassmorphism panels (translucent +
   backdrop blur), glowing orange gradient primaries, clean white
   typography (Sora display + Sarabun for legible Thai body), and
   elegant rounded corners with soft cinematic shadows.
   ============================================================ */
:root {
  --display-font: "Sora", "Sarabun", system-ui, -apple-system, sans-serif;
  --body-font: "Sarabun", "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--body-font);
  letter-spacing: 0.1px;
}

/* Display headings — geometric, confident, tight tracking. */
h1, h2, h3, h4, .brand-title, .pixel-heading {
  font-family: var(--display-font);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.35;
}
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; }
.brand-title { font-size: 15px; font-weight: 800; letter-spacing: 0.2px; }

/* ---- Ambient cyber-luxury glow behind everything ---- */
.app::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(900px 620px at 86% -8%, rgba(255, 106, 0, 0.10), transparent 60%),
    radial-gradient(720px 600px at -10% 112%, rgba(255, 138, 28, 0.07), transparent 62%);
}
:root[data-theme="dark"] .app::before {
  background:
    radial-gradient(1000px 720px at 88% -10%, rgba(255, 106, 0, 0.16), transparent 58%),
    radial-gradient(820px 720px at -12% 112%, rgba(255, 138, 28, 0.10), transparent 60%),
    radial-gradient(620px 620px at 50% 122%, rgba(255, 106, 0, 0.06), transparent 60%);
}

/* ---- Buttons ---- */
.btn {
  border-radius: var(--radius);
  font-weight: 600;
  transition: all 0.18s ease;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px rgba(255, 106, 0, 0.32);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  box-shadow: 0 10px 26px rgba(255, 106, 0, 0.46);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

/* Glass secondary buttons in the dark (premium) theme. */
:root[data-theme="dark"] .btn:not(.btn-primary):not(.btn-control) {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--glass-border);
  backdrop-filter: blur(6px);
}
:root[data-theme="dark"] .btn:not(.btn-primary):not(.btn-control):hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 106, 0, 0.45);
}

/* ---- Navigation ---- */
.nav-item {
  border-radius: var(--radius);
  border-left: 3px solid transparent;
  transition: all 0.18s ease;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active {
  border-left-color: var(--primary);
  background: var(--primary-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 106, 0, 0.25);
}
:root[data-theme="dark"] .nav-item.active {
  box-shadow: inset 0 0 0 1px rgba(255, 106, 0, 0.4),
    0 0 18px rgba(255, 106, 0, 0.18);
}

/* ---- Glass surfaces: panels, cards, modals ---- */
.panel,
.token-card,
.modal-card {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .token-card,
:root[data-theme="dark"] .modal-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px) saturate(120%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ---- Bot cards ---- */
.bot-card {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
/* hover effect removed — card stays static when pointed at */
:root[data-theme="dark"] .bot-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px) saturate(120%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.bot-card.is-working {
  background-image: linear-gradient(180deg, rgba(255, 106, 0, 0.12) 0%, transparent 42%);
}

/* ---- Bot status hero (replaces the cartoon office) ---- */
.bc-hero {
  margin: 12px 0 4px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}
:root[data-theme="dark"] .bc-hero {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--glass-border);
}
.bc-hero-main {
  display: flex;
  align-items: center;
  gap: 12px;
}
.bc-hero-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 12px;
  color: #fff;
  background: var(--text-light);
}
.bc-hero-icon svg { width: 20px; height: 20px; }
.bc-hero-text { flex: 1; min-width: 0; }
.bc-hero-state {
  font-family: var(--display-font);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  color: var(--text);
}
.bc-hero-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.bc-hero-sub.is-fail {
  color: var(--danger, #ff5a5a);
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bc-hero-pct {
  font-family: var(--display-font);
  font-weight: 800;
  font-size: 22px;
  line-height: 1;
  color: var(--text);
  letter-spacing: -0.02em;
}
.bc-hero-pct span { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-left: 1px; }
.bc-hero-bar {
  margin-top: 12px;
  height: 6px;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.18);
  overflow: hidden;
}
.bc-hero-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  transition: width 0.5s cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* State accents */
.bc-hero-running .bc-hero-icon {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  box-shadow: 0 0 0 1px rgba(255, 106, 0, 0.35), 0 6px 18px rgba(255, 106, 0, 0.4);
  animation: bcHeroPulse 1.8s ease-in-out infinite;
}
.bc-hero-running { border-color: rgba(255, 106, 0, 0.3); }
.bc-hero-done .bc-hero-icon {
  background: linear-gradient(135deg, var(--success), #4ade80);
  box-shadow: 0 6px 18px rgba(34, 197, 94, 0.35);
}
.bc-hero-done .bc-hero-bar-fill { background: linear-gradient(90deg, var(--success), #4ade80); }
.bc-hero-idle .bc-hero-icon {
  background: rgba(127, 127, 127, 0.28);
  color: var(--text-muted);
}
@keyframes bcHeroPulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 106, 0, 0.35), 0 6px 18px rgba(255, 106, 0, 0.35); }
  50%      { box-shadow: 0 0 0 1px rgba(255, 106, 0, 0.5), 0 8px 26px rgba(255, 106, 0, 0.6); }
}
.bc-hero-failed .bc-hero-icon {
  background: linear-gradient(135deg, var(--danger), #fb7185);
  box-shadow: 0 6px 18px rgba(248, 113, 113, 0.32);
}
.bc-hero-failed .bc-hero-bar-fill { background: linear-gradient(90deg, var(--danger), #fb7185); }

/* App-token card uses the same hero, but offline devices read calmer. */
.tk-hero.is-offline { opacity: 0.9; }
.tk-hero.is-offline .bc-hero-icon {
  background: rgba(127, 127, 127, 0.22);
  color: var(--text-muted);
  box-shadow: none;
  animation: none;
}
.tk-hero.is-offline .bc-hero-state { color: var(--text-muted); }

/* Keep meta text legible on any card state. */
.bot-card .bc-meta .muted,
.bot-card .bc-active .muted {
  color: var(--text-muted);
  font-weight: 500;
  opacity: 1;
}
[data-theme="dark"] .bot-card .bc-meta .muted,
[data-theme="dark"] .bot-card .bc-active .muted {
  color: #cbd2da;
  opacity: 0.9;
}

/* ---- Form inputs ---- */
.text-input, .form-row input, .form-row select, .form-row textarea,
input[type="text"], input[type="number"], input[type="password"],
input[type="email"], select, textarea {
  border-radius: var(--radius);
  font-family: var(--body-font);
}
:root[data-theme="dark"] .text-input,
:root[data-theme="dark"] .form-row input,
:root[data-theme="dark"] .form-row select,
:root[data-theme="dark"] .form-row textarea,
:root[data-theme="dark"] input[type="text"],
:root[data-theme="dark"] input[type="number"],
:root[data-theme="dark"] input[type="password"],
:root[data-theme="dark"] input[type="email"],
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
}
.text-input:focus, .form-row input:focus, .form-row select:focus,
.form-row textarea:focus, input[type="text"]:focus, input[type="number"]:focus,
input[type="password"]:focus, input[type="email"]:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  outline: none;
}

/* ---- Pills & badges ---- */
.badge, .pill, .status-pill {
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* ---- Brand & chrome ---- */
.brand-logo:not(.brand-logo-img) {
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  box-shadow: 0 6px 20px rgba(255, 106, 0, 0.4);
}
.brand-logo-img {
  border-radius: 12px;
  image-rendering: auto;
  box-shadow: 0 6px 20px rgba(255, 106, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.sidebar-brand { border-bottom: 1px solid var(--border); }
.sidebar { border-right: 1px solid var(--border); }
.topbar  { border-bottom: 1px solid var(--border); }

:root[data-theme="dark"] .topbar {
  background: rgba(8, 8, 8, 0.72);
  backdrop-filter: blur(16px) saturate(120%);
  border-bottom: 1px solid var(--glass-border);
}
:root[data-theme="dark"] .sidebar {
  background: rgba(9, 9, 9, 0.74);
  backdrop-filter: blur(16px) saturate(120%);
  border-right: 1px solid var(--glass-border);
}

.tab-btn { font-family: var(--display-font); border-radius: var(--radius); }

/* =====================================================================
   NEON 3D — bot cards (หน้า "บอท")  · dark theme only
   - รอบกรอบนีออนหมุน, hover ยก/เอียงแบบ 3D, ตัวเลข/จุดสถานะเรืองแสง
   ===================================================================== */
@property --neon-ang {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@keyframes neon-spin { to { --neon-ang: 360deg; } }
@keyframes neon-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

.tk-app-grid {
  perspective: 1500px;
  gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
}

:root[data-theme="dark"] .app-token-card.bot-card {
  background:
    radial-gradient(135% 120% at 0% 0%, rgba(255, 106, 0, 0.12), transparent 46%),
    radial-gradient(135% 120% at 100% 0%, rgba(120, 90, 255, 0.10), transparent 46%),
    linear-gradient(180deg, #16161f, #0c0c11);
  border: 1px solid rgba(255, 138, 28, 0.22);
  border-radius: 18px;
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.28s cubic-bezier(0.2, 0.7, 0.2, 1),
              box-shadow 0.28s ease, border-color 0.28s ease;
}

/* rotating neon outline (masked ring) */
:root[data-theme="dark"] .app-token-card.bot-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px;
  background: conic-gradient(from var(--neon-ang),
    #ff6a00, #ffb648, #7a5bff, #00e0ff, #ff6a00);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0.38;
  z-index: 0;
  pointer-events: none;
  animation: neon-spin 7s linear infinite;
}
/* keep all card content above the neon ring */
:root[data-theme="dark"] .app-token-card.bot-card > * {
  position: relative;
  z-index: 1;
}

/* hover effect removed — card stays static when pointed at */
/* working card gets a permanent gentle float + brighter ring */
:root[data-theme="dark"] .app-token-card.bot-card.is-working {
  animation: neon-float 4.5s ease-in-out infinite;
}
:root[data-theme="dark"] .app-token-card.bot-card.is-working::before {
  opacity: 0.8;
  animation-duration: 4s;
}

/* neon title + status dot */
:root[data-theme="dark"] .app-token-card .bc-name > span:last-child {
  text-shadow: 0 0 12px rgba(255, 138, 28, 0.55);
}
:root[data-theme="dark"] .app-token-card .bc-dot.on {
  background: #2bff88;
  box-shadow: 0 0 12px #2bff88, 0 0 0 4px rgba(43, 255, 136, 0.16);
}
:root[data-theme="dark"] .app-token-card .bc-dot.off {
  box-shadow: 0 0 9px rgba(255, 90, 90, 0.65);
}

/* glassy hero + glow while running */
:root[data-theme="dark"] .app-token-card .bc-hero {
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  border: 1px solid rgba(255, 255, 255, 0.07);
}
:root[data-theme="dark"] .app-token-card .bc-hero-running {
  border-color: rgba(255, 106, 0, 0.5);
  box-shadow: inset 0 0 26px rgba(255, 106, 0, 0.14);
}
:root[data-theme="dark"] .app-token-card .bc-hero-running .bc-hero-icon {
  box-shadow: 0 0 18px rgba(255, 106, 0, 0.75);
}

/* glowing stat numbers */
:root[data-theme="dark"] .app-token-card .ext-stats .ext-stat {
  background: rgba(255, 255, 255, 0.035);
  border-color: rgba(255, 255, 255, 0.07);
}
:root[data-theme="dark"] .app-token-card .ext-stat-num { text-shadow: 0 0 12px currentColor; }
:root[data-theme="dark"] .app-token-card .app-stats .bcs-num { text-shadow: 0 0 10px currentColor; }

/* neon primary buttons (เพิ่ม link ฯลฯ) */
:root[data-theme="dark"] .app-token-card .btn-primary {
  background: linear-gradient(180deg, #ff7d20, #ff5e00);
  border: none;
  box-shadow: 0 0 14px rgba(255, 106, 0, 0.5);
}
:root[data-theme="dark"] .app-token-card .btn-primary:hover {
  box-shadow: 0 0 24px rgba(255, 106, 0, 0.9);
  filter: brightness(1.06);
}

@media (prefers-reduced-motion: reduce) {
  :root[data-theme="dark"] .app-token-card.bot-card::before,
  :root[data-theme="dark"] .app-token-card.bot-card.is-working { animation: none; }
}

/* App-token QR (scan to log in from the app). Generated locally by qr.js. */
.token-qr { display:flex; flex-direction:column; align-items:center; gap:8px; margin-top:14px; }
.token-qr-box { background:#fff; padding:10px; border-radius:12px; border:1px solid var(--border, #e2e5ea); box-shadow:0 1px 3px rgba(0,0,0,.08); line-height:0; }
.token-qr-box svg { display:block; width:200px; height:200px; }
.token-qr-cap { font-size:12px; text-align:center; max-width:260px; line-height:1.4; }
