/* Light, flat, professional. White surfaces on a light grey page, dark
   grey text, one blue accent for focus/selection. No rounded corners, no
   decorative shadows. Editor-specific rules live in editor.css. */

:root {
  --bg: #f3f4f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --border: #d9d9d9;
  --border-strong: #b5b5b5;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --ok: #2e7d32;
  --ok-soft: #e8f5e9;
  --warn: #b26a00;
  --warn-soft: #fff4e0;
  --ink: #1f1f1f;
  --topbar-h: 52px;
}

* { margin: 0; padding: 0; box-sizing: border-box; border-radius: 0 !important; }

html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.4;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---- topbar ------------------------------------------------------------ */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 20px;
  height: 100%; display: flex; align-items: center; gap: 28px;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: 0.01em; white-space: nowrap; }
.nav { display: flex; gap: 4px; height: 100%; }
.nav a {
  display: flex; align-items: center; padding: 0 12px; height: 100%;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--text); border-bottom-color: var(--ink); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-name { color: var(--muted); }

/* ---- layout ------------------------------------------------------------ */
.view { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { font-size: 22px; font-weight: 700; }
.page-head .spacer { flex: 1; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); padding: 16px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px 24px; }
@media (max-width: 800px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mt { margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---- controls ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); cursor: pointer; white-space: nowrap; line-height: 1;
}
.btn:hover { background: #f4f4f4; }
.btn:active { background: #ececec; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #333; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #ededed; }
.btn.icon { width: 32px; padding: 0; }
.btn svg { width: 18px; height: 18px; display: block; flex-shrink: 0; }
.btn.small { height: 26px; padding: 0 8px; font-size: 12.5px; }
.btn.small svg { width: 15px; height: 15px; }
.btn.busy { opacity: 0.6; pointer-events: none; }

.input, .select, .textarea {
  height: 32px; padding: 0 8px; background: var(--surface);
  border: 1px solid var(--border-strong); width: 100%; outline: none;
}
.textarea { height: auto; min-height: 64px; padding: 6px 8px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.input.invalid { border-color: var(--danger); }
.input[readonly] { background: #f7f7f7; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; color: var(--muted); }
.field-row { display: flex; gap: 8px; }
.field-row > .field { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--ink); }

/* ---- tables ------------------------------------------------------------ */
.table-wrap { background: var(--surface); border: 1px solid var(--border); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: #fafafa; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: #f7f9fc; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions .btn { vertical-align: middle; }
.table .empty { color: var(--muted); text-align: center; padding: 28px; }
.table td.check-cell, .table th.check-cell { width: 34px; }

.badge {
  display: inline-block; padding: 2px 7px; font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.02em; text-transform: uppercase; border: 1px solid transparent; line-height: 1.4;
}
.badge.draft { background: #efefef; color: #555; border-color: #ddd; }
.badge.issued { background: var(--accent-soft); color: #1d4ed8; border-color: #c7d7fb; }
.badge.paid { background: var(--ok-soft); color: var(--ok); border-color: #c8e6c9; }
.badge.overdue { background: var(--danger-soft); color: var(--danger); border-color: #f5c6c2; }

.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 8px 12px; cursor: pointer; color: var(--muted);
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--ink); }
.tabs .count { color: var(--muted); font-size: 12px; margin-left: 4px; }

.stats { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); padding: 10px 14px; min-width: 150px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- login ------------------------------------------------------------- */
.login-wrap { min-height: calc(100vh - 80px); display: flex; align-items: center; justify-content: center; }
.login { width: 360px; max-width: 100%; }
.login h1 { font-size: 20px; margin-bottom: 4px; }
.login .sub { color: var(--muted); margin-bottom: 18px; }
.login .field { margin-bottom: 12px; }
.login .error { color: var(--danger); margin-bottom: 10px; min-height: 18px; }

/* ---- toasts, dialog ---------------------------------------------------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--ink); color: #fff; padding: 10px 14px; min-width: 220px; max-width: 420px;
  border-left: 3px solid #888; animation: toast-in 0.15s ease-out;
}
.toast.success { border-left-color: #66bb6a; }
.toast.error { border-left-color: #ef5350; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.dialog-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.dialog { background: var(--surface); border: 1px solid var(--border); padding: 20px; width: 420px; max-width: 100%; }
.dialog p { margin-bottom: 18px; white-space: pre-line; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- settings ---------------------------------------------------------- */
.logo-preview { max-width: 240px; max-height: 100px; display: block; border: 1px solid var(--border); padding: 6px; background: #fff; }
.settings-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.hint { font-size: 12px; color: var(--muted); }

@media (max-width: 700px) {
  .topbar-inner { gap: 12px; padding: 0 12px; }
  .nav a { padding: 0 8px; }
  .user-name { display: none; }
  .view { padding: 14px 12px 40px; }
}
