:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #64707d;
  --line: #e2e6eb;
  --accent: #0f5fa8;
  --accent-soft: #e6f0fa;
  --danger: #b42318;
  --sidebar: #12263f;
  --sidebar-ink: #c9d4e2;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand-name { color: #fff; font-weight: 600; line-height: 1.1; }
.brand-name small { color: var(--sidebar-ink); font-weight: 400; }
nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  background: none; border: 0; color: inherit; text-align: left;
  padding: 10px 12px; border-radius: 8px; font: inherit; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; }
.sidebar-foot { margin-top: auto; font-size: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.user-email { opacity: .7; word-break: break-all; }
.btn.ghost { background: transparent; color: var(--sidebar-ink); border-color: rgba(255,255,255,.2); }
.btn.ghost:hover { border-color: rgba(255,255,255,.45); }

/* Sign-in gate */
.gate {
  position: fixed; inset: 0; z-index: 10; background: var(--bg);
  display: grid; place-items: center; padding: 16px;
}
.gate[hidden] { display: none; }
.gate-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 28px;
}
.gate-brand { margin-bottom: 20px; }
.gate-brand .brand-name { color: var(--ink); }
.gate-card h2 { font-size: 18px; margin: 0 0 6px; }
.gate-card input {
  width: 100%; font: inherit; padding: 9px 12px; margin: 12px 0;
  border: 1px solid var(--line); border-radius: 7px;
}
.gate-card form .btn { padding: 9px 12px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* Main */
main { flex: 1; padding: 28px 32px; overflow-x: hidden; }
.view { display: none; max-width: 1100px; }
.view.active { display: block; }
.view-head h1 { margin: 0 0 4px; font-size: 24px; }
.view-head p { margin: 0 0 20px; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 6px;
}
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 28px; font-weight: 600; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; }
.activity li:last-child { border-bottom: 0; }
.activity time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Upload */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 2px dashed #b8c4d2; border-radius: var(--radius);
  background: var(--panel); padding: 36px 20px; margin-bottom: 16px;
  text-align: center; cursor: pointer; transition: .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .hint { color: var(--muted); font-size: 12px; max-width: 520px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table td:last-child { text-align: right; white-space: nowrap; }

.empty { color: var(--muted); }

/* Controls */
.btn, select {
  font: inherit; border-radius: 7px; border: 1px solid var(--line);
  padding: 7px 12px; background: var(--panel); color: var(--ink);
}
.btn { cursor: pointer; }
.btn:hover { border-color: #b8c4d2; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: #f1c4c0; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.full { width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.split .card { margin-bottom: 0; }
.preview {
  background: var(--bg); border-radius: 7px; padding: 12px;
  max-height: 360px; overflow: auto; white-space: pre-wrap; font-size: 12px; margin: 0;
}
.output { line-height: 1.55; }
.output h3 { font-size: 13px; margin: 14px 0 6px; }
.output h3:first-child { margin-top: 0; }
.output ul { margin: 0; padding-left: 18px; }

.tag { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 8px; font-size: 11px; margin: 2px 4px 2px 0; }
.badge { display: inline-block; background: #fef3c7; color: #92400e; border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.badge.ok { background: #dcfce7; color: #166534; }
.muted { color: var(--muted); }
button:disabled { opacity: .6; cursor: wait; }

.report h2 { display: flex; justify-content: space-between; align-items: baseline; }
.report h2 small { color: var(--muted); font-weight: 400; font-size: 12px; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--sidebar); color: #fff;
  padding: 10px 16px; border-radius: 8px; opacity: 0; transform: translateY(8px);
  transition: .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

@media (max-width: 800px) {
  body { flex-direction: column; }
  .sidebar { width: auto; padding: 12px 16px; }
  .brand { margin-bottom: 10px; }
  nav { flex-direction: row; overflow-x: auto; }
  .sidebar-foot { flex-direction: row; align-items: center; margin-top: 10px; }
  main { padding: 20px 16px; }
  .split { grid-template-columns: 1fr; }
}
