/* Invoicer admin UI */
:root {
  --bg: #f5f3f0;
  --surface: #fff;
  --ink: #1c1d21;
  --muted: #6b6f78;
  --line: #e4e1dc;
  --navy: #1b2a55;
  --accent: #e8702f;
  --accent-ink: #fff;
  --ok: #1f7a4d; --ok-bg: #e5f4ec;
  --warn: #8a5a00; --warn-bg: #fff3d6;
  --err: #a8321f; --err-bg: #fde8e4;
  --info: #24407e; --info-bg: #e8eefb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,20,30,.05), 0 2px 10px rgba(20,20,30,.04);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--navy); }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0 0 12px; }
.section-title { font-size: 17px; margin: 28px 0 4px; }
.mono { font-family: var(--mono); letter-spacing: .01em; }
.upper { text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.big { font-size: 18px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 28px; padding: 0 24px; height: 60px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 24px; height: 24px; background: url(icons/brand-128.png) center / contain no-repeat; display: inline-block; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.topbar nav a:hover { background: var(--bg); color: var(--ink); }
.topbar nav a.active { background: var(--bg); color: var(--ink); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.muted-link { color: var(--muted); text-decoration: none; font-size: 13px; }

.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.back { display: inline-block; color: var(--muted); text-decoration: none; font-size: 13px; margin-bottom: 6px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.narrow { max-width: 720px; }
.table-card { padding: 0; overflow-x: auto; }
.empty { text-align: center; padding: 48px 20px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #cfcac2; background: #fbfaf8; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #d9611f; border-color: #d9611f; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(0,0,0,.04); border-color: transparent; color: var(--ink); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.copied { background: var(--ok-bg); border-color: var(--ok-bg); color: var(--ok); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.icon-btn { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--err-bg); color: var(--err); }

/* Forms */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
label .muted { font-weight: 400; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 8px 10px; font: inherit; font-weight: 400;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(232,112,47,.35); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; display: inline-block; margin: 0 8px 0 0; accent-color: var(--accent); }
input[type=file] { padding: 6px; }
label.check { display: flex; align-items: center; font-weight: 500; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
label.inline select { margin: 0; width: auto; }
textarea { resize: vertical; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.code-row { grid-template-columns: 160px 1fr; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 8px; }
.inline-form select { margin: 0; min-width: 200px; }

/* Invoice form */
.form-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.form-grid > .card { margin-bottom: 16px; }
.preview-card { background: #fbfaf8; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; word-break: break-all; }
.items-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.items-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 6px 8px; border-bottom: 1px solid var(--line); }
.items-table td { padding: 8px 6px; vertical-align: top; border-bottom: 1px solid var(--line); }
.items-table input { margin: 0; }
.items-table input.sub { margin-top: 6px; font-style: italic; font-size: 13px; }
.items-table .c-idx { width: 28px; color: var(--muted); padding-top: 16px; }
.items-table .c-qty { width: 90px; }
.items-table .c-price { width: 130px; }
.items-table .c-amt { width: 120px; padding-top: 16px; font-weight: 600; }
.items-table th.c-amt, .items-table th.c-qty, .items-table th.c-price { text-align: right; }
.items-table .c-del { width: 36px; padding-top: 10px; }
input.num { text-align: right; }
.totals { margin-left: auto; max-width: 360px; margin-top: 10px; }
.totals-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals-row input.tiny { display: inline-block; width: 64px; margin: 0 4px 0 0; padding: 4px 6px; }
.tax-row.is-zero #t-tax { color: var(--muted); }
.totals-row.grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 16px; }
.sticky-actions {
  position: sticky; bottom: 0; background: rgba(245,243,240,.92); backdrop-filter: blur(6px);
  padding: 12px 0; border-top: 1px solid var(--line); margin-top: 0;
}
.sticky-actions .reason { margin: 0 auto 0 0; max-width: 420px; }

/* Invoice page */
.show-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.preview-frame-card { padding: 0; overflow: hidden; }
.preview-frame { width: 100%; height: 1120px; border: 0; display: block; }
.side .card { margin-bottom: 16px; }
.pay-link { display: flex; gap: 14px; align-items: flex-start; }
.qr { border: 1px solid var(--line); border-radius: 8px; flex: none; }
.short-url { font-size: 15px; word-break: break-all; }
.url-block { display: block; margin-top: 8px; padding: 8px; background: var(--bg); border-radius: 6px; font-size: 11.5px; word-break: break-all; font-family: var(--mono); }
details > summary { cursor: pointer; }
details.small { margin-top: 12px; }
.email-text { font-size: 13px; background: #fbfaf8; }
.list { list-style: none; margin: 0 0 12px; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list form { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 13px; }
.payment-form label { margin-bottom: 10px; }

/* "More" menu */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: 6px;
}
.menu-panel form { margin: 0; }
.menu-panel button { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-panel button:hover, .menu-panel .menu-item:hover { background: var(--bg); }
.menu-panel .menu-item { display: block; padding: 8px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.menu-panel button.danger { color: var(--err); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fbfaf8; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: #fbfaf8; }
.row-link a { text-decoration: none; }
.is-archived td { opacity: .55; }
.table.compact td, .table.compact th { padding: 8px; }
.table.compact input { margin: 0; }

/* Toolbar + tabs */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; background: #ebe8e3; padding: 3px; border-radius: 9px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: 13px; }
.tabs a.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Stats */
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; min-width: 150px; text-decoration: none; color: var(--ink); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-attention { border-color: #f0d58a; background: var(--warn-bg); }
.stat-danger { border-color: #f3c2b8; background: var(--err-bg); }

/* Badges */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #ecebe8; color: var(--muted); vertical-align: middle; font-family: Inter, system-ui, sans-serif; letter-spacing: 0; }
.badge-draft { background: #ecebe8; color: #555; }
.badge-sent { background: var(--info-bg); color: var(--info); }
.badge-overdue { background: var(--err-bg); color: var(--err); }
.badge-client_reported { background: var(--warn-bg); color: var(--warn); }
.badge-paid { background: var(--ok-bg); color: var(--ok); }
.badge-void { background: #ecebe8; color: #888; text-decoration: line-through; }

/* Flash */
[hidden] { display: none !important; }
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid transparent; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); display: block; }
.flash-info { background: var(--info-bg); color: var(--info); display: block; }
.flash-attention { background: var(--warn-bg); color: var(--warn); border-color: #f0d58a; }
.flash form { margin: 0; }

/* Settings */
.company-card > summary { display: flex; align-items: center; gap: 10px; }
.company-card[open] > summary { margin-bottom: 16px; }
.mini-logo { height: 28px; width: auto; }

/* Login + public pages */
.center-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { margin-bottom: 20px; }
.message-card { max-width: 440px; text-align: center; padding: 36px 32px; }
.message-card h1 { justify-content: center; margin-bottom: 10px; }
.message-logo { width: 110px; height: auto; margin-bottom: 18px; }

@media (max-width: 960px) {
  .show-grid, .form-grid { grid-template-columns: 1fr; }
  .preview-frame { height: 760px; }
}
@media (max-width: 640px) {
  .topbar { gap: 12px; padding: 0 16px; height: auto; min-height: 56px; flex-wrap: wrap; }
  .topbar-right .btn { padding: 6px 10px; }
  .page { padding: 20px 16px 80px; }
  .row-2, .row-3, .code-row { grid-template-columns: 1fr; gap: 0; }
  .items-table thead { display: none; }
  .items-table tr { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .items-table td { border: 0; padding: 0; width: auto !important; }
  .items-table td:nth-child(2) { grid-column: 1 / -1; }
  .items-table .c-idx { display: none; }
}

/* Settings: webhook steps */
.steps { padding-left: 20px; margin: 0 0 16px; }
.steps li { margin-bottom: 10px; }
.copy-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.copy-row .url-block { margin: 0; flex: 1; }

/* Email compose */
.attachment { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfaf8; margin-bottom: 14px; }
.attachment-icon { flex: none; width: 40px; height: 48px; border-radius: 4px; background: #d9412f; color: #fff; font-weight: 700; font-size: 11px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Setup + system checks */
.setup { width: 100%; max-width: 620px; }
.setup .brand { margin-bottom: 18px; }
.setup h1 { margin-bottom: 6px; }
.setup > p { margin: 0 0 18px; }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.checks li:last-child { border-bottom: 0; }
.check-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; margin-top: 1px; }
.check-ok .check-icon { background: var(--ok-bg); color: var(--ok); }
.check-warn .check-icon { background: var(--warn-bg); color: var(--warn); }
.check-fail .check-icon { background: var(--err-bg); color: var(--err); }
.version { color: var(--muted); font-size: 12px; text-align: center; margin-top: 40px; }

/* Log viewer */
pre.log { margin: 0; max-height: 340px; overflow: auto; background: #1c1d21; color: #d6d6d6; border-radius: 8px; padding: 12px; font: 11.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; }
pre.log .log-error { color: #ff8f7a; }
pre.log .log-warn { color: #f5c96a; }
label.check span { font-weight: 400; }
label.check { align-items: flex-start; }
label.check input { margin-top: 3px; }

/* Client-facing invoice page */
.client-page { background: var(--bg); }
.client-wrap { max-width: 860px; margin: 0 auto; padding: 28px 16px 60px; }
.client-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.client-logo { height: 48px; width: auto; }
.client-summary { text-align: center; padding: 28px 20px; }
.client-for { font-weight: 600; margin-top: 4px; }
.client-amount { font-size: 38px; font-weight: 800; letter-spacing: -.02em; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.client-status { display: inline-block; font-weight: 600; font-size: 13px; padding: 4px 12px; border-radius: 999px; background: var(--info-bg); color: var(--info); margin-bottom: 6px; }
.client-status.status-paid { background: var(--ok-bg); color: var(--ok); }
.client-status.status-overdue { background: var(--err-bg); color: var(--err); }
.client-status.status-client_reported { background: var(--warn-bg); color: var(--warn); }
.client-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.btn-lg { padding: 13px 22px; font-size: 16px; border-radius: 10px; }
.client-note { max-width: 520px; margin: 16px auto 0; }
.client-sheet { padding: 0; overflow: hidden; }
.client-frame { width: 100%; height: 1120px; border: 0; display: block; }
.client-foot { text-align: center; margin-top: 8px; }
@media (max-width: 640px) {
  .client-amount { font-size: 32px; }
  .client-actions .btn { width: 100%; }
}

.reroute-box { border: 1px solid var(--line); border-radius: 8px; padding: .5rem 1rem 1rem; margin: 1rem 0; }
.reroute-box legend { font-weight: 600; padding: 0 .4rem; }
.reroute-form { margin-top: .5rem; }
