:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e3e8ee;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --danger: #dc2626;
  --ok: #059669;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
a { color: var(--primary); text-decoration: none; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; background: #eef1f5; color: var(--ink); transition: .12s; }
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- auth ---------- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--card); padding: 32px; border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.auth-card .brand { margin: 0; font-size: 22px; text-align: center; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.auth-card input { padding: 10px 12px; }

/* ---------- topbar ---------- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 24px; padding: 10px 20px; }
.logo { font-weight: 700; font-size: 16px; }
.nav { display: flex; gap: 6px; margin-right: auto; }
.nav-link { padding: 8px 14px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.nav-link.active { background: #eef2ff; color: var(--primary); }

/* ---------- layout ---------- */
.view { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .spacer { margin-left: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-body { padding: 18px; }

/* ---------- forms ---------- */
input, select, textarea { font-family: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-weight: 600; font-size: 12.5px; color: var(--muted); }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.form-error { color: var(--danger); font-size: 13px; min-height: 16px; }
.inline { display: flex; gap: 10px; align-items: center; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
td .right, th.right { text-align: right; }
tr:last-child td { border-bottom: none; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #eef2ff; color: var(--primary); }
.tag.q { background: #fef3c7; color: #b45309; }
.tag.p { background: #ede9fe; color: #6d28d9; }

/* ---------- line items ---------- */
.items-table td { padding: 6px 8px; vertical-align: top; }
.items-table input { padding: 7px 8px; }
.items-table .col-qty { width: 90px; }
.items-table .col-price { width: 130px; }
.items-table .col-total { width: 120px; text-align: right; white-space: nowrap; padding-top: 14px; }
.items-table .col-del { width: 40px; }
.linkish { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 18px; line-height: 1; }

/* ---------- totals ---------- */
.totals { margin-left: auto; max-width: 320px; }
.totals .row { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .row.grand { border-top: 2px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 16px; }

/* ---------- letterhead preview ---------- */
.lh-preview { position: relative; display: inline-block; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; max-width: 340px; }
.lh-preview img { display: block; width: 100%; }
.lh-safebox { position: absolute; background: rgba(37,99,235,.14); border: 2px solid var(--primary); pointer-events: none; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff;
  padding: 12px 20px; border-radius: 8px; box-shadow: var(--shadow); z-index: 100; font-weight: 600; }
.toast.err { background: var(--danger); }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { border: none; background: #fff; padding: 8px 16px; cursor: pointer; font-weight: 600; color: var(--muted); }
.segmented button.active { background: var(--primary); color: #fff; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
