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

:root {
  --navy: #19223F;
  --dark: #0d1117;
  --dark2: #0a0e1a;
  --gold: #C99E50;
  --tan: #EBCA9C;
  --slate: #7FA8C9;
  --green: #4ade80;
  --red: #f87171;
  --purple: #a78bfa;
  --border: rgba(255,255,255,0.06);
  --text: #d0d8e4;
  --text-dim: #8893A0;
  --sidebar-w: 280px;
  --header-h: 48px;
  --stats-h: 68px;
  --font: 'Lato', -apple-system, sans-serif;
  --font-head: 'Noto Sans Display', 'Lato', sans-serif;
}

html, body {
  height: 100%;
  background: var(--dark2);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Mobile Bar ── */
#mobile-bar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--dark);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 100;
}

.mobile-logo { height: 24px; width: auto; }
.mobile-actions { display: flex; gap: 6px; }

.mobile-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.mobile-btn:hover { background: rgba(255,255,255,0.08); }

/* ── App Layout ── */
#app-layout {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--dark);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 50;
  flex-shrink: 0;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.sidebar-header {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-logo { height: 28px; width: auto; }

.sidebar-header .subtitle {
  font-size: 11px;
  color: var(--tan);
  font-weight: 400;
  letter-spacing: 0.5px;
  flex: 1;
}

.sidebar-close-btn { display: none; }

/* Sidebar sections */
.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
  font-size: 10px;
  font-weight: 600;
  color: var(--tan);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

h3.collapsible {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

h3.collapsible::before {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--tan);
  transition: transform 0.2s;
  flex-shrink: 0;
}

h3.collapsible.collapsed::before { transform: rotate(-90deg); }

.collapsible-content {
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.collapsible-content.collapsed {
  max-height: 0 !important;
}

/* Sidebar input */
.sidebar-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  font-family: var(--font);
}
.sidebar-input:focus { border-color: rgba(127,168,201,0.5); }
.sidebar-input::placeholder { color: rgba(176,184,196,0.4); }

/* Radio groups */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.1s;
}
.radio-item:hover { color: var(--text); }
.radio-item input[type="radio"] { accent-color: var(--slate); flex-shrink: 0; }

/* Actions */
.sidebar-actions { display: flex; flex-direction: column; gap: 8px; }

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  font-family: var(--font);
}
.action-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.2); }
.action-btn:active { transform: scale(0.98); }
.action-btn.loading { opacity: 0.6; pointer-events: none; }

.action-btn-gold {
  border-color: rgba(201,158,80,0.3);
  color: var(--gold);
}
.action-btn-gold:hover { background: rgba(201,158,80,0.1); border-color: rgba(201,158,80,0.5); }

.action-btn-blue {
  border-color: rgba(127,168,201,0.3);
  color: var(--slate);
}
.action-btn-blue:hover { background: rgba(127,168,201,0.1); border-color: rgba(127,168,201,0.5); }

.cache-info {
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
}

/* ── Sidebar overlay ── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
}
#sidebar-overlay.visible { display: block; }

/* ── Main Content ── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Stats Bar ── */
#stats-bar {
  display: flex;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.stat-card {
  flex: 1;
  padding: 12px 16px;
  background: var(--dark);
  text-align: center;
}

.stat-value {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 600;
  color: var(--tan);
  line-height: 1.2;
}

.stat-value.stat-matched { color: var(--green); }
.stat-value.stat-unmatched { color: var(--gold); }
.stat-value.stat-missing { color: var(--red); }

.stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 2px;
}

/* ── Tab Nav ── */
#tab-nav {
  display: flex;
  background: var(--dark);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  flex-shrink: 0;
}

.tab {
  padding: 11px 16px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ── Tab Panels ── */
.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.tab-panel.active { display: block; }

/* ── Loading / Error / Auth States ── */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  padding: 20px;
  color: #f87171;
  background: rgba(248,113,113,0.08);
  border-radius: 8px;
  margin: 16px;
  font-size: 13px;
}

.auth-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 40px;
  gap: 12px;
}

.auth-prompt h2 {
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 600;
  color: var(--tan);
}

.auth-prompt p {
  font-size: 13px;
  color: var(--text-dim);
  max-width: 340px;
  line-height: 1.6;
}

.btn-primary {
  padding: 10px 24px;
  background: var(--gold);
  color: var(--dark);
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }

