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

/* ── Tokens ────────────────────────────────────────── */
:root {
  --bg:       #09090b;
  --sidebar:  #0e0e11;
  --surface:  #18181b;
  --surface2: #1f1f24;
  --border:   #2c2c32;
  --border2:  #3f3f46;
  --text:     #fafafa;
  --text2:    #a1a1aa;
  --text3:    #71717a;
  --accent:   #f43f5e;
  --accent-h: #fb7185;
  --blue:     #818cf8;
  --green:    #34d399;
  --radius:   9px;
  --sidebar-w: 284px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Base ──────────────────────────────────────────── */
html, body {
  height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbars ────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: #3f3f46 transparent; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #52525b; }

/* ── Layout ────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--sidebar);
  display: flex; flex-direction: column;
  padding: 1.25rem 1.1rem;
  gap: 0.55rem;
  overflow-y: auto; overflow-x: hidden;
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 1rem; font-weight: 700; letter-spacing: -0.02em;
  padding-bottom: 0.1rem;
}
.sidebar-brand .emoji { font-size: 1.25rem; line-height: 1; }

.sidebar-desc {
  font-size: 0.8rem; color: var(--text3); line-height: 1.5;
}

.sep {
  border: none; border-top: 1px solid var(--border);
  margin: 0.3rem 0;
}

.field-label {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text3);
  display: block; margin-bottom: 0.3rem; margin-top: 0.45rem;
}

input[type="text"], input[type="date"], input[type="number"] {
  width: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  padding: 0.55rem 0.8rem; font-size: 0.875rem;
  font-family: var(--font); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--text3); }
input:focus {
  border-color: var(--border2);
  box-shadow: 0 0 0 3px rgba(244,63,94,0.12);
}

#search-btn {
  width: 100%; margin-top: 0.3rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
  padding: 0.62rem 1rem; font-size: 0.9rem; font-weight: 600;
  font-family: var(--font); cursor: pointer;
  transition: background 0.15s;
}
#search-btn:hover:not(:disabled) { background: var(--accent-h); }
#search-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.toggle-row {
  display: flex; align-items: center; gap: 0.55rem;
  font-size: 0.85rem; color: var(--text2);
}
.toggle-row input[type="checkbox"] {
  accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer;
}
.toggle-row label { cursor: pointer; }

.tip-icon {
  margin-left: auto;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text3); font-size: 0.65rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: default; flex-shrink: 0;
}

.section-title {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--text3); margin-top: 0.2rem;
}

.how-to {
  padding-left: 1.1rem; color: var(--text3);
  font-size: 0.82rem; line-height: 1.8;
}
.how-to li { margin-bottom: 0.1rem; }
.how-to strong { color: var(--text2); font-weight: 600; }

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

/* ── State screens ─────────────────────────────────── */
.state {
  flex: 1; display: none; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: 0.9rem; padding: 2rem;
  animation: fadeIn 0.2s ease;
}
.state.active { display: flex; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.state-icon { font-size: 3.2rem; line-height: 1; }
.state h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; }
.state h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.state p { color: var(--text3); max-width: 380px; line-height: 1.7; font-size: 0.925rem; }
.state .hint { font-size: 0.82rem; color: var(--text3); opacity: 0.7; }

/* Loading dots */
.dots::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0%, 100% { content: ''; }
  25%       { content: '.'; }
  50%       { content: '..'; }
  75%       { content: '...'; }
}

/* ── Results ───────────────────────────────────────── */
#results {
  flex: 1; display: none; flex-direction: column;
  overflow: hidden; padding: 1.4rem 1.6rem 1rem; gap: 1rem;
  animation: fadeIn 0.2s ease;
}
#results.active { display: flex; }

.results-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.results-header h2 {
  font-size: 1.65rem; font-weight: 800; letter-spacing: -0.03em;
}

/* ── Metrics ───────────────────────────────────────── */
.metrics { display: grid; grid-template-columns: repeat(4,1fr); gap: 0.75rem; }

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem 1.1rem;
  position: relative; overflow: hidden;
}
.metric-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: linear-gradient(90deg, var(--accent), transparent);
}
.metric-label {
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 0.35rem;
}
.metric-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; }


.tbtn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; color: var(--text2);
  padding: 0.38rem 0.8rem; font-size: 0.82rem; font-weight: 500;
  font-family: var(--font); cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.tbtn:hover { background: var(--surface2); color: var(--text); }
.tbtn.active {
  background: rgba(244,63,94,0.1);
  border-color: rgba(244,63,94,0.35);
  color: var(--accent);
}

/* ── Table ─────────────────────────────────────────── */
.table-wrap {
  flex: 1; overflow: auto;
  border: 1px solid var(--border); border-radius: 10px;
  scrollbar-color: transparent transparent;
}
.table-wrap:hover { scrollbar-color: #3f3f46 transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: transparent; transition: background 0.2s; }
.table-wrap:hover::-webkit-scrollbar-thumb { background: #3f3f46; }

table { width: 100%; border-collapse: collapse; font-size: 0.855rem; }

thead { position: sticky; top: 0; z-index: 2; }

th {
  background: var(--surface); padding: 0.62rem 0.9rem;
  text-align: left; font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text3); white-space: nowrap;
  border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none;
  transition: color 0.12s;
}
th:hover { color: var(--text2); }
th.sorted { color: var(--text); }
th.no-sort { cursor: default; }
th.r { text-align: right; }

.sort-ic { margin-left: 0.2rem; font-style: normal; font-size: 0.7rem; opacity: 0.35; }
th.sorted .sort-ic { opacity: 1; color: var(--accent); }

td {
  padding: 0.52rem 0.9rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text2);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.025); color: var(--text); }

td.app-cell { max-width: 280px; }
td.app-cell .app-inner {
  display: flex; align-items: center; gap: 0.65rem;
  overflow: hidden;
}
td.app-cell .app-text {
  display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}
.cell-sub {
  font-size: 0.72rem; color: var(--text3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 0.1rem; line-height: 1.3;
}
td.app-cell img {
  width: 34px; height: 34px; border-radius: 8px;
  display: block; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.08);
}
td.app-cell .no-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--surface2); flex-shrink: 0; display: block;
  border: 1px solid var(--border);
}
td.app-cell a {
  color: var(--text); text-decoration: none; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color 0.12s;
}
td.app-cell a:hover { color: var(--blue); }

td.r { text-align: right; }
td.dim { color: var(--text3); }
td.num { font-variant-numeric: tabular-nums; }

/* ── Tooltips ──────────────────────────────────────── */
[data-tooltip] { position: relative; }

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 100;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text2);
  font-size: 0.78rem;
  font-family: var(--font);
  line-height: 1.4;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  border-radius: 7px;
  padding: 0.45rem 0.7rem;
  max-width: 280px;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

[data-tooltip]:hover::after { opacity: 1; }

/* Right-align to icon edge so tooltip stays inside the sidebar */
.tip-icon[data-tooltip]::after {
  left: auto;
  right: 0;
  transform: none;
  width: 240px;
}
