/* ── Reset & variables ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0f14;
  --surface:   #161a22;
  --surface2:  #1e2330;
  --border:    #252b3a;
  --accent:    #4f8ef7;
  --green:     #2ecc71;
  --orange:    #f39c12;
  --red:       #e74c3c;
  --purple:    #6c63ff;
  --text:      #dce3f0;
  --muted:     #6b7590;
  --sidebar-w: 210px;
  --topbar-h:  54px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }
.main   { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform .25s ease;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 190;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo-icon { font-size: 22px; color: var(--accent); flex-shrink: 0; }
.logo-text  { font-weight: 700; font-size: 14px; color: var(--text); line-height: 1.2; }
.logo-sub   { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

.nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover  { color: var(--text); background: var(--surface2); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: rgba(79,142,247,.08); }
.nav-item span   { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.live { background: var(--green); box-shadow: 0 0 6px var(--green); }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  flex-shrink: 0;
  gap: 8px;
}
.topbar-left  { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.page-title   { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Hamburger ────────────────────────────────────────────────────────────── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  width: 22px; height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: .2s;
}

/* ── Content ──────────────────────────────────────────────────────────────── */
.content { flex: 1; overflow-y: auto; padding: 20px; -webkit-overflow-scrolling: touch; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}
.card-title {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin-bottom: 14px;
}

/* ── Stat grid ────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-label  { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; }
.stat-value  { font-size: 26px; font-weight: 700; margin: 4px 0; line-height: 1; }
.stat-sub    { font-size: 11px; color: var(--muted); }
.stat-accent { color: var(--accent); }
.stat-green  { color: var(--green);  }
.stat-orange { color: var(--orange); }

/* ── Progress ─────────────────────────────────────────────────────────────── */
.progress-wrap { margin-top: 8px; }
.progress-bar-bg { height: 5px; background: var(--surface2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.progress-bar-fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s ease; }
.progress-bar-fill.over { background: var(--green); }

/* ── Pulse dots ───────────────────────────────────────────────────────────── */
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.pulse-green {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(46,204,113,.6);
  animation: pulse-anim 1.8s infinite;
}
.pulse-red  { background: var(--red); }
.pulse-grey { background: var(--muted); }
@keyframes pulse-anim {
  0%   { box-shadow: 0 0 0 0 rgba(46,204,113,.6); }
  70%  { box-shadow: 0 0 0 7px rgba(46,204,113,0); }
  100% { box-shadow: 0 0 0 0 rgba(46,204,113,0); }
}

/* ── Worker grid (monitor) ────────────────────────────────────────────────── */
.worker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.worker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  transition: border-color .2s;
}
.worker-card.card-running { border-color: rgba(46,204,113,.3); }
.worker-card.card-offline  { border-color: rgba(231,76,60,.2); opacity: .7; }
.wcard-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.wcard-name   { font-weight: 600; font-size: 14px; }
.wcard-activity {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 10px;
}
.wcard-field   { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.wcard-label   { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); min-width: 52px; flex-shrink: 0; }
.wcard-val     { font-size: 12px; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wcard-url     { font-family: 'Cascadia Code','Consolas',monospace; font-size: 11px; color: var(--muted); }
.action-tag    { color: var(--orange); font-weight: 500; }
.wcard-footer  { display: flex; flex-direction: column; }
.wcard-visits  { display: flex; align-items: baseline; gap: 4px; }

/* ── Worker rows (workers page) ───────────────────────────────────────────── */
.worker-row-header {
  display: flex; align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.worker-config summary { list-style: none; cursor: pointer; user-select: none; }
.worker-config summary::-webkit-details-marker { display: none; }
.worker-config-body { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 8px; }

/* ── Proxy checkboxes ─────────────────────────────────────────────────────── */
.proxy-checks { display: flex; flex-wrap: wrap; gap: 8px; }
.proxy-check  {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px;
  cursor: pointer; transition: border-color .15s;
  font-size: 13px; user-select: none;
}
.proxy-check:has(input:checked) { border-color: var(--accent); background: rgba(79,142,247,.1); }
.proxy-check input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }

/* ── Mini worker rows (overview) ──────────────────────────────────────────── */
.mini-worker-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid var(--border); gap: 8px;
}
.mini-worker-row:last-child { border-bottom: none; }

