/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d0f14;
  --surface:     #161922;
  --surface2:    #1e2230;
  --border:      #2a2f3f;
  --text:        #e2e8f0;
  --text-muted:  #64748b;
  --accent:      #6366f1;
  --accent-dim:  #312e81;
  --green:       #22c55e;
  --green-dim:   #14532d;
  --red:         #ef4444;
  --red-dim:     #7f1d1d;
  --yellow:      #f59e0b;
  --yellow-dim:  #78350f;
  --header-h:    56px;
  --toggles-h:   48px;
  --radius:      8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 24px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .5px;
  color: #f8fafc;
}

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot--connected    { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot--disconnected { background: var(--text-muted); }

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 20px;
}

.stat-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.stat-label  { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value  { font-size: 18px; font-weight: 700; line-height: 1; }
.stat-value--fail { color: var(--red); }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.btn {
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn--start { background: var(--accent); color: #fff; }
.btn--start:hover:not(:disabled) { background: #818cf8; }
.btn--stop  { background: var(--red); color: #fff; }
.btn--stop:hover:not(:disabled)  { background: #f87171; }

.automation-status {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 55px;
}
.automation-status--running { color: var(--green); }

/* ── Toggles Bar ─────────────────────────────────────────────────────────── */
.toggles-bar {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  height: var(--toggles-h);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 20px;
  z-index: 99;
}

.toggles-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
}
.toggle-switch input { display: none; }

.toggle-track {
  width: 36px; height: 20px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform .2s;
}
.toggle-switch input:checked + .toggle-track { background: var(--accent); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(16px); }

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

/* ── Drop Zone ───────────────────────────────────────────────────────────── */
.drop-zone {
  margin-left: auto;
  padding: 6px 14px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(99,102,241,.07);
}
.file-label { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ── Board ───────────────────────────────────────────────────────────────── */
.board {
  position: fixed;
  top: calc(var(--header-h) + var(--toggles-h));
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ── Column ──────────────────────────────────────────────────────────────── */
.column {
  flex: 1;
  min-width: 160px;
  max-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.column--active  { border-color: var(--accent); }
.column--success { border-color: var(--green-dim); }
.column--fail    { border-color: var(--red-dim); }

.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.column-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}

.column--active  .column-title { color: #a5b4fc; }
.column--success .column-title { color: #86efac; }
.column--fail    .column-title { color: #fca5a5; }

.badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--surface2);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 20px;
  min-width: 24px;
  text-align: center;
}
.badge--fail { background: var(--red-dim); color: #fca5a5; }

.column-cards {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.column-cards::-webkit-scrollbar { width: 4px; }
.column-cards::-webkit-scrollbar-track { background: transparent; }
.column-cards::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: context-menu;
  transition: border-color .15s, background .15s;
  position: relative;
}
.card:hover { border-color: var(--accent); }

.card--uploading { border-color: var(--accent); animation: pulse-border 1.5s infinite; }
.card--failed    { border-color: var(--red-dim); }
.card--complete  { border-color: var(--green-dim); opacity: .75; }

@keyframes pulse-border {
  0%, 100% { border-color: var(--accent); }
  50%       { border-color: var(--accent-dim); }
}

.card-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.card-size {
  font-size: 10px;
  color: var(--text-muted);
}

.card-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
}
.card-badge--json    { background: rgba(99,102,241,.2); color: #a5b4fc; }
.card-badge--no-json { background: rgba(245,158,11,.15); color: #fcd34d; }

.card-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Empty Column ─────────────────────────────────────────────────────────── */
.empty-col {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60px;
  color: var(--text-muted);
  font-size: 11px;
  opacity: .5;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
}

/* ── Context Menu ─────────────────────────────────────────────────────────── */
.context-menu {
  position: fixed;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 0;
  min-width: 200px;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.context-menu.hidden { display: none; }

.context-menu-title {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 14px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
  margin-bottom: 4px;
}

.ctx-btn {
  display: block;
  width: 100%;
  padding: 7px 14px;
  background: none;
  border: none;
  text-align: left;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .1s;
}
.ctx-btn:hover { background: var(--border); }
.ctx-btn--danger { color: var(--red); }
.ctx-btn--danger:hover { background: var(--red-dim); }
.ctx-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Scrollbar (board) ────────────────────────────────────────────────────── */
.board::-webkit-scrollbar { height: 6px; }
.board::-webkit-scrollbar-track { background: var(--bg); }
.board::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  html, body {
    height: auto !important;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Header: auto height, wrap content */
  header {
    position: relative !important;
    height: auto !important;
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
  }
  .header-left { min-width: 0; flex: 1; }
  h1 { font-size: 14px; }
  .header-center {
    order: 3;
    width: 100%;
    gap: 10px;
    padding: 4px 0 2px;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .stat-group { flex-direction: row; gap: 6px; align-items: baseline; }
  .stat-label { font-size: 11px; }
  .stat-value { font-size: 16px; }
  .header-right { gap: 6px; }
  .btn { padding: 5px 10px; font-size: 12px; }

  /* Toggles bar: relative, wrap */
  .toggles-bar {
    position: relative !important;
    top: auto !important;
    height: auto !important;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
  }
  .toggles-label { width: 100%; }
  .drop-zone { margin-left: 0; width: 100%; text-align: center; }

  /* Board: full-width vertical stack, normal document flow */
  .board {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: visible !important;
    overflow-x: hidden !important;
    width: 100% !important;
    box-sizing: border-box;
    padding: 10px 12px;
    gap: 10px;
  }

  /* Columns: full width, compact height with scroll */
  .column {
    flex: none !important;
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box;
    max-height: none !important;
  }
  .column-cards {
    max-height: 200px;
    overflow-y: auto;
  }

  /* Cards */
  .card { padding: 8px 10px; }
  .card-name { font-size: 13px; white-space: normal; word-break: break-word; }

  /* Context menu: keep on screen */
  .context-menu { max-width: calc(100vw - 24px); }
}
