/* Straven Books — quiet ledger look: deep green sidebar, warm paper canvas, white cards, Inter. */
:root {
  --ink: #17221f;
  --ink-2: #4a5753;
  --ink-3: #7b8682;
  --paper: #f6f4ef;
  --card: #ffffff;
  --line: #e4e0d7;
  --line-soft: #efece5;
  --side: #0f3d36;
  --side-2: #0b2f2a;
  --accent: #1f7a68;
  --accent-hover: #186453;
  --accent-soft: #e5f1ee;
  --bad: #b42318;
  --bad-soft: #fdf0ee;
  --good: #1f7a4d;
  --r: 8px;
  --shadow: 0 1px 2px rgba(23, 34, 31, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 28px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 14px; line-height: 20px; font-weight: 600; margin: 0 0 6px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; line-height: 17px; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.bad { color: var(--bad); }
.good { color: var(--good); font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* shell */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: linear-gradient(170deg, var(--side), var(--side-2)); color: #f4efe6; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 18px 18px; color: inherit; }
.brand:hover { text-decoration: none; }
.mark { width: 34px; height: 34px; border-radius: 8px; background: #f4efe6; color: var(--side); display: grid; place-items: center; font: 700 18px/1 Georgia, serif; flex: none; }
.brand b { display: block; font-size: 14px; line-height: 18px; }
.brand small { display: block; font-size: 11px; color: rgba(244, 239, 230, .6); }
.nav { display: flex; flex-direction: column; }
.nav a, .nav-soon, .side-bottom a, .side-bottom button { display: flex; align-items: center; justify-content: space-between; height: 36px; padding: 0 18px; color: #f4efe6; font: 500 14px/20px inherit; font-family: inherit; background: none; border: 0; width: 100%; text-align: left; cursor: pointer; }
.nav a:hover, .side-bottom a:hover, .side-bottom button:hover { background: rgba(255, 255, 255, .06); text-decoration: none; }
.nav a.active, .side-bottom a.active { background: rgba(255, 255, 255, .1); box-shadow: inset 3px 0 0 #8fd3c1; }
.nav-soon { color: rgba(244, 239, 230, .45); cursor: default; }
.nav-soon em { font-style: normal; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; border: 1px solid rgba(244, 239, 230, .25); border-radius: 4px; padding: 0 5px; line-height: 16px; }
.side-bottom { margin-top: auto; }
.side-bottom a, .side-bottom button { font-size: 13px; color: rgba(244, 239, 230, .85); }
.who { padding: 10px 18px 0; margin-top: 8px; border-top: 1px solid rgba(255, 255, 255, .1); font-size: 11px; color: rgba(244, 239, 230, .55); word-break: break-all; }
.content { padding: 28px 32px 48px; min-width: 0; max-width: 1360px; }

/* page */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.head-actions form { margin: 0; }
.back { display: inline-block; font-size: 13px; margin-bottom: 6px; }
.cur { color: var(--ink-3); font-weight: 500; font-size: .85em; }
.flash { background: var(--accent-soft); color: var(--accent-hover); border: 1px solid #c4e2da; padding: 10px 14px; border-radius: var(--r); margin-bottom: 16px; font-weight: 500; }
.alert { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: var(--r); margin: 12px 0; font-size: 13px; }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: var(--r); border: 1px solid var(--accent); background: var(--accent); color: #fff; font: 600 13px/1 inherit; font-family: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--line-soft); }
input, select, textarea { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 10px; width: 100%; }
input, select { height: 36px; }
textarea { resize: vertical; }
label > span { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
.form label { display: block; margin: 12px 0; }
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.filters label { width: 150px; }
.filters label.grow { flex: 1; min-width: 180px; }
.filters .clear { font-size: 13px; padding-bottom: 9px; }

/* layout & cards */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.layout.detail { grid-template-columns: minmax(0, 1fr) 340px; }
.side { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); }
.table-card { padding: 0; overflow-x: auto; }
.total { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--line-soft); }
.total span { color: var(--ink-2); font-weight: 500; }
.total b { font-size: 18px; font-weight: 650; }
.kv { list-style: none; margin: 0; padding: 0; }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line-soft); }
.kv li:first-child { border-top: 0; }
.kv li > span:last-child { text-align: right; }
.note-bar { padding: 10px 16px; background: #fbf7ea; border-bottom: 1px solid var(--line); font-size: 13px; }

/* table */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fbfaf7; }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr:hover td { background: #faf9f5; }
.table.compact td, .table.compact th { padding: 7px 10px; font-size: 13px; }
.card .table.compact { margin-top: 6px; }
.clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; white-space: nowrap; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-hover); font-size: 12px; font-weight: 500; }
.row-link { font-size: 13px; white-space: nowrap; }
.empty { padding: 48px 24px; text-align: center; }
.empty p { max-width: 440px; margin: 6px auto 0; }

/* receipt */
.receipt { padding: 0; overflow: hidden; min-height: 420px; display: flex; align-items: center; justify-content: center; background: #efede7; }
.receipt img { display: block; max-width: 100%; max-height: 80vh; margin: auto; }
.receipt iframe { width: 100%; height: 80vh; border: 0; background: #fff; }
.receipt-load { padding: 40px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 30% 20%, #e8efe9, var(--paper) 60%); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 32px 28px; text-align: center; box-shadow: 0 12px 32px rgba(15, 61, 54, .08); }
.login-card .mark { margin: 0 auto 14px; background: var(--side); color: #f4efe6; width: 44px; height: 44px; font-size: 22px; }
.login-card p { margin: 6px 0 20px; }
.login-card .btn { width: 100%; height: 42px; margin-top: 8px; }
.btn-google { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-google:hover { background: var(--line-soft); }

/* narrow desktop: summary cards move under the table */
@media (max-width: 1180px) {
  .layout, .layout.detail { grid-template-columns: 1fr; }
  .layout:not(.detail) .side { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; }
}

/* phone */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 8px; }
  .brand { padding: 0 8px; }
  .brand small { display: none; }
  .nav { flex-direction: row; }
  .nav a, .nav-soon, .side-bottom a, .side-bottom button { height: 32px; padding: 0 10px; width: auto; }
  .nav-soon { display: none; }
  .side-bottom { margin: 0 0 0 auto; display: flex; }
  .who { display: none; }
  .content { padding: 18px 16px 40px; }
  .layout, .layout.detail, .grid-2 { grid-template-columns: 1fr; }
  .filters label { width: calc(50% - 5px); }
  .table:not(.lines) th:nth-child(3), .table:not(.lines) td:nth-child(3), .table:not(.lines) th:nth-child(5), .table:not(.lines) td:nth-child(5) { display: none; }
  .table td, .table th { padding: 10px 12px; }
}

/* ---------- invoicing ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat .total b { font-size: 17px; }
.total.bad b, .total.bad span { color: var(--bad); }
.status { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; text-transform: capitalize; vertical-align: middle; letter-spacing: .01em; }
h1 .status { font-size: 12px; position: relative; top: -2px; }
.st-draft { background: #eeeae1; color: #5d5a52; }
.st-issued { background: #e6eefb; color: #2556a8; }
.st-overdue { background: var(--bad-soft); color: var(--bad); }
.st-paid { background: #e3f3ea; color: var(--good); }
.st-cancelled { background: #f1f0ee; color: #8a8a86; text-decoration: line-through; }
.tag-soft { background: #f1eee6; color: var(--ink-2); }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; }
.grid-form label { margin: 8px 0; }
.grid-form .span-2 { grid-column: 1 / -1; }
.grid-form h2 { margin: 4px 0 0; }
.grid-form .section-gap { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.grid-form.narrow { max-width: 720px; }
label small { display: block; margin-top: 4px; font-size: 12px; }
label em { font-style: normal; font-weight: 400; }
.check { display: flex !important; align-items: center; gap: 8px; margin: 10px 0; }
.check input { width: 16px; height: 16px; flex: none; accent-color: var(--accent); }
.check span { margin: 0 !important; font-size: 13px !important; color: var(--ink) !important; font-weight: 400 !important; }
fieldset.currencies { border: 1px solid var(--line); border-radius: var(--r); padding: 6px 12px 2px; margin: 8px 0; display: flex; flex-wrap: wrap; column-gap: 18px; }
fieldset.currencies legend { font-size: 12px; font-weight: 500; color: var(--ink-2); padding: 0 4px; }
.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 10px; }
.btn-wide { width: 100%; height: 42px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--accent); cursor: pointer; text-align: left; }
.link-btn:hover { text-decoration: underline; }
.link-btn.bad { color: var(--bad); }
.inline-form { margin-top: 10px; }
.action-list { display: flex; flex-direction: column; gap: 10px; }
.action-list form { margin: 0; }
.lines-card { padding: 0; overflow-x: auto; }
.table.lines td { padding: 6px 8px; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
.table.lines th { padding: 9px 8px; }
.table.lines tbody tr:hover td { background: none; }
.table.lines textarea { min-height: 36px; resize: none; overflow: hidden; line-height: 1.4; }
.table.lines input { text-align: right; }
.table.lines input[name=line_unit] { text-align: left; }
.table.lines .amt { padding-top: 15px; white-space: nowrap; }
.w-qty { width: 76px; } .w-unit { width: 84px; } .w-price { width: 120px; } .w-amt { width: 120px; }
.icon-btn { width: 30px; height: 36px; border: 0; background: none; color: var(--ink-3); font-size: 20px; cursor: pointer; border-radius: 6px; }
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); }
.lines-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); background: #fbfaf7; }
.grand span:first-child { color: var(--ink-2); margin-right: 10px; font-weight: 500; }
.grand b { font-size: 18px; }
.pdf-view { min-height: 82vh; }
.pdf-view iframe { height: 82vh; }
@media (max-width: 860px) {
  .stats, .grid-form { grid-template-columns: 1fr; }
  .lines-foot { flex-direction: column; gap: 10px; align-items: stretch; }
}
.table th.right { text-align: right; }
.token-new { margin-bottom: 16px; border-color: #c4e2da; background: #f4faf8; }
.code { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; font: 12.5px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all; margin: 6px 0 10px; }
.btn-danger { background: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: #912018; }
