/* ═══════════════════════════════════════════════════════════════
   CustomsWave Global Harmonised Tariff Explorer — Stylesheet
   ═══════════════════════════════════════════════════════════════ */
:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --border: #e8e5e0;
  --border-light: #f0ede8;
  --text: #1a1a18;
  --text-secondary: #6b6860;
  --text-muted: #9e9a92;
  --accent: #c8553d;
  --accent-light: #f5ebe8;
  --navy: #0a1628;
  --navy-light: #1b2a40;
  --teal: #0d8a72;
  --gold: #b8860b;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', -apple-system, sans-serif;
  --header-h: 44px;
  --ease: cubic-bezier(.22,.68,0,1.2);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 13px; }

/* ─── Top Bar ────────────────────────────────────────────── */
#topBar {
  height: var(--header-h);
  background: var(--navy);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: relative; z-index: 100;
}
.top-left { display: flex; align-items: center; gap: 14px; }
.top-logo-img { height: 24px; filter: brightness(0) invert(1); }
.top-divider { width: 1px; height: 20px; background: rgba(255,255,255,.15); }
.top-system { font-size: 10px; font-weight: 700; letter-spacing: 2px; color: rgba(255,255,255,.7); }
.top-right { display: flex; align-items: center; gap: 20px; }
.top-revision { font-size: 10px; font-weight: 600; letter-spacing: 1.5px; color: rgba(255,255,255,.4); font-family: var(--mono); }
.top-btn { font-size: 11px; font-weight: 600; color: rgba(255,255,255,.7); text-decoration: none; padding: 5px 12px; border-radius: 6px; border: 1px solid rgba(255,255,255,.12); transition: all .2s; }
.top-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ─── 3-Panel Layout ─────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ─── Notes Panel (Left) ─────────────────────────────────── */
#notesPanel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.notes-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-tab {
  flex: 1; padding: 10px 6px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); cursor: pointer; transition: all .2s;
}
.notes-tab:hover { color: var(--text-secondary); }
.notes-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.notes-body {
  flex: 1; overflow-y: auto; padding: 16px;
  font-size: 13px; line-height: 1.7; color: var(--text-secondary);
}
.notes-body h3 { font-size: 14px; color: var(--text); font-style: italic; margin-bottom: 12px; font-weight: 700; }
.notes-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 12px; color: var(--text-muted); text-align: center;
}
.notes-placeholder p { font-style: italic; font-size: 12px; max-width: 180px; }

/* ─── Tree Panel (Center) ────────────────────────────────── */
#treePanel {
  display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg);
}
.search-bar {
  display: flex; align-items: center; gap: 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: relative;
}
.search-icon { color: var(--text-muted); margin-right: 10px; display: flex; }
#searchInput {
  flex: 1; border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 14px; font-size: 13px; font-family: var(--sans);
  color: var(--text); background: var(--bg); outline: none; transition: border .2s;
}
#searchInput:focus { border-color: var(--accent); }
#searchBtn {
  margin-left: 10px; padding: 9px 20px; font-size: 11px; font-weight: 700;
  letter-spacing: 1px; border: none; border-radius: 6px;
  background: var(--navy); color: #fff; cursor: pointer; transition: all .2s;
}
#searchBtn:hover { background: var(--navy-light); }
.search-results {
  position: absolute; top: 100%; left: 20px; right: 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,.12);
  max-height: 320px; overflow-y: auto; z-index: 50; display: none;
}
.search-results.visible { display: block; }
.sr-item {
  padding: 10px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border-light); transition: background .15s;
}
.sr-item:hover { background: var(--accent-light); }
.sr-item:last-child { border-bottom: none; }
.sr-code { font-family: var(--mono); font-weight: 600; font-size: 12px; color: var(--accent); }
.sr-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-rate { font-size: 10px; font-weight: 600; color: var(--teal); float: right; }

