/* ─── DESIGN TOKENS ─────────────────────────────────────────────────────── */
:root {
  /* Palette — light mode */
  --bg:        #f5f6f8;
  --surface:   #ffffff;
  --surface2:  #f0f1f4;
  --surface3:  #e8eaed;
  --border:    #e2e4e9;
  --border2:   #d0d3db;

  /* Text */
  --text-primary:   #111318;
  --text-secondary: #4b5060;
  --text-tertiary:  #8a8fa8;

  /* Brand accent */
  --accent:         #c53f09;
  --accent-light:   #e8501a;
  --accent-dim:     rgba(197,63,9,0.08);

  /* Category colors — slightly deepened for light bg contrast */
  --cat1: #16a34a;  /* green  */
  --cat2: #d97706;  /* amber  */
  --cat3: #ea580c;  /* orange */
  --cat4: #7c3aed;  /* violet */
  --cat5: #dc2626;  /* red    */
  --cat6: #71717a;  /* zinc   */

  /* Spacing */
  --sp-xs:  4px;
  --sp-sm:  8px;
  --sp-md:  16px;
  --sp-lg:  24px;
  --sp-xl:  32px;

  /* Radius */
  --r-sm:   6px;
  --r-md:   10px;
  --r-lg:   14px;

  /* Shadow */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  padding: var(--sp-lg) var(--sp-md) 80px;
  -webkit-font-smoothing: antialiased;
  font-weight: 450;
}

/* ─── LAYOUT SHELL ──────────────────────────────────────────────────────── */
.shell {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-lg);
}

/* ─── TOPBAR ────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-md);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.brand-name {
  font-size: 17px; font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text-primary);
}
.brand-name span { color: var(--accent); }
.brand-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
  margin-top: 1px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  flex-wrap: wrap;
}
.file-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  color: var(--text-secondary);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-pill svg { width: 12px; height: 12px; flex-shrink: 0; color: var(--accent); }

#fileInput { display: none; }

.btn-upload {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  font-size: 12px; font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn-upload:hover { border-color: var(--accent); background: var(--surface3); }
.btn-upload svg { width: 14px; height: 14px; }
.btn-upload .upload-chevron { width: 10px; height: 10px; opacity: 0.6; }

/* ─── UPLOAD DROPDOWN (TOPBAR) ──────────────────────────────────────────── */
.upload-wrap { position: relative; display: inline-flex; }
.upload-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  min-width: 288px;
  z-index: 200;
  padding: 5px;
}
.upload-wrap.open .upload-dropdown { display: block; }
.upload-option-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: background .12s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.upload-option-item:hover { background: var(--surface2); }
.upload-option-item svg { width: 14px; height: 14px; color: var(--text-secondary); flex-shrink: 0; }
.upload-dropdown-sep { margin: 4px 0; border: none; border-top: 1px solid var(--border); }
.upload-option-sheets { padding: 6px 10px 8px; }
.upload-sheets-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px; font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 7px;
}
.upload-sheets-label svg { width: 12px; height: 12px; }
.upload-sheets-form { display: flex; gap: 6px; }
.topbar-sheets-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  font-size: 11px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
  min-width: 0;
}
.topbar-sheets-input:focus { border-color: var(--accent); }
.topbar-sheets-input::placeholder { color: var(--text-tertiary); }
.btn-topbar-sheets-load {
  padding: 6px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
  flex-shrink: 0;
  font-family: inherit;
}
.btn-topbar-sheets-load:hover { background: var(--accent-light); }
.btn-topbar-sheets-load:disabled { opacity: 0.6; cursor: not-allowed; }
.upload-sheets-note {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 5px;
}

