:root{
  /* DARK THEME (default) */
  --bg:#0b1220;
  --panel:#101a30;
  --panel2:#0f1930;
  --text:#e9eefc;
  --muted:#a8b3d1;
  --border:#223156;
  --accent:#4c7dff;
  --danger:#ff4c4c;
  --success:#3ddc97;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

body[data-theme="light"]{
  --bg:#f5f7ff;
  --panel:#ffffff;
  --panel2:#ffffff;
  --text:#0e1628;
  --muted:#51607d;
  --border:#d6deee;
  --accent:#2f62ff;
  --danger:#d93025;
  --success:#0f9d58;
  --shadow: 0 10px 25px rgba(0,0,0,.10);
}

*{ box-sizing:border-box; }
body{
  margin:0;
  font-family:var(--font);
  background: radial-gradient(1200px 700px at 20% 0%, rgba(76,125,255,.25) 0%, var(--bg) 55%);
  color:var(--text);
}

/* ---------- AUTH (LOGIN) ---------- */
.auth{
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.auth-card{
  width: 100%;
  max-width: 520px;
  background: rgba(16,26,48,.85);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow);
  padding: 16px;
}
body[data-theme="light"] .auth-card{
  background: rgba(255,255,255,.92);
}

.auth-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  margin-bottom: 14px;
}

.auth-title{
  font-weight: 900;
  letter-spacing: .2px;
  font-size: 18px;
}

.auth-subtitle{
  margin-top: 4px;
  font-size: 12px;
}

.auth-form{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.auth-label{
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.auth-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-top: 2px;
}

.auth-remember{
  display:flex;
  align-items:center;
  gap:8px;
  font-size: 12px;
  color: var(--muted);
  user-select:none;
}

.auth-btn{
  margin-top: 6px;
  width: 100%;
}

.auth-foot{
  margin-top: 10px;
  font-size: 11px;
  line-height: 1.35;
}

/* App shell wrapper */
.app-shell[hidden]{ display:none; }

/* ---------- TOPBAR / TABS ---------- */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:16px 20px;
  border-bottom:1px solid var(--border);
  background: rgba(10,16,30,.55);
  backdrop-filter: blur(10px);
  position: sticky;
  top:0;
  z-index:10;
}
body[data-theme="light"] .topbar{
  background: rgba(255,255,255,.72);
}

.brand{ display:flex; flex-direction:column; gap:10px; }
.brand-title{ font-weight:800; letter-spacing:.2px; font-size:18px;}
.brand-subtitle{ color:var(--muted); font-size:12px; margin-top:4px; }

.top-actions{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }

.tabs{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}
.tab{
  border:1px solid var(--border);
  background: rgba(255,255,255,.05);
  color:var(--text);
  padding:8px 10px;
  border-radius:12px;
  cursor:pointer;
  font-size:12px;
}
.tab.is-active{
  border:1px solid rgba(76,125,255,.55);
  background: rgba(76,125,255,.18);
}

/* ---------- SUBBAR ---------- */
.subbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:14px 20px;
  border-bottom:1px solid var(--border);
  background: rgba(16,26,48,.35);
}
body[data-theme="light"] .subbar{
  background: rgba(255,255,255,.55);
}

.subbar-left{ min-width:0; }
.subbar-title{
  font-weight:800;
  letter-spacing:.2px;
}
.subbar-subtitle{
  font-size:12px;
  margin-top:4px;
}

.subbar-actions{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
}

.file-btn{
  display:inline-flex;
  align-items:center;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:12px;
  cursor:pointer;
  background: linear-gradient(180deg, rgba(76,125,255,.22), rgba(76,125,255,.10));
  box-shadow: var(--shadow);
  user-select:none;
}
.file-btn input{ display:none; }

.btn{
  border:1px solid rgba(76,125,255,.55);
  background: rgba(76,125,255,.18);
  color:var(--text);
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
}
.btn:disabled{ opacity:.45; cursor:not-allowed; }
.btn.secondary{
  border:1px solid var(--border);
  background: rgba(255,255,255,.05);
}
.btn.danger{
  border:1px solid rgba(255,76,76,.55);
  background: rgba(255,76,76,.14);
}

.report{ display:none; }
.report.is-active{ display:block; }

.layout{
  display:grid;
  grid-template-columns: 360px 1fr;
  gap:14px;
  padding:14px;
}

.sidebar{
  display:flex;
  flex-direction:column;
  gap:12px;
}

.panel{
  background: rgba(16,26,48,.85);
  border:1px solid var(--border);
  border-radius: var(--radius);
  padding:14px;
  box-shadow: var(--shadow);
}
body[data-theme="light"] .panel{
  background: rgba(255,255,255,.92);
}

.panel h2{
  margin:0 0 10px 0;
  font-size:14px;
  letter-spacing:.2px;
}

.filters-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
}
.filters-head h2{ margin:0; }

.kv{
  display:grid;
  grid-template-columns: 80px 1fr;
  gap:8px 10px;
  font-size:13px;
}
.k{ color:var(--muted); }
.v{ color:var(--text); word-break:break-word; }

.status{ margin-top:10px; font-size:12px; }
.status.danger{ color: var(--danger); }
.status.success{ color: var(--success); }
.muted{ color:var(--muted); }

.input, .select{
  width:100%;
  border:1px solid var(--border);
  background: rgba(255,255,255,.05);
  color:var(--text);
  border-radius: 12px;
  padding:10px 12px;
  outline:none;
}
.input:disabled, .select:disabled{ opacity:.6; }

