:root {
  --bg:       #11151c;
  --surface:  #1a2030;
  --border:   #2d3748;
  --text:     #e2e8f0;
  --muted:    #8899aa;
  --accent:   #5ad1a8;
  --accent-h: #7ee0bf;
  --danger:   #ef4444;
  --green:    #10b981;
  --amber:    #f59e0b;
  --sidebar:  280px;
}

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

html, body { height: 100%; font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

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

/* Sidebar */
#sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
#sidebar-header h1 { font-size: 15px; font-weight: 600; letter-spacing: -.3px; flex: 1; }
#sidebar-header span { font-size: 10px; color: var(--muted); background: var(--bg); padding: 2px 6px; border-radius: 4px; }

#sidebar-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 16px; }

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

/* Toolbar */
#toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
}

.tab-group { display: flex; gap: 2px; background: var(--bg); border-radius: 6px; padding: 3px; }
.tab { padding: 4px 12px; border-radius: 4px; cursor: pointer; color: var(--muted); font-size: 13px; border: none; background: none; }
.tab.active { background: var(--accent); color: #fff; }

#query-label { margin-left: auto; color: var(--muted); font-size: 12px; }
#query-label strong { color: var(--text); }

/* Content area */
#content { flex: 1; position: relative; overflow: hidden; }

/* Map */
#map { position: absolute; inset: 0; }

/* Graph */
#graph-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: none;
}

/* Article list overlay */
#list-panel {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 360px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform .2s ease;
}
#list-panel.open { transform: none; }
#list-panel.fullscreen { width: 100%; border-left: none; }

#list-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
#list-header h2 { font-size: 13px; font-weight: 600; flex: 1; }
#list-count { font-size: 11px; color: var(--muted); }

#article-list { flex: 1; overflow-y: auto; }

/* Article card */
.article {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: default;
}
.article:hover { background: rgba(90,209,168,.07); }
.article-meta-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.article-source { font-size: 10px; color: var(--accent); text-transform: uppercase; letter-spacing: .5px; }
.article-date   { font-size: 10px; color: var(--muted); flex-shrink: 0; }
.article-url {
  font-size: 12px; color: var(--text); margin: 3px 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-all;
}
.article-url a { color: inherit; text-decoration: none; }
.article-url a:hover { color: var(--accent-h); }
.article-desc { font-size: 11px; color: var(--muted); margin: 2px 0 4px; }
.article-footer { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.article-loc { font-size: 10px; color: var(--muted); }
.article-meta { font-size: 10px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.article-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  font-size: 10px; padding: 1px 6px; border-radius: 99px;
  background: rgba(255,255,255,.07); color: var(--muted);
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tag.person { background: rgba(90,209,168,.2); color: #7ee0bf; }
.tag.org    { background: rgba(16,185,129,.2); color: #6ee7b7; }
.tag.theme  { background: rgba(245,158,11,.15); color: #fcd34d; }

.tone-pos { color: var(--green); }
.tone-neg { color: var(--danger); }
.tone-neu { color: var(--muted); }

#list-more { padding: 12px 16px; text-align: center; }

/* ── Auth screen ─────────────────────────────────────────────────────────── */
#auth-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 340px;
}
.auth-card h2  { font-size: 18px; margin-bottom: 2px; }
.auth-card h3  { font-size: 14px; font-weight: 500; color: var(--muted); margin-bottom: 16px; }
.auth-card p   { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

/* ── Queries ─────────────────────────────────────────────────────────────── */
.section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  font-weight: 600;
}

.query-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border: 1px solid transparent;
}
.query-item:hover { background: rgba(255,255,255,.04); }
.query-item.selected { background: rgba(90,209,168,.12); border-color: var(--accent); }

.query-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 4px; flex-shrink: 0;
}
.query-dot.active { background: var(--green); }
.query-dot.inactive { background: var(--border); }

.query-info { flex: 1; min-width: 0; }
.query-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.query-desc { font-size: 10px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.query-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 11px; color: var(--muted); font-weight: 500; }
.form-row { display: flex; gap: 6px; }

input[type=text], input[type=email], input[type=number] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  width: 100%;
  outline: none;
}
input:focus { border-color: var(--accent); }

/* Collapsible create form */
#create-form {
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}
#create-form.open { display: flex; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-ghost    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-danger   { background: transparent; color: var(--danger); border: 1px solid transparent; padding: 4px 6px; font-size: 11px; }
.btn-icon     { background: transparent; border: none; cursor: pointer; color: var(--muted); padding: 3px 5px; border-radius: 4px; font-size: 12px; line-height: 1; }
.btn-icon:hover { color: var(--text); background: rgba(255,255,255,.06); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; }

/* ── Empty / loading states ─────────────────────────────────────────────── */
.empty {
  padding: 32px 16px; text-align: center;
  color: var(--muted); font-size: 13px;
}
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Graph legend ────────────────────────────────────────────────────────── */
#graph-legend {
  position: absolute; bottom: 12px; left: 12px;
  background: rgba(17,21,28,.88);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: none;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}
#graph-legend.visible { display: flex; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

/* ── Graph controls ──────────────────────────────────────────────────────── */
#graph-controls {
  position: absolute; top: 12px; right: 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
}
#graph-controls.visible { display: flex; }
.graph-ctrl-group {
  background: rgba(17,21,28,.88);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}
.graph-ctrl-group label { white-space: nowrap; }
.graph-ctrl-group input[type=range] { width: 80px; accent-color: var(--accent); }
.graph-ctrl-group output { width: 20px; text-align: center; }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
#sidebar-toggle {
  display: none;
  position: fixed; bottom: 20px; left: 20px; z-index: 50;
  background: var(--accent); color: #fff;
  border: none; border-radius: 50%;
  width: 44px; height: 44px;
  font-size: 20px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed; left: -100%; top: 0; bottom: 0; z-index: 40;
    transition: left .25s ease;
    width: 85%;
    max-width: 320px;
  }
  #sidebar.open { left: 0; }
  #sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  #list-panel { width: 100%; border-left: none; }
}
