:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #0f6e5c; --accent-2: #0b5547; --danger: #b42318; --warn: #b54708;
  --radius: 10px;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
main { max-width: 1150px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; padding: .6rem 1rem; background: #13202b; }
.nav a, .nav .linkish { color: #cfd8e0; padding: .4rem .7rem; border-radius: 6px; font-size: .95rem; }
.nav a:hover, .nav .linkish:hover { background: #22323f; color: #fff; text-decoration: none; }
.nav a.active { background: #22323f; color: #fff; }
.nav .brand { color: #fff; font-weight: 700; margin-right: .8rem; }
.nav .spacer { flex: 1; }
.nav form { margin: 0; }

.head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; margin-bottom: 1rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; }

.btn { display: inline-block; padding: .5rem .9rem; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 7px; font: inherit; cursor: pointer; line-height: 1.2; }
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); border-color: #f1c4c0; }
.btn.small { padding: .3rem .6rem; font-size: .88rem; }
.linkish { background: none; border: 0; font: inherit; cursor: pointer; color: var(--muted); padding: .2rem .4rem; }
form.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }

input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #cfd4db; border-radius: 7px; background: #fff; width: 100%; color: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8fd0c2; border-color: var(--accent); }
form.inline input, form.inline select { width: auto; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
label.block { margin-top: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.narrow { max-width: 420px; }
.danger-zone { margin-top: 1rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { border-bottom: 0; }
tr.grand td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--text); }
.items input { min-width: 90px; }
.items td:first-child input { min-width: 220px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions a { margin-left: .7rem; font-size: .88rem; }
.overdue { color: var(--danger); font-weight: 600; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px;
  background: #eef0f3; color: #475467; text-transform: capitalize; }
.badge.new, .badge.draft { background: #eef4ff; color: #3538cd; }
.badge.in_progress, .badge.sent, .badge.unpaid { background: #fff6e5; color: var(--warn); }
.badge.completed, .badge.paid, .badge.signed { background: #e7f6ef; color: #067647; }
.badge.cancelled, .badge.expired { background: #fdecea; color: var(--danger); }

.filters { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters a { padding: .3rem .8rem; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--text); font-size: .88rem; text-transform: capitalize; }
.filters a.active { background: var(--text); color: #fff; border-color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; color: var(--muted); font-size: .9rem; }
.stat span { display: block; font-size: 1.6rem; font-weight: 700; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--accent); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: #e7f6ef; color: #067647; }
.flash.error { background: #fdecea; color: var(--danger); }

.login { max-width: 400px; margin: 10vh auto; }
.login h1 { margin-bottom: .2rem; }

.meta { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.docs { list-style: none; padding: 0; margin: 0; }
.docs li { padding: .3rem 0; }

@media print {
  body { background: #fff; }
  .no-print, .nav { display: none !important; }
  main { padding: 0; max-width: none; }
  a { color: inherit; }
}

/* v2: branding, admin, auth */
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 82%, black); }
.nav .brand { display: inline-flex; align-items: center; gap: .5rem; }
.nav .brand img { height: 26px; width: auto; max-width: 120px; object-fit: contain; background: #fff; border-radius: 4px; padding: 2px; }
.login-logo { display: block; max-height: 70px; max-width: 200px; margin: 0 auto 1rem; object-fit: contain; }
.login h1 { text-align: center; }
.login > .muted { text-align: center; }
.center { text-align: center; }
.btn.google { display: flex; align-items: center; justify-content: center; gap: .6rem; width: 100%; font-weight: 500; padding: .6rem; }
.or { display: flex; align-items: center; gap: .8rem; color: var(--muted); font-size: .85rem; margin: 1rem 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.code-input { font-size: 1.4rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.hint { font-weight: 400; font-size: .8rem; color: var(--muted); }
label.check, span.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
label.check input, span.check input { width: auto; }
input[type=color] { height: 2.4rem; padding: .2rem; }
input[type=file] { width: auto; max-width: 100%; }
form.inline.wrap { flex-wrap: wrap; }
code { background: #f0f2f5; padding: .1rem .35rem; border-radius: 4px; font-size: .85em; }
code.copy { user-select: all; word-break: break-all; }
.logo-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.logo-preview { width: 140px; height: 70px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; overflow: hidden; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sticky-save { position: sticky; bottom: 0; background: var(--bg); padding: .8rem 0; margin-top: 0; }

/* v3: document toolbar & design picker */
.doc-toolbar { display: flex; justify-content: flex-end; align-items: center; gap: .5rem; flex-wrap: wrap; max-width: 820px; margin: 0 auto 1rem; }
.design-picker select { width: auto; }
.design-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; }
.design-card { border: 1px solid var(--line); border-radius: 8px; padding: .8rem; display: flex; flex-direction: column; gap: .4rem; font-weight: 400; cursor: pointer; }
.design-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.design-card .row { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.design-card input { width: auto; }
.design-card .swatch { height: 46px; border-radius: 5px; border: 1px solid var(--line); background: #fff; position: relative; overflow: hidden; }
.swatch.s-classic::before { content: ""; position: absolute; left: 8px; right: 8px; top: 16px; border-top: 2px solid #1d2330; }
.swatch.s-modern::before { content: ""; position: absolute; left: 4px; right: 4px; top: 4px; height: 16px; border-radius: 3px; background: var(--accent); }
.swatch.s-minimal::before { content: ""; position: absolute; left: 10px; right: 10px; top: 24px; border-top: 1px solid #c9ced6; }
.swatch.s-formal::before { content: "Aa"; position: absolute; inset: 0; display: grid; place-items: center; font-family: Georgia, serif; font-size: 20px; border-bottom: 3px double #1d2330; }
h3.sub { font-size: .95rem; margin: 1rem 0 .5rem; }
