:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-1: #f7f7f5;
  --border: #e2e2de;
  --text: #1a1a18;
  --text-secondary: #6b6b66;
  --text-muted: #9a9a94;
  --accent: #185fa5;
  --accent-bg: #e6f1fb;
  --success: #0f6e56;
  --success-bg: #e1f5ee;
  --warning: #854f0b;
  --warning-bg: #faeeda;
  --danger: #a32d2d;
  --danger-bg: #fcebeb;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1a;
    --surface: #242422;
    --surface-1: #2a2a27;
    --border: #3a3a36;
    --text: #f0f0ec;
    --text-secondary: #b5b5ae;
    --text-muted: #85857e;
    --accent-bg: #0c447c;
    --success-bg: #085041;
    --warning-bg: #633806;
    --danger-bg: #791f1f;
  }
}

* { box-sizing: border-box; }

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

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
}

.brand { font-weight: 600; padding: 0 0.5rem 1rem; font-size: 15px; }

.nav-links { display: flex; flex-direction: column; gap: 2px; }

.navlink {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
}
.navlink:hover { background: var(--surface); }
.navlink.active { background: var(--accent-bg); color: var(--accent); }
.navlink.small { font-size: 12px; padding: 4px 10px; }

.sidebar-bottom {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lang-form select {
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.small { font-size: 12px; }

.content { flex: 1; padding: 1.5rem 2rem; min-width: 0; }

h1 { font-size: 20px; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 15px; font-weight: 600; color: var(--text-secondary); margin: 1.5rem 0 0.5rem; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.metric { background: var(--surface-1); border-radius: var(--radius); padding: 1rem; }
.metric .label { font-size: 13px; color: var(--text-secondary); margin: 0 0 6px; }
.metric .value { font-size: 24px; font-weight: 600; margin: 0; }
.metric .value.danger { color: var(--danger); }

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

.row-link { text-decoration: none; color: inherit; cursor: pointer; }
.row-link:hover { border-color: var(--border-strong, var(--border)); background: var(--surface-1); }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13px;
}
.row.small { font-size: 12px; padding: 8px 12px; }

.row .flex { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row .flex .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.channel { font-size: 12px; color: var(--text-muted); text-transform: uppercase; min-width: 70px; flex-shrink: 0; }
.muted { color: var(--text-secondary); }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }

.badge {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}
.badge.success, .status-ai_answered, .status-resolved, .status-paid { background: var(--success-bg); color: var(--success); }
.badge.warning, .status-escalated, .status-sent { background: var(--warning-bg); color: var(--warning); }
.badge.danger, .status-unsorted, .status-overdue { background: var(--danger-bg); color: var(--danger); }
.status-new, .status-draft, .badge.accent, .status-ai_synthesized { background: var(--accent-bg); color: var(--accent); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.card-title { font-weight: 600; font-size: 14px; margin: 0 0 6px; }
.card-title a { color: inherit; text-decoration: none; }
.card-title a:hover { text-decoration: underline; }

.detail-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.detail-header h1 { margin: 0; }

.file-preview {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 420px;
  overflow-y: auto;
}

.qa-list { display: flex; flex-direction: column; gap: 10px; }
.qa-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.qa-question { margin: 0 0 10px; font-size: 14px; }
.qa-answer { margin: 0; font-size: 14px; color: var(--text-secondary); }

.invoice-paper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 640px;
}
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; }
.invoice-issuer { font-weight: 600; font-size: 16px; margin: 0 0 4px; }
.invoice-meta { display: flex; gap: 2.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.invoice-meta p { margin: 0 0 2px; }
.invoice-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.invoice-table th, .invoice-table td { text-align: left; padding: 10px 0; border-bottom: 1px solid var(--border); }
.invoice-table tfoot td { border-bottom: none; border-top: 1px solid var(--border); padding-top: 12px; font-size: 15px; }
.align-right { text-align: right; }

form.toggle { margin: 0; }
button.link-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
button.link-btn:hover { background: var(--surface-1); }

.placeholder {
  color: var(--text-secondary);
  padding: 2rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.project-switch { padding: 0 0 1rem; }
.project-switch select {
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.admin-links { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }

.section { margin-bottom: 2rem; }

.form { display: flex; flex-direction: column; gap: 14px; max-width: 480px; }
.field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=file], .field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
.field .help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field .errors { font-size: 12px; color: var(--danger); margin-top: 4px; }

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

.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: var(--surface-1); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.9; background: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; background: var(--danger); }

.messages { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 8px; }
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); margin-bottom: 1rem; }
.alert-demo { background: var(--warning-bg); color: var(--warning); margin-bottom: 1rem; }

.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}
.login-card .brand { font-weight: 600; font-size: 16px; margin: 0 0 1.25rem; }
.login-card .form { max-width: none; }
