:root {
  --ink: #0b1d4a;
  --ink-2: #16307a;
  --text: #17212b;
  --muted: #4f5d6b;
  --line: #e2e7ec;
  --bg: #f5f7f9;
  --card: #ffffff;
  --accent: #c8102e;
  --accent-2: #ff4d5e;
  --accent-soft: #fdecee;
  --navy: #0b1d4a;
  --navy-soft: #e8edf8;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #18794e;
  --ok-soft: #e7f6ee;
  --warn: #9a6700;
  --warn-soft: #fff6dd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11,29,74,.06), 0 4px 16px rgba(11,29,74,.06);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Figtree, system-ui, -apple-system, Segoe UI, sans-serif;
  font-size: 17px; line-height: 1.45; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: .9em; }
.hidden { display: none !important; }

/* Layout */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side {
  background: var(--ink); color: #c9d6e2; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 18px; padding: 4px 10px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--ink-2); display: grid; place-items: center; border: 1px solid #234a6e; }
.side a {
  color: #c9d6e2; padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; font-weight: 500;
}
.side a:hover { background: var(--ink-2); text-decoration: none; color: #fff; }
.side a.active { background: var(--ink-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent-2); }
.side .new-btns { display: grid; gap: 8px; padding: 6px 4px 16px; }
.side .new-btns a { justify-content: center; background: var(--accent); color: #fff; font-weight: 600; }
.side .new-btns a.alt { background: transparent; border: 1px solid #2c5478; }
.side .spacer { flex: 1; }
.side .who { font-size: 13px; padding: 10px 12px; border-top: 1px solid #1d3a57; }
.side .who button { background: none; border: 0; color: var(--accent-2); padding: 0; cursor: pointer; font: inherit; }
.main { padding: 28px 32px 60px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 200px; }

/* Forms */
label.f { display: grid; gap: 6px; font-size: 15px; font-weight: 600; color: #2b3946; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: #fff;
  border: 1.5px solid #b9c4ce; border-radius: 8px; padding: 10px 12px; min-height: 46px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
button, .btn {
  font: inherit; font-size: 16px; font-weight: 600; border-radius: 8px; padding: 10px 16px; min-height: 46px; cursor: pointer;
  border: 1.5px solid #b9c4ce; background: #fff; color: var(--text); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { background: #f0f3f6; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { background: #a00c24; border-color: #a00c24; }
button.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
button.danger { color: var(--danger); }
button.link, .btn.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; min-height: 0; }
button:disabled { opacity: .55; cursor: not-allowed; }
.iconbtn { border: 0; background: none; padding: 6px; color: var(--muted); }
.iconbtn:hover { color: var(--danger); background: var(--danger-soft); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7fafc; }
tr.cat td { background: #f1f4f7; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 7px 14px; }
tr.inactive td { color: #98a4b0; }

.pill { display: inline-block; font-size: 14px; font-weight: 600; padding: 3px 11px; border-radius: 99px; background: #eef1f4; color: #3e4c5a; white-space: nowrap; }
.pill.paid, .pill.accepted, .pill.closed { background: var(--ok-soft); color: var(--ok); }
.pill.open, .pill.pending { background: var(--accent-soft); color: var(--accent); }
.pill.partial { background: var(--warn-soft); color: var(--warn); }
.pill.overdue, .pill.error, .pill.rejected { background: var(--danger-soft); color: var(--danger); }
.pill.sent { background: #eef0ff; color: #3c3fb0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--accent); text-decoration: none; }

/* Document builder */
.lines { width: 100%; }
.line {
  display: grid; grid-template-columns: minmax(220px, 2.2fr) 1.7fr 120px 120px 84px; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: start;
}
.line-head { padding: 10px 16px; background: #fafbfc; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.line .sizes { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.line .sizes.two { grid-template-columns: 1fr 1fr; }
.line .sizes label { font-size: 13px; color: var(--muted); font-weight: 600; display: grid; gap: 3px; }
.line .detail { font-size: 14px; color: var(--muted); margin-top: 5px; }
.line .detail.warn { color: var(--warn); font-weight: 600; }
.line .amount { padding-top: 8px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.line .margin { font-size: 12px; color: var(--muted); text-align: right; font-weight: 500; }
.line textarea { margin-top: 6px; font-size: 13px; }
.add-line { padding: 12px 16px; display: flex; gap: 8px; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 24px; justify-content: end; margin-left: auto; max-width: 380px; padding: 16px 20px; }
.totals .num { font-weight: 600; }
.totals .big { font-size: 20px; font-weight: 700; }
.foot-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* Combobox */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0; min-width: 320px; max-height: 340px; overflow: auto;
  background: #fff; border: 1px solid #cdd5dd; border-radius: 10px; box-shadow: 0 12px 32px rgba(11,31,51,.16);
}
.combo-list .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 8px 12px 4px; background: #fafbfc; position: sticky; top: 0; }
.combo-list .opt { padding: 7px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.combo-list .opt .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.combo-list .opt.hl, .combo-list .opt:hover { background: var(--accent-soft); }
.combo-list .empty { padding: 12px; color: var(--muted); font-size: 14px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(11,31,51,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(640px, 100%); max-height: 92vh; overflow: auto; padding: 24px; box-shadow: 0 24px 64px rgba(0,0,0,.25); }
.modal h2 { margin-bottom: 16px; }
.modal .foot-actions { margin-top: 20px; }
.form-grid { display: grid; gap: 14px; }

.tier-table td, .tier-table th { padding: 6px 8px; }
.tier-table input { padding: 6px 8px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 20px; }
.login { width: min(380px, 100%); background: #fff; border-radius: 16px; padding: 32px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.login .brand { color: var(--ink); padding: 0 0 20px; }
.login .brand-mark { background: var(--ink); }
.login form { display: grid; gap: 14px; }
.err { color: var(--danger); font-size: 14px; min-height: 18px; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.banner { padding: 12px 16px; border-radius: 10px; background: var(--warn-soft); color: #6b4a00; margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-weight: 500; transition: .2s; z-index: 80; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--danger); }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
button:not(.primary):not(.dark) .spinner { border-color: #cdd5dd; border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.mobile-nav { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .mobile-nav { display: flex; gap: 6px; overflow-x: auto; background: var(--ink); padding: 10px 16px; position: sticky; top: 0; z-index: 20; }
  .mobile-nav a { color: #c9d6e2; padding: 6px 10px; border-radius: 6px; white-space: nowrap; font-weight: 600; font-size: 14px; }
  .mobile-nav a.active { background: var(--ink-2); color: #fff; }
  .main { padding: 18px 16px 60px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .line { grid-template-columns: 1fr 1fr; }
  .line > :first-child, .line > :nth-child(2) { grid-column: 1 / -1; }
  .line-head { display: none; }
  .hide-sm { display: none; }
  td, th { padding: 9px 10px; }
}

/* ---- Easy-to-use additions ---- */
button.big, .btn.big { font-size: 18px; padding: 14px 22px; min-height: 56px; border-radius: 10px; }
.step { display: flex; align-items: center; gap: 12px; font-size: 20px; margin: 0 0 16px; }
.step > span:first-child { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 17px; flex: none; }
.finish { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.removebtn { border: 0; background: none; color: var(--muted); font-size: 14px; padding: 8px 6px; min-height: 0; text-decoration: underline; }
.removebtn:hover { color: var(--danger); background: none; }
details.more { margin-top: 14px; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 15px; padding: 6px 0; }
.big-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 28px; }
.big-actions a {
  display: grid; gap: 6px; padding: 24px 22px; border-radius: 14px; background: var(--card); border: 1.5px solid var(--line);
  box-shadow: var(--shadow); color: var(--text); text-decoration: none;
}
.big-actions a:first-child { background: var(--accent); border-color: var(--accent); color: #fff; }
.big-actions a:first-child span { color: #d6f3f9; }
.big-actions a:hover { border-color: var(--accent); text-decoration: none; }
.big-actions b { font-size: 21px; }
.big-actions span { color: var(--muted); font-size: 15px; }
.plain { padding: 16px 20px; border-radius: 12px; background: var(--accent-soft); color: #0b4f62; font-size: 18px; margin-bottom: 18px; }
.plain.ok { background: var(--ok-soft); color: var(--ok); }
.plain.bad { background: var(--danger-soft); color: var(--danger); }
.modal button.big { min-width: 180px; justify-content: center; }
.combo-list .opt { padding: 10px 14px; font-size: 16px; }
.combo-list .opt .meta { font-size: 13px; }

/* Simple view: larger everything, hide internal/advanced bits */
body.simple { font-size: 19px; }
body.simple input, body.simple select, body.simple textarea { font-size: 18px; min-height: 52px; }
body.simple button, body.simple .btn { font-size: 18px; min-height: 52px; }
body.simple label.f { font-size: 17px; }
body.simple .side a { font-size: 18px; padding: 12px 14px; }
body.simple .internal, body.simple .adv { display: none !important; }
body.simple td { padding: 14px; }
body.simple .line .sizes label { font-size: 15px; }
body.simple .pill { font-size: 16px; }

@media (max-width: 900px) {
  .big-actions { grid-template-columns: 1fr; }
  .finish > * { flex: 1 1 100%; justify-content: center; }
}

/* ---- Stone Marketing branding: red, white & navy ---- */
a, button.link, .btn.link, details.more summary { color: var(--navy); }
.side .logo-card, .login .logo-card { background: #fff; border-radius: 10px; padding: 10px 12px; margin: 0 2px 18px; display: block; }
.side .logo-card img, .login .logo-card img { display: block; width: 100%; height: auto; }
.login .logo-card { padding: 0; margin: 0 0 22px; }
.side a.active { box-shadow: inset 4px 0 0 var(--accent); }
.side .new-btns a.alt { border-color: #3a5aa8; }
.side .who button { color: #ffb3bc; }
.side { border-top: 4px solid var(--accent); }
.mobile-nav { border-bottom: 3px solid var(--accent); }
.mobile-logo { display: none; }
input:focus, select:focus, textarea:focus { outline-color: var(--navy); border-color: var(--navy); }
.step > span:first-child { background: var(--navy); }
.plain { background: var(--navy-soft); color: var(--navy); }
.pill.open, .pill.pending { background: var(--navy-soft); color: var(--navy); }
.big-actions a:first-child span { color: #ffe3e7; }
.big-actions a:hover { border-color: var(--navy); }
.combo-list .opt.hl, .combo-list .opt:hover { background: var(--navy-soft); }
tr.clickable:hover td { background: #f4f6fb; }
.tabs a.active { border-color: var(--accent); }
.login-wrap { background: linear-gradient(180deg, var(--navy) 0 70%, var(--accent) 70% 100%); }
@media (max-width: 900px) {
  .mobile-logo { display: block; background: #fff; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .mobile-logo img { height: 44px; width: auto; display: block; }
}
.shell > div { min-width: 0; }
@media (max-width: 900px) { .page-head h1 { font-size: 21px; } }
.filters { display: flex; gap: 14px; align-items: end; flex-wrap: wrap; margin-bottom: 14px; }
.filters label.f:first-child { min-width: 220px; }
.filters .grow { flex: 1; min-width: 200px; }
.stat.link { cursor: pointer; } .stat.link:hover { border-color: var(--navy); box-shadow: var(--shadow); }
.btn.reorder { padding: 6px 12px; min-height: 0; font-size: 14px; }
