:root {
  --navy: #0f2438;
  --navy-light: #1c3c58;
  --accent: #b8860b;
  --accent-green: #1e7145;
  --accent-red: #a3312a;
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --border: #dde3e9;
  --text: #1a232c;
  --text-muted: #5b6b7a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 36, 56, 0.08), 0 1px 2px rgba(15, 36, 56, 0.06);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

h1, h2, h3, .serif {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--navy);
  margin: 0 0 0.4em;
}

a { color: var(--navy-light); }

button, .btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  padding: 0.55em 1.1em;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover, .btn:hover { border-color: var(--navy-light); }

.btn-primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.btn-primary:hover { background: var(--navy-light); }

.btn-danger { color: var(--accent-red); border-color: var(--accent-red); background: transparent; }

input, select, textarea {
  font: inherit;
  padding: 0.55em 0.7em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy-light); outline-offset: 1px; }

label { display: block; font-size: 0.85em; color: var(--text-muted); margin-bottom: 0.3em; }

/* ---------- Login / setup ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.2rem 2rem;
  text-align: center;
}
.auth-card h1 { font-size: 1.5rem; }
.auth-card p.subtitle { color: var(--text-muted); margin-top: -0.3em; margin-bottom: 1.4em; font-size: 0.92em; }
.auth-card form { display: flex; flex-direction: column; gap: 0.9em; text-align: left; }
.auth-error { color: var(--accent-red); font-size: 0.88em; min-height: 1.2em; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--navy);
  color: #fff;
  padding: 1.4rem 1rem;
  flex-shrink: 0;
}
.sidebar .brand { font-family: Georgia, serif; font-size: 1.15rem; margin-bottom: 1.6rem; padding: 0 0.5rem; }
.sidebar nav a {
  display: block;
  color: #cdd9e4;
  text-decoration: none;
  padding: 0.6em 0.7em;
  border-radius: 8px;
  margin-bottom: 0.15em;
  font-size: 0.95em;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #23180a; font-weight: 600; }
.sidebar .badge {
  display: inline-block;
  background: var(--accent-red);
  color: #fff;
  font-size: 0.7rem;
  border-radius: 999px;
  padding: 0.05em 0.5em;
  margin-left: 0.4em;
}
.sidebar .logout { margin-top: 2rem; }
.sidebar .logout button { width: 100%; background: transparent; color: #cdd9e4; border-color: rgba(255,255,255,0.25); }

.main { flex: 1; padding: 2rem 2.4rem; max-width: 1100px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem 1.6rem;
  margin-bottom: 1.4rem;
}

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.stat-tile { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.3rem; }
.stat-tile .label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-tile .value { font-family: Georgia, serif; font-size: 1.6rem; margin-top: 0.2em; color: var(--navy); }
.stat-tile .value.positive { color: var(--accent-green); }
.stat-tile .value.negative { color: var(--accent-red); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.55em 0.6em; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.subtotal td { font-weight: 700; border-top: 2px solid var(--navy); }
tr.grand-total td { font-weight: 700; font-size: 1.05em; border-top: 2px solid var(--navy); border-bottom: 3px double var(--navy); }

.pill { display: inline-block; padding: 0.15em 0.6em; border-radius: 999px; font-size: 0.78em; background: #eef2f6; color: var(--text-muted); }
.pill.uncategorized { background: #fdeeee; color: var(--accent-red); }

.toolbar { display: flex; gap: 0.6em; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.4rem 1rem;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
}
.dropzone.drag { border-color: var(--navy-light); background: #eef4f9; }

.question-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.3rem; margin-bottom: 1rem; }
.question-card .meta { color: var(--text-muted); font-size: 0.85em; margin-bottom: 0.7em; }
.category-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.4em; margin-bottom: 0.8em; }
.category-options label {
  display: flex; align-items: center; gap: 0.5em;
  border: 1px solid var(--border); border-radius: 8px; padding: 0.5em 0.7em;
  color: var(--text); font-size: 0.9em; cursor: pointer;
}
.category-options input { width: auto; }
.category-options label.selected { border-color: var(--navy); background: #eef4f9; }

.progress-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.progress-bar .fill { height: 100%; background: var(--accent-green); }

.report-header { text-align: center; margin-bottom: 1.6rem; }
.report-header .company { font-family: Georgia, serif; font-size: 1.6rem; color: var(--navy); }
.report-header .title { font-size: 1.05rem; color: var(--text-muted); margin-top: 0.2em; }
.report-header .period { font-size: 0.88rem; color: var(--text-muted); }

.chart-wrap { max-width: 100%; }

.msg { padding: 0.7em 1em; border-radius: 8px; font-size: 0.9em; margin-bottom: 1em; }
.msg.error { background: #fdeeee; color: var(--accent-red); }
.msg.success { background: #eaf6ee; color: var(--accent-green); }

.chat-panel {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6em;
  padding: 0.4em 0;
  margin-bottom: 0.8em;
}
.chat-message { padding: 0.6em 0.9em; border-radius: 10px; max-width: 80%; font-size: 0.92em; white-space: pre-wrap; }
.chat-message.user { align-self: flex-end; background: var(--navy); color: #fff; }
.chat-message.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
.chat-input-row { display: flex; gap: 0.6em; align-items: flex-end; }
.chat-input-row textarea { flex: 1; resize: vertical; font-family: inherit; }

.digest-history { list-style: none; margin: 0; padding: 0; }
.digest-history li:hover { background: #eef4f9; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; display: flex; align-items: center; gap: 1rem; }
  .sidebar nav { display: flex; gap: 0.3em; }
  .sidebar .logout { margin-top: 0; margin-left: auto; }
  .main { padding: 1.2rem; }
}

@media print {
  .sidebar, .toolbar, .no-print { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; padding: 0; }
  .view { display: none; }
  .view.active { display: block; }
}