/* ─── DROP ZONE ─────────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border2);
  border-radius: var(--r-lg);
  padding: 48px var(--sp-lg);
  text-align: center;
  transition: border-color .15s, background .15s;
}
.drop-zone.drag {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.drop-zone-icon {
  width: 44px; height: 44px;
  margin: 0 auto 12px;
  background: var(--surface2);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.drop-zone-icon svg { width: 22px; height: 22px; }
.drop-zone h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.drop-zone p { font-size: 12px; color: var(--text-secondary); line-height: 1.6; }
.drop-zone p strong { color: var(--accent); cursor: pointer; }
.drop-zone p strong:hover { text-decoration: underline; }
.drop-zone .cols-hint {
  margin-top: 14px;
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ─── INPUT SOURCE TABS ─────────────────────────────────────────────────── */
.input-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px;
  margin-bottom: 20px;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}
.input-tab {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.input-tab svg { width: 13px; height: 13px; flex-shrink: 0; }
.input-tab.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.input-tab:hover:not(.active) { color: var(--text-primary); }

.sheets-input-row {
  display: flex;
  gap: 8px;
  max-width: 480px;
  margin: 0 auto 14px;
}
.sheets-url-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  font-size: 12px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
}
.sheets-url-input:focus { border-color: var(--accent); }
.sheets-url-input::placeholder { color: var(--text-tertiary); }
.btn-sheets-load {
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
}
.btn-sheets-load svg { width: 13px; height: 13px; }
.btn-sheets-load:hover { background: var(--accent-light); }
.btn-sheets-load:disabled { opacity: 0.6; cursor: not-allowed; }
.sheets-note {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}
.col-chip {
  padding: 3px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-tertiary);
}

/* ─── STATS BAR ─────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 10px var(--sp-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  flex-wrap: wrap;
}
.stats-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px;
}
.stats-item strong { font-weight: 700; color: var(--text-primary); }
.stats-item span { color: var(--text-secondary); }
.stats-sep { width: 1px; height: 16px; background: var(--border); flex-shrink: 0; }

/* ─── CATEGORY GRID ─────────────────────────────────────────────────────── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--sp-sm);
}
@media (max-width: 640px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 380px) { .cat-grid { grid-template-columns: repeat(2, 1fr); } }

.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 12px 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  position: relative;
  overflow: hidden;
  outline: none;
  text-align: left;
}
.cat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--r-md) var(--r-md) 0 0;
}
.cat-card:hover { background: var(--surface2); transform: translateY(-1px); }
.cat-card:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.cat-card.active { background: var(--surface2); border-color: var(--card-color); }
.cat-card.active::before { opacity: 1; }

/* Color scoping — ONLY the number gets the category color */
.cat-card[data-cat="1"] { --card-color: var(--cat1); }
.cat-card[data-cat="2"] { --card-color: var(--cat2); }
.cat-card[data-cat="3"] { --card-color: var(--cat3); }
.cat-card[data-cat="4"] { --card-color: var(--cat4); }
.cat-card[data-cat="5"] { --card-color: var(--cat5); }
.cat-card[data-cat="6"] { --card-color: var(--cat6); }
.cat-card::before { background: var(--card-color); }

.cat-num {
  font-size: 26px; font-weight: 700; line-height: 1;
  margin-bottom: 5px;
  color: var(--card-color);
}
.cat-label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-tertiary);
  margin-bottom: 3px;
}
.cat-desc {
  font-size: 10px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ─── PANEL ─────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  border-left: 3px solid var(--active-cat-color, var(--border));
  transition: border-left-color .2s;
}

