:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #0b1220;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-btn: #0284c7;
  --ok-bg: #14532d;
  --ok-text: #dcfce7;
  --warn-bg: #78350f;
  --warn-text: #fef3c7;
  --err-bg: #7f1d1d;
  --err-text: #fee2e2;
  --info-bg: #0c4a6e;
  --info-text: #e0f2fe;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: 72px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1020px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand img { width: 32px; height: 32px; border-radius: 8px; }
.brand h1 { font-size: 1.05rem; margin: 0; }
.brand small { display: block; color: var(--muted); font-size: 0.75rem; }

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

.container {
  max-width: 1020px;
  margin: 16px auto;
  padding: 0 16px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  padding: 11px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent-btn);
  color: #fff;
  border-color: var(--accent);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

.scan-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 780px) {
  .scan-layout {
    grid-template-columns: 360px 1fr;
    align-items: start;
  }
}

.upload-zone {
  display: block;
  border: 2px dashed #475569;
  border-radius: 12px;
  padding: 24px 14px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
}

.upload-zone:hover { border-color: var(--accent); }
.upload-zone strong { display: block; color: var(--accent); font-size: 1.05rem; margin-bottom: 4px; }
.upload-zone span { color: var(--muted); font-size: 0.85rem; }
input[type="file"] { display: none; }

.preview-box {
  margin-top: 12px;
  text-align: center;
  display: none;
}

.preview-box img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.banner {
  display: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  margin-top: 12px;
}
.banner.info { background: var(--info-bg); color: var(--info-text); display: block; }
.banner.ok { background: var(--ok-bg); color: var(--ok-text); display: block; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); display: block; }
.banner.err { background: var(--err-bg); color: var(--err-text); display: block; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.full { grid-column: 1 / -1; }

label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.98rem;
}

textarea { min-height: 64px; resize: vertical; }

.btn {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-primary {
  background: var(--accent-btn);
  border-color: var(--accent);
  color: #fff;
}
.btn-block { width: 100%; padding: 13px; font-size: 1rem; margin-top: 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.pill {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill.connected { border-color: #22c55e; color: #86efac; background: #14532d; }
.pill.demo { border-color: #f59e0b; color: #fde68a; background: #78350f; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.kpi small { color: var(--muted); font-size: 0.8rem; }
.kpi strong { display: block; font-size: 1.4rem; margin-top: 4px; color: var(--accent); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
a { color: var(--accent); text-decoration: none; }

.inline-add {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  max-height: 90vh;
  overflow-y: auto;
}

.hidden { display: none !important; }

@media print {
  body { background: #fff; color: #000; padding: 0; }
  .topbar, .tabs, .no-print { display: none !important; }
  .card, .kpi { background: #fff; border-color: #cbd5e1; color: #000; }
  .kpi strong { color: #000; }
  th, td { border-color: #cbd5e1; color: #000; }
  #tab-report { display: block !important; }
}