.hint{
  margin-top:8px;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
}

.preset-row{
  display:grid;
  grid-template-columns: 1fr 90px;
  gap:10px;
  margin-bottom:10px;
}
.preset-actions{
  display:flex;
  gap:10px;
  margin-top:8px;
}

.filters{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.filter{
  border:1px solid var(--border);
  border-radius: 12px;
  padding:10px;
  background: rgba(255,255,255,.03);
}

/* Collapsible filter header */
.filter-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  cursor:pointer;
  user-select:none;
}

.filter-title{
  font-size:12px;
  color:var(--muted);
  display:flex;
  align-items:center;
  gap:10px;
  min-width: 0;
}

.filter-title .name{
  color:var(--muted);
  font-size:12px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.filter-right{
  display:flex;
  align-items:center;
  gap:8px;
  flex-shrink:0;
}

.pill{
  font-size:11px;
  padding:2px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  color:var(--muted);
  white-space:nowrap;
}

.chev{
  width:28px;
  height:28px;
  border-radius:10px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.05);
  display:flex;
  align-items:center;
  justify-content:center;
  color:var(--muted);
  font-size:12px;
  transition: transform .15s ease;
}

/* Body show/hide */
.filter-body{ margin-top:10px; }
.filter.collapsed .filter-body{ display:none; }
.filter.collapsed .chev{ transform: rotate(-90deg); }

.filter .row{
  display:flex;
  gap:8px;
  align-items:center;
}

.small-btn{
  border:1px solid var(--border);
  background: rgba(255,255,255,.05);
  color:var(--text);
  border-radius:10px;
  padding:8px 10px;
  cursor:pointer;
}
.small-btn:disabled{ opacity:.45; cursor:not-allowed; }

.content{
  min-width: 0;
  display:flex;
  flex-direction:column;
  gap:12px;
}

/* ---------- DASHBOARD ---------- */
.dash{
  background: rgba(16,26,48,.55);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding:14px;
}
body[data-theme="light"] .dash{
  background: rgba(255,255,255,.75);
}

.dash-head{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:12px;
  margin-bottom:12px;
}

.dash-title{
  font-weight:800;
  letter-spacing:.2px;
}

.kpis{
  display:grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap:10px;
  margin-bottom:12px;
}

.kpi{
  border:1px solid var(--border);
  border-radius: 14px;
  padding:12px;
  background: rgba(255,255,255,.03);
}

.kpi .label{
  font-size:12px;
  color:var(--muted);
  margin-bottom:6px;
}

.kpi .value{
  font-size:22px;
  font-weight:800;
  letter-spacing:.2px;
}

.kpi .sub{
  margin-top:6px;
  font-size:12px;
  color:var(--muted);
}

.breakdowns{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap:10px;
}

.bd{
  border:1px solid var(--border);
  border-radius: 14px;
  padding:12px;
  background: rgba(255,255,255,.03);
  min-height: 120px;
}

.bd .title{
  font-size:12px;
  color:var(--muted);
  margin-bottom:10px;
}

.bd .list{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.bd .item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

.bd .item .name{
  font-size:13px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.bd .item .count{
  font-size:12px;
  color:var(--muted);
  border:1px solid var(--border);
  padding:1px 8px;
  border-radius:999px;
  flex-shrink:0;
}

/* ---------- TABLE ---------- */
.table-wrap{
  background: rgba(16,26,48,.55);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}
body[data-theme="light"] .table-wrap{
  background: rgba(255,255,255,.75);
}

table{
  width:100%;
  border-collapse:collapse;
  font-size:13px;
}

thead th{
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(12,18,34,.92);
  border-bottom:1px solid var(--border);
  text-align:left;
  padding:10px 10px;
  white-space:nowrap;
  cursor:pointer;
}
body[data-theme="light"] thead th{
  background: rgba(250,251,255,.95);
}

thead th .sort{
  color:var(--muted);
  font-size:11px;
  margin-left:6px;
}

tbody td{
  border-bottom:1px solid rgba(34,49,86,.35);
  padding:9px 10px;
  vertical-align:top;
  word-break:break-word;
}

tbody tr:hover{
  background: rgba(76,125,255,.08);
}

.footer{
  padding:14px;
  border-top:1px solid var(--border);
  margin-top:10px;
  text-align:center;
}

/* ---------- Facet list ---------- */
.facet-actions{
  display:flex;
  gap:8px;
  margin-top:10px;
}

.facet-list{
  margin-top:10px;
  max-height:520px; /* raised to better support hundreds of unique values (e.g., Model) */
  overflow:auto;
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px;
  background: rgba(255,255,255,.03);
}

.facet-item{
  display:flex;
  align-items:center;
  gap:10px;
  padding:7px 8px;
  border-radius:10px;
  cursor:pointer;
  user-select:none;
}

.facet-item:hover{
  background: rgba(76,125,255,.08);
}

.facet-item input[type="checkbox"]{
  width:16px;
  height:16px;
  accent-color: var(--accent);
}

.facet-text{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:10px;
  width:100%;
}

.facet-value{ font-size:13px; }

.facet-count{
  font-size:12px;
  color: var(--muted);
  border:1px solid var(--border);
  padding:1px 8px;
  border-radius:999px;
}

.facet-list::-webkit-scrollbar{ width:10px; }
.facet-list::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,.12);
  border-radius: 999px;
  border:2px solid rgba(0,0,0,0);
  background-clip: padding-box;
}
.facet-list::-webkit-scrollbar-track{
  background: rgba(0,0,0,0);
}