.panel-head {
  padding: 14px var(--sp-md);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  background: var(--surface2);
}
.panel-title-wrap { display: flex; align-items: center; gap: var(--sp-sm); }
.panel-cat-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--active-cat-color, var(--text-tertiary));
  flex-shrink: 0;
}
.panel-title {
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
}
.panel-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
  background: var(--surface3);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.panel-desc {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.panel-actions { display: flex; gap: var(--sp-sm); flex-wrap: wrap; }

/* ─── BUTTONS ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-size: 12px; font-weight: 600;
  cursor: pointer; border: none;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn svg { width: 13px; height: 13px; }

.btn-ghost {
  background: var(--surface3);
  color: var(--text-primary);
  border: 1px solid var(--border2);
}
.export-wrap { position: relative; display: inline-flex; }
.export-dropdown {
  display: none; position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.12);
  min-width: 200px; z-index: 200; overflow: hidden;
}
.export-wrap.open .export-dropdown { display: block; }
.export-dropdown button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 14px; font-size: 13px; font-family: inherit;
  background: none; border: none; color: var(--text-primary);
  cursor: pointer; text-align: left; transition: background .15s;
}
.export-dropdown button:hover { background: var(--surface2); }
.export-dropdown button svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-secondary); }
.export-dropdown hr { margin: 4px 0; border: none; border-top: 1px solid var(--border); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-light); opacity: 1; }
.btn-open {
  background: #16a34a;
  color: #fff;
}
.btn-open:hover { background: #15803d; opacity: 1; }
.btn[aria-disabled="true"] {
  background: var(--surface3) !important;
  color: var(--text-tertiary) !important;
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.6;
}

/* ─── RANGE SELECTOR ─────────────────────────────────────────────────────── */
.range-row {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px var(--sp-md);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  flex-wrap: wrap;
}
.range-row.show { display: flex; }
.range-input {
  width: 62px;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  text-align: center;
  line-height: 1;
}
.range-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.range-sep { color: var(--text-tertiary); font-weight: 400; }
.range-hint { margin-left: 4px; color: var(--text-tertiary); font-weight: 400; font-size: 11px; }
.range-all-btn {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: inherit;
  transition: background .12s, color .12s;
}
.range-all-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* ─── POPUP WARNING ─────────────────────────────────────────────────────── */
.popup-warn {
  margin: 0 var(--sp-md);
  padding: 10px var(--sp-md);
  background: rgba(197,63,9,0.08);
  border: 1px solid rgba(197,63,9,0.3);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: #9a2d04;
  display: none;
  line-height: 1.5;
}
.popup-warn.show { display: block; }

/* ─── TABS ──────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  padding: 0 var(--sp-md);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.tab-btn {
  padding: 10px 16px;
  font-size: 12px; font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  font-family: inherit;
  background: none; border-top: none; border-left: none; border-right: none;
  outline: none;
}
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ─── TABLE ─────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  max-height: 440px;
  overflow-y: auto;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 9px var(--sp-md);
  text-align: left;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-tertiary);
  background: var(--surface2);
  position: sticky; top: 0; z-index: 1;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 8px var(--sp-md); vertical-align: middle; }
.td-num {
  font-size: 11px; color: var(--text-tertiary);
  width: 36px; text-align: right; padding-right: 12px;
  font-variant-numeric: tabular-nums;
}
.td-url {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
  max-width: 380px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.td-url a { color: inherit; text-decoration: none; }
.td-url a:hover { color: var(--accent); }
.td-badge {
  width: 60px;
  text-align: center;
}
.from-badge, .to-badge {
  font-size: 9px; font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.from-badge { background: rgba(99,102,241,.15); color: #818cf8; }
.to-badge   { background: rgba(34,197,94,.12);  color: #4ade80; }

/* ─── LIST VIEW ─────────────────────────────────────────────────────────── */
.list-wrap { padding: var(--sp-md); }
.list-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-md);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
  resize: vertical;
  min-height: 320px;
  line-height: 2;
  outline: none;
  transition: border-color .15s;
}
.list-textarea:focus { border-color: var(--accent); }

/* ─── EMPTY STATE ───────────────────────────────────────────────────────── */
.empty-state {
  padding: 56px var(--sp-lg);
  text-align: center;
}
.empty-icon {
  width: 48px; height: 48px;
  margin: 0 auto 14px;
  background: var(--surface2);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary);
}
.empty-icon svg { width: 24px; height: 24px; }
.empty-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.empty-sub { font-size: 12px; color: var(--text-secondary); }

/* ─── PROGRESS BAR ──────────────────────────────────────────────────────── */
.progress-bar-wrap {
  height: 3px;
  background: var(--border);
  overflow: hidden;
  display: none;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width .1s linear;
}
.progress-bar-wrap.show { display: block; }

/* ─── TOAST ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 999;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #15803d; color: #fff; }
.toast-info    { background: #c53f09; color: #fff; }

/* ─── SCROLLBAR ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