/* Breadcrumb */
.breadcrumb {
  padding: 8px 20px;
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  background: var(--surface);
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.bc-item { cursor: pointer; transition: color .2s; }
.bc-item:hover { color: var(--accent); }
.bc-sep { color: var(--border); margin: 0 2px; }
.bc-active { color: var(--text); font-weight: 700; cursor: default; }
.bc-icon { font-size: 12px; margin-right: 3px; }

/* Tree Content */
.tree-content {
  flex: 1; overflow-y: auto; padding: 12px 10px;
  scroll-behavior: smooth;
  font-family: var(--sans);
}
.tree-loading {
  display: flex; align-items: center; justify-content: center;
  height: 100%; gap: 12px; color: var(--text-muted); font-size: 13px;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Tree View Classic Styles */
.tv-root, .tv-children {
  list-style: none;
  margin: 0; padding: 0;
}
.tv-children {
  padding-left: 20px;
  position: relative;
}
/* Vertical dotted line for children */
.tv-children::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 8px;
  border-left: 1px dotted var(--text-muted);
}
.tv-node {
  position: relative;
  margin: 0;
}
/* Horizontal dotted line pointing to the node */
.tv-node::before {
  content: '';
  position: absolute;
  top: 14px; left: -12px; width: 12px;
  border-top: 1px dotted var(--text-muted);
}
/* Hide horizontal line for root items */
.tv-root > .tv-node::before {
  display: none;
}
/* Special leaf nodes to not go past the last item */
.tv-node:last-child > .tv-children::before {
  display: none; /* Usually handled by cutting off the line, but simpler this way */
}

.tv-row {
  display: flex;
  align-items: flex-start;
  padding: 4px 0;
  cursor: pointer;
  position: relative;
}
.tv-toggle {
  width: 15px; height: 15px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--sans);
  font-size: 10px;
  line-height: 15px;
  text-align: center;
  margin-top: 3px;
  margin-right: 6px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  user-select: none;
  transition: transform .2s;
}
.tv-toggle:hover {
  color: var(--text);
}
.tv-toggle.open {
  transform: rotate(90deg);
}
.tv-toggle.leaf {
  color: var(--border);
  font-size: 12px;
}
.tv-content {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  transition: all .15s;
}
.tv-row:hover .tv-content {
  background: rgba(200,85,61,.04);
}
.tv-row.selected .tv-content {
  background: rgba(200,85,61,.08);
  border-color: var(--accent);
}
.tv-code {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  margin-top: 1px;
}
.tv-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.4;
}
[data-type="section"] > .tv-row > .tv-content > .tv-code { color: var(--accent); }
[data-type="chapter"] > .tv-row > .tv-content > .tv-code { color: var(--gold); }
[data-type="line"] > .tv-row > .tv-content > .tv-code { color: var(--teal); }

/* ─── Rulings Panel (Right) ──────────────────────────────── */
#rulingsPanel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.rulings-header {
  padding: 12px 16px;
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  color: var(--text-secondary); text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.rulings-count {
  margin-left: auto;
  font-size: 9px; font-weight: 800; letter-spacing: 1px;
  padding: 3px 8px; border-radius: 10px;
  background: var(--navy); color: #fff;
}
.rulings-body {
  flex: 1; overflow-y: auto; padding: 12px;
}
.rulings-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 14px; color: var(--text-muted); text-align: center;
}
.rulings-placeholder p { font-size: 12px; max-width: 200px; line-height: 1.6; }
.rulings-footer {
  padding: 10px 14px;
  font-size: 10px; color: var(--text-muted); line-height: 1.5;
  border-top: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 6px;
  flex-shrink: 0;
}
.rulings-footer svg { flex-shrink: 0; margin-top: 1px; }

/* Code Detail Card */
.code-detail {
  padding: 16px; margin: 0;
  background: var(--surface); border-radius: 0;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.05);
}
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.detail-code { font-family: var(--mono); font-weight: 700; font-size: 16px; color: var(--accent); }
.detail-rate { font-family: var(--mono); font-weight: 800; font-size: 18px; color: #10b981; }
.detail-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 12px; }
.detail-flags { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-flag {
  font-size: 9px; font-weight: 700; letter-spacing: .5px;
  padding: 3px 8px; border-radius: 4px; text-transform: uppercase;
}
.flag-s232 { background: #fef3c7; color: #92400e; }
.flag-s301 { background: #fee2e2; color: #dc2626; }
.flag-s122 { background: #dbeafe; color: #1d4ed8; }
.flag-addcvd { background: #fce7f3; color: #be185d; }

/* Ruling Card */
.ruling-card {
  padding: 12px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); transition: all .2s;
}
.ruling-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(200,85,61,.08); }
.rc-id { font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--accent); }
.rc-date { font-size: 10px; color: var(--text-muted); float: right; }
.rc-desc { font-size: 11px; color: var(--text-secondary); margin-top: 6px; line-height: 1.5; }

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

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .25s ease-out; }