/* ── Shop rows ────────────────────────────────────────────────────────────── */
.shop-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.shop-row:last-child { border-bottom: none; }
.shop-name  { min-width: 120px; font-weight: 500; font-size: 13px; }
.shop-prog  { flex: 1; }
.shop-count { font-size: 12px; color: var(--muted); min-width: 64px; text-align: right; flex-shrink: 0; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { border-bottom: 1px solid var(--border); }
th { padding: 8px 10px; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-running     { background: rgba(46,204,113,.15);  color: var(--green);  }
.badge-stopped     { background: rgba(107,117,144,.15); color: var(--muted);  }
.badge-offline     { background: rgba(231,76,60,.15);   color: var(--red);    }
.badge-online      { background: rgba(79,142,247,.15);  color: var(--accent); }
.badge-success     { background: rgba(46,204,113,.15);  color: var(--green);  }
.badge-error       { background: rgba(231,76,60,.15);   color: var(--red);    }
.badge-time        { background: var(--surface2); color: var(--muted); font-size: 12px; padding: 3px 10px; }
.badge-dataimpulse { background: rgba(79,142,247,.12);  color: var(--accent); }
.badge-webshare    { background: rgba(243,156,18,.12);  color: var(--orange); }
.badge-vpn         { background: rgba(108,99,255,.18);  color: var(--purple); }
.badge-none        { background: rgba(107,117,144,.12); color: var(--muted);  }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 6px; border: none;
  cursor: pointer; font-size: 13px; font-weight: 500;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  min-height: 36px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent);   color: #fff; }
.btn-success { background: var(--green);    color: #fff; }
.btn-danger  { background: var(--red);      color: #fff; }
.btn-ghost   { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-sm      { padding: 5px 10px; font-size: 12px; min-height: 30px; }
.btn:hover   { opacity: .88; }
.btn-group   { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
label { font-size: 12px; font-weight: 500; color: var(--muted); }

input[type=text], input[type=number], input[type=password],
input[type=url], select, textarea {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 9px 10px; border-radius: 6px;
  font-size: 13px; outline: none; width: 100%; transition: border-color .15s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=range] { accent-color: var(--accent); width: 100%; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-val { min-width: 32px; text-align: right; font-size: 13px; color: var(--accent); font-weight: 600; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab-btn {
  padding: 8px 14px; background: none; border: none;
  color: var(--muted); font-size: 13px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all .15s; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Toggle ───────────────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 8px; }
.toggle { position: relative; display: inline-block; width: 38px; height: 20px; flex-shrink: 0; }
.toggle input { display: none; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 99px; cursor: pointer; transition: .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 14px; height: 14px; left: 2px; top: 2px;
  background: var(--muted); border-radius: 50%; transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: #fff; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.65); z-index: 300;
  align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px 14px 0 0;
  padding: 24px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity:0; } to { transform: none; opacity:1; } }
.modal-title  { font-size: 15px; font-weight: 600; margin-bottom: 18px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Log stream ───────────────────────────────────────────────────────────── */
.log-stream {
  font-family: 'Cascadia Code','Consolas',monospace; font-size: 12px;
  background: #0a0c10; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px;
  height: 280px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
  -webkit-overflow-scrolling: touch;
}
.log-line { display: flex; gap: 8px; align-items: baseline; animation: fadeIn .2s ease; min-width: 0; }
.log-ts      { color: var(--muted); min-width: 60px; flex-shrink: 0; }
.log-shop    { color: var(--accent); min-width: 90px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-worker  { color: #9b59b6; min-width: 70px; flex-shrink: 0; }
.log-dur     { color: var(--orange); min-width: 42px; flex-shrink: 0; }
.log-ip      { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; }
.log-status-success { color: var(--green); flex-shrink: 0; }
.log-status-error   { color: var(--red);   flex-shrink: 0; }
@keyframes fadeIn { from { opacity:0; transform:translateY(3px); } to { opacity:1; } }

/* ── Grid helpers ─────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.section-head    { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.section-title   { font-size: 13px; font-weight: 600; }
.mt-4            { margin-top: 4px; }
.mt-16           { margin-top: 16px; }
.mt-24           { margin-top: 24px; }
.mb-16           { margin-bottom: 16px; }
.flex            { display: flex; }
.gap-8           { gap: 8px; }
.gap-12          { gap: 12px; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted      { color: var(--muted); font-size: 12px; }
.divider         { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 8px; z-index: 999;
}
.toast {
  padding: 10px 16px; border-radius: 8px; font-size: 13px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); max-width: 280px;
  animation: toastIn .2s ease;
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); }
@keyframes toastIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; } }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ══ RESPONSIVE ══════════════════════════════════════════════════════════════ */

/* Tablet: ≤ 900px */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .worker-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

/* Mobile: ≤ 640px */
@media (max-width: 640px) {

  /* Sidebar becomes slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open { display: block; }
  .sidebar-close { display: block; }
  .hamburger     { display: flex; }

  /* Content fills full width */
  .layout { display: block; height: 100vh; }
  .main   { height: 100vh; }

  /* Smaller padding */
  .content { padding: 12px; }
  .card    { padding: 14px; }

  /* Stat grid 2 cols on phone */
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 22px; }

  /* Worker grid single col */
  .worker-grid { grid-template-columns: 1fr; }

  /* Table: horizontally scrollable */
  .table-wrap { border: 1px solid var(--border); border-radius: 8px; }

  /* Topbar: hide clock on very small */
  #clock { display: none; }

  /* Export/import btn text - icon only on mobile */
  .topbar-right .btn-sm { padding: 6px 8px; font-size: 12px; }

  /* Form grid single col */
  .form-grid { grid-template-columns: 1fr; }

  /* Modal full sheet */
  .modal { border-radius: 14px 14px 0 0; }
  .modal-backdrop { align-items: flex-end; }

  /* Hide some table columns on mobile via class */
  .hide-mobile { display: none !important; }

  /* Worker row header stack */
  .worker-row-header { flex-direction: column; align-items: flex-start; }

  /* Proxy checks wrap */
  .proxy-checks { gap: 6px; }

  /* Log stream shorter */
  .log-stream { height: 200px; }

  /* Section head wrap */
  .section-head { flex-direction: column; align-items: flex-start; }
}

/* Very small: ≤ 380px */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
  .btn-group { gap: 4px; }
  .btn-sm { padding: 5px 7px; font-size: 11px; }
}

/* little "?" you hover for a quick explanation */
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; margin-left: 6px;
  background: rgba(79,142,247,.18); color: var(--accent);
  font-size: 10px; font-weight: 700; cursor: help; position: relative; vertical-align: middle;
}
.help::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: 150%; transform: translateX(-50%) translateY(6px);
  width: 260px; max-width: 70vw; background: #161b26; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; font-weight: 400; line-height: 1.5; text-align: left; white-space: normal;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .12s ease, transform .12s ease;
}
.help:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.help.rt::after { left: auto; right: 0; transform: translateX(0) translateY(6px); }
.help.rt:hover::after { transform: translateX(0) translateY(0); }

/* header LIVE switch (turn real shop visits on/off) */
.live-switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; margin-right: 4px; }
.live-switch input { display: none; }
.live-track {
  position: relative; width: 46px; height: 24px; border-radius: 99px;
  background: var(--red); transition: background .18s;
}
.live-knob {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.live-text { font-size: 11px; font-weight: 800; letter-spacing: .6px; color: var(--red); }
.live-switch.on .live-track { background: var(--green); }
.live-switch.on .live-knob { transform: translateX(22px); }
.live-switch.on .live-text { color: var(--green); }

/* device picker: one row per device = a tick + an engine dropdown */
.device-picker { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.device-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.device-chip {
  display: inline-flex; align-items: center; gap: 7px; min-width: 170px;
  padding: 8px 13px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); cursor: pointer; font-size: 13px; user-select: none;
}
.device-chip input { accent-color: var(--accent); cursor: pointer; margin: 0; }
.device-chip:has(input:checked) { border-color: var(--accent); background: rgba(79,142,247,.10); }
.device-engine {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text); font-size: 13px; min-width: 190px;
}
.device-engine:disabled { opacity: .55; }
