:root {
  --navy: #0b1f3f; --blue: #1a7bff; --cyan: #20a4e8; --purple: #6d3ae6;
  --bg: #f3f6fb; --card: #fff; --line: #e1e8f4; --text: #14233f; --muted: #6b7a93; --danger: #d92d4b; --ok: #14a35c; --warn: #d98a0b;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 'Hanken Grotesk', 'Open Sans', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .center { text-align: center; padding: 40px 16px; }
[hidden] { display: none !important; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; height: 56px; background: var(--navy); color: #fff; }
.top .brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; }
.top .brand img { width: 28px; height: 28px; border-radius: 6px; background: #fff; padding: 2px; }
.top .brand em { font-style: normal; font-weight: 500; opacity: .7; }
.top nav { display: flex; align-items: center; gap: 4px; }
.top nav a { color: #cfd9ee; padding: 7px 12px; border-radius: 8px; font-weight: 600; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.top .ghost { color: #cfd9ee; border-color: rgba(255,255,255,.25); }

/* buttons */
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; font-weight: 600; transition: background .12s, border-color .12s; }
button:hover { border-color: #c5d2e8; background: #f8faff; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.primary:hover { background: #0f6ae8; }
button.dark { background: var(--navy); border-color: var(--navy); color: #fff; }
button.wa { background: #1fa855; border-color: #1fa855; color: #fff; }
button.wa:hover { background: #178f47; }
button.danger { color: var(--danger); }
button.ghost { background: transparent; }
button.sm { padding: 5px 10px; font-size: 13px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

main.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head-row h1 { font-size: 22px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat small { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }
.stat b { display: block; font-size: 22px; margin-top: 2px; }
.stat span { color: var(--muted); font-size: 12px; }

/* list */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; background: #e8eef9; border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--navy); box-shadow: 0 1px 2px rgba(11,31,63,.12); }
.filters input[type=search] { flex: 1; min-width: 180px; max-width: 340px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.table-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: visible; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafcff; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover { background: #f8faff; }
table.list .num { font-weight: 700; color: var(--navy); }
table.list .r { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 700; background: #e8eef9; color: var(--navy); white-space: nowrap; }
.badge.PAID, .badge.Accepted { background: #dcf6e8; color: #0b7a43; }
.badge.UNPAID, .badge.Rejected { background: #fde4e8; color: #b3203b; }
.badge.PART-PAID, .badge.Sent { background: #fdf0d3; color: #996000; }
.badge.type { background: #e5f1ff; color: #0f5fd0; }
.badge.type.quotation { background: #efe8ff; color: #5a2fc4; }
.acts { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-weight: 700; user-select: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary { background: #f1f5fc; }
details.menu .pop { position: absolute; right: 0; top: calc(100% + 4px); min-width: 210px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(11,31,63,.16); padding: 5px; z-index: 30; }
details.menu .pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; }
details.menu .pop button:hover { background: #f1f5fc; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* editor */
.ed-bar { position: sticky; top: 56px; z-index: 15; background: rgba(243,246,251,.94); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ed-bar .ttl { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ed-bar h2 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dirty { font-size: 12px; font-weight: 700; color: var(--warn); }
.dirty.ok { color: var(--ok); }
.split { display: grid; grid-template-columns: minmax(360px, 500px) 1fr; gap: 0; align-items: start; }
.form-col { padding: 18px 20px 80px; display: flex; flex-direction: column; gap: 14px; }
.pv-col { position: sticky; top: 112px; height: calc(100vh - 112px); overflow: auto; padding: 18px 12px 40px; background: #dde5f2; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px 16px; margin: 0; min-width: 0; }
.card > legend, .card > h3 { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--blue); padding: 0; margin: 0 0 10px; display: block; float: none; width: 100%; }
fieldset.card { border: 1px solid var(--line); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
label.f:last-child { margin-bottom: 0; }
.grid2 label.f { margin-bottom: 0; }
.grid2 + label.f, label.f + .grid2, .grid2 + .grid2 { margin-top: 10px; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=tel], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d3dcec; border-radius: 8px; background: #fff; min-width: 0; }
textarea { resize: vertical; line-height: 1.4; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.numrow { display: flex; gap: 8px; align-items: center; }
.numrow input { flex: 1; }
.auto { font-size: 11px; font-weight: 700; color: var(--ok); background: #dcf6e8; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }

.item { border: 1px solid var(--line); border-radius: 9px; padding: 10px; margin-bottom: 10px; background: #fbfcff; }
.item-h { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.item-h b { color: var(--navy); }
.item-h .amt { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 6px; }
.item-h button { padding: 2px 8px; }
.item label.f { margin-bottom: 8px; }
.sum { margin-top: 12px; background: #f3f7ff; border-radius: 9px; padding: 8px 12px; }
.sum div { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.sum .tot { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; font-weight: 800; }
.sum .due { color: var(--blue); font-weight: 800; font-size: 15px; }
.tabs-m { display: none; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--navy), #16337a 60%, #2a2f9c); }
.login form { background: #fff; width: 100%; max-width: 360px; padding: 28px; border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.login img.logo { width: 64px; margin: 0 auto 6px; display: block; }
.login h1 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.login p { text-align: center; margin: 0 0 18px; color: var(--muted); }
.login button { width: 100%; margin-top: 12px; padding: 10px; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: 90vw; font-weight: 600; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); }

/* share page */
body.share { background: #dde5f2; }
.share-host { padding: 20px 8px 40px; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .tabs-m { display: flex; gap: 6px; padding: 10px 20px 0; }
  .tabs-m button { flex: 1; }
  .tabs-m button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
  .split[data-tab="edit"] .pv-col, .split[data-tab="preview"] .form-col { display: none; }
  .pv-col { position: static; height: auto; min-height: 70vh; }
  .stats { grid-template-columns: 1fr; }
  .ed-bar { top: 56px; padding: 8px 12px; }
  main.wrap { padding: 16px 12px 60px; }
  .top { padding: 0 12px; } .top .brand em { display: none; }
  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; }
  table.list tr { padding: 10px 14px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
  table.list td { padding: 0; border: 0; }
  table.list td.c-actions { grid-column: 1 / -1; margin-top: 6px; }
  table.list td.c-date, table.list td.c-project { color: var(--muted); font-size: 13px; }
  .acts { justify-content: flex-start; flex-wrap: wrap; }
}