/* ── Panel Toolbar ── */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-count {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Item List ── */
.item-list { display: flex; flex-direction: column; gap: 8px; }

/* ── Match Cards (Matched view) ── */
.match-card {
  background: var(--dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  transition: border-color 0.15s;
}
.match-card:hover { border-color: rgba(255,255,255,0.12); }

.match-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.job-num {
  font-family: var(--font-head);
  font-size: 12px;
  font-weight: 700;
  color: var(--tan);
  white-space: nowrap;
  flex-shrink: 0;
}

.job-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  line-height: 1.3;
  min-width: 120px;
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  background: rgba(255,255,255,0.1);
  color: var(--text-dim);
}

/* Match confidence badges */
.match-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.match-badge.direct {
  background: rgba(201,158,80,0.15);
  color: var(--gold);
  border: 1px solid rgba(201,158,80,0.3);
}
.match-badge.file {
  background: rgba(127,168,201,0.15);
  color: var(--slate);
  border: 1px solid rgba(127,168,201,0.3);
}
.match-badge.fuzzy {
  background: rgba(167,139,250,0.15);
  color: var(--purple);
  border: 1px solid rgba(167,139,250,0.3);
}
.match-badge.manual {
  background: rgba(74,222,128,0.15);
  color: var(--green);
  border: 1px solid rgba(74,222,128,0.3);
}

.match-card-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.folder-name {
  font-size: 11px;
  color: var(--text-dim);
  flex: 1;
  min-width: 120px;
  font-family: monospace;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px;
  background: rgba(255,255,255,0.04);
  color: var(--text-dim);
  font-size: 11px;
  text-decoration: none;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}
.link-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); border-color: rgba(255,255,255,0.2); }

.link-btn-drive { color: var(--gold); border-color: rgba(201,158,80,0.2); }
.link-btn-drive:hover { background: rgba(201,158,80,0.1); border-color: rgba(201,158,80,0.4); }

.link-btn-monday { color: var(--slate); border-color: rgba(127,168,201,0.2); }
.link-btn-monday:hover { background: rgba(127,168,201,0.1); border-color: rgba(127,168,201,0.4); }

.writeback-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid rgba(201,158,80,0.3);
  border-radius: 5px;
  background: rgba(201,158,80,0.08);
  color: var(--gold);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}
.writeback-btn:hover { background: rgba(201,158,80,0.15); }
.writeback-btn.done {
  border-color: rgba(74,222,128,0.3);
  background: rgba(74,222,128,0.08);
  color: var(--green);
}
.writeback-btn.loading { opacity: 0.5; pointer-events: none; }

/* ── Unmatched Folder Cards ── */
.folder-card {
  background: var(--dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  transition: border-color 0.15s;
}
.folder-card:hover { border-color: rgba(255,255,255,0.12); }
.folder-card.junk { opacity: 0.5; }
.junk-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.1);
}

.folder-card-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.folder-icon {
  flex-shrink: 0;
  color: var(--gold);
  opacity: 0.7;
}

.folder-card-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
}

.folder-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.subfolder-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.subfolder-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
}

.manual-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.manual-link-row label {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.manual-select {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
}
.manual-select:focus { border-color: rgba(127,168,201,0.5); }

.save-link-btn {
  padding: 5px 12px;
  background: rgba(127,168,201,0.1);
  border: 1px solid rgba(127,168,201,0.3);
  border-radius: 5px;
  color: var(--slate);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
  transition: all 0.15s;
}
.save-link-btn:hover { background: rgba(127,168,201,0.2); }

.suggestions-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Missing Cards ── */
.missing-card {
  background: var(--dark);
  border: 1px solid rgba(248,113,113,0.15);
  border-radius: 8px;
  padding: 12px 16px;
}
.missing-card.urgent {
  border-color: rgba(248,113,113,0.4);
  background: rgba(248,113,113,0.04);
}
.missing-card.stale {
  opacity: 0.5;
}

.missing-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.missing-label {
  font-size: 10px;
  font-style: italic;
  color: rgba(248,113,113,0.6);
}

.urgent-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  background: rgba(248,113,113,0.15);
  color: #f87171;
  border: 1px solid rgba(248,113,113,0.3);
}

/* ── Board tag ── */
.board-tag {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.board-tag.active { background: rgba(74,222,128,0.1); color: var(--green); }
.board-tag.y2026   { background: rgba(127,168,201,0.1); color: var(--slate); }
.board-tag.y2025   { background: rgba(201,158,80,0.1); color: var(--gold); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30,35,50,0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text);
  z-index: 9999;
  backdrop-filter: blur(8px);
  white-space: nowrap;
  max-width: 90vw;
  white-space: normal;
  text-align: center;
}
.toast.success { border-color: rgba(74,222,128,0.3); color: var(--green); }
.toast.error { border-color: rgba(248,113,113,0.3); color: var(--red); }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #mobile-bar { display: flex; }

  #app-layout { padding-top: var(--header-h); }

  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 60;
  }

  #sidebar.open { transform: translateX(0); }
  .sidebar-close-btn { display: flex; }

  #main-content { height: calc(100vh - var(--header-h)); }

  #stats-bar { flex-wrap: wrap; gap: 1px; }
  .stat-card { flex: 0 0 calc(50% - 1px); min-width: 0; }

  .match-card-links { flex-direction: column; align-items: flex-start; }
  .manual-link-row { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .tab { padding: 11px 10px; font-size: 11px; }
  .stat-value { font-size: 16px; }
  .match-card-header { flex-wrap: wrap; }
}
