/* Mamma's Tuck Shop — internal invoicing tool */
:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --subtle: #f2f0eb;
  --ink: #1a1a1a;
  --muted: #74716b;
  --faint: #a9a59d;
  --line: #e6e3dc;
  --accent: #2f8f6f;
  --accent-dark: #24725a;
  --mint: #9fdcc4;
  --mint-soft: #e4f5ed;
  --owe: #a3412a;
  --owe-soft: #f8e9e4;
  --warn-soft: #f6efe0;
  --radius: 10px;
  --serif: "Instrument Serif", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;
  --gutter: clamp(16px, 3vw, 40px);
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 500; line-height: 1.15; }
h1 { font-family: var(--serif); font-weight: 400; letter-spacing: -.01em; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
code { background: var(--subtle); padding: .1rem .35rem; border-radius: 4px; font-size: .85em; }
.owe { color: var(--owe); }
.good { color: var(--accent-dark); }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem .95rem; border-radius: 8px; font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s; white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-soft { background: var(--mint-soft); border-color: var(--mint); color: var(--accent-dark); }
.btn-danger { color: var(--owe); }
.btn-sm { padding: .3rem .65rem; font-size: .82rem; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--ink); }
.icon-btn { display: inline-grid; place-items: center; background: none; border: 0; font-size: 1rem; line-height: 1; cursor: pointer; width: 30px; height: 30px; border-radius: 6px; color: var(--faint); text-decoration: none; }
.icon-btn:hover, .icon-btn.active { background: var(--subtle); color: var(--ink); }

input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--mint-soft); }
label { display: grid; gap: .3rem; font-weight: 500; font-size: .8rem; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form-grid .full { grid-column: 1 / -1; }
.check-label { display: flex; align-items: center; gap: .5rem; color: var(--ink); font-size: .9rem; }
.check-label input { width: auto; }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .85rem; color: var(--muted); user-select: none; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; padding: 0; border: 0; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }
.switch input:focus { box-shadow: 0 0 0 3px var(--mint-soft); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 1rem; }
.login-card h1 { font-size: 2.6rem; }
.login-card p { margin: 0; }
.form-msg { min-height: 1.2em; color: var(--owe); margin: 0; }
.form-msg.ok { color: var(--accent-dark); }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 600; font-size: .95rem; letter-spacing: -.01em; white-space: nowrap; }
.brand::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 3px var(--mint-soft); }

/* ---------- app bar + tabs ---------- */
.appbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 2rem; padding: 0 var(--gutter); height: 60px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: .25rem; height: 100%; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs a { display: flex; align-items: center; padding: 0 .9rem; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }
.appbar-end { display: flex; align-items: center; gap: 1rem; }
.page { padding: 1.75rem var(--gutter) 4rem; display: grid; gap: 1.5rem; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head h1 { font-size: 2.4rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- generic blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2 { font-size: 1rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.stat { padding: 1.1rem 1.25rem; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat span { display: block; font-size: .78rem; color: var(--muted); }
.stat strong { display: block; font-family: var(--serif); font-weight: 400; font-size: 2rem; margin-top: .1rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stat.mint { background: var(--mint-soft); }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.toolbar input[type="search"] { max-width: 260px; }
.toolbar select { width: auto; }
.toolbar .spacer { flex: 1; }
.card-head .toolbar { justify-content: flex-end; }
.card-head .toolbar input[type="search"] { width: 200px; }
.seg { display: inline-flex; gap: 2px; background: var(--subtle); padding: 3px; border-radius: 8px; }
.seg button { border: 0; background: none; font: inherit; padding: .3rem .7rem; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .62rem .85rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--surface); font-size: .75rem; color: var(--muted); font-weight: 500; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg); }
tfoot td { font-weight: 500; border-top: 1px solid var(--line); border-bottom: 0; background: var(--bg); }
td.cat-row { background: var(--bg); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-dark); font-weight: 600; padding: .45rem .85rem; }

/* editable sheet */
.sheet td.cell { padding: 0; }
.sheet input { border: 0; border-radius: 0; background: transparent; padding: .6rem .85rem; }
.sheet input:focus { background: var(--mint-soft); box-shadow: none; }
.sheet input.num { text-align: right; }
.sheet .w-name { min-width: 220px; }
.sheet .w-cat { min-width: 130px; }
.sheet .w-num { min-width: 90px; }
.saved-flash { animation: flash 1s ease; }
@keyframes flash { 0% { background: var(--mint-soft); } 100% { background: transparent; } }
.low { color: var(--owe); font-weight: 600; }

/* pills */
.pill { display: inline-block; padding: .08rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 500; background: var(--subtle); color: var(--muted); white-space: nowrap; }
.pill.paid { background: var(--mint-soft); color: var(--accent-dark); }
.pill.unpaid { background: var(--warn-soft); color: #7a5a17; }
.pill.partly { background: #fbeedd; color: #8a5312; }
.pill.overdue { background: var(--owe-soft); color: var(--owe); }
.pill.open { background: #e9eef6; color: #2c4a73; }
.pill.void { text-decoration: line-through; }

/* ---------- clients tab ---------- */
.split { display: grid; grid-template-columns: 300px 1fr; gap: 1.5rem; align-items: start; }
.client-list { position: sticky; top: 84px; display: grid; gap: .75rem; }
.client-list .list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(100vh - 210px); overflow-y: auto; }
.client-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .65rem .9rem; border-bottom: 1px solid var(--line); text-decoration: none; }
.client-row:last-child { border-bottom: 0; }
.client-row:hover { background: var(--bg); }
.client-row.active { background: var(--mint-soft); }
.client-row .who { min-width: 0; }
.client-row .who b { display: block; font-weight: 500; }
.client-row .who span { display: block; font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-row .amt { font-size: .82rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.client-row .amt.has { color: var(--ink); font-weight: 500; }

.client-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.client-head h1 { font-size: 2.4rem; }
.client-head p { margin: .2rem 0 0; }
.week-nav { display: inline-flex; align-items: center; gap: .25rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.week-nav span { min-width: 170px; text-align: center; font-weight: 500; }
.week-nav button { border: 0; background: none; width: 30px; height: 30px; border-radius: 6px; cursor: pointer; font-size: 1rem; color: var(--muted); }
.week-nav button:hover { background: var(--subtle); color: var(--ink); }
.week-bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }

.days { display: grid; grid-template-columns: repeat(var(--day-count, 5), minmax(0, 1fr)); gap: .75rem; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 220px; }
.day.today { border-color: var(--mint); box-shadow: 0 0 0 3px var(--mint-soft); }
.day-head { padding: .7rem .85rem .5rem; display: flex; justify-content: space-between; align-items: baseline; }
.day-head b { font-weight: 600; }
.day-head span { font-size: .78rem; color: var(--muted); }
.day-items { flex: 1; padding: 0 .4rem; display: grid; align-content: start; gap: 2px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: .2rem .5rem; padding: .45rem .45rem; border-radius: 6px; }
.item:hover { background: var(--bg); }
.item .name { font-size: .85rem; line-height: 1.3; }
.item .price { font-size: .82rem; font-variant-numeric: tabular-nums; text-align: right; }
.item .ctrl { grid-column: 1 / -1; display: flex; align-items: center; gap: .25rem; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface); }
.qty button { border: 0; background: none; width: 24px; height: 22px; cursor: pointer; color: var(--muted); font-size: .9rem; }
.qty button:hover { background: var(--subtle); color: var(--ink); }
.qty span { min-width: 22px; text-align: center; font-size: .8rem; font-variant-numeric: tabular-nums; }
.item .remove { margin-left: auto; border: 0; background: none; color: var(--faint); cursor: pointer; font-size: .8rem; }
.item .remove:hover { color: var(--owe); }
.day-foot { display: flex; justify-content: space-between; align-items: center; padding: .55rem .85rem; border-top: 1px solid var(--line); }
.day-foot b { font-variant-numeric: tabular-nums; font-weight: 600; }
.add-btn { border: 1px dashed var(--line); background: none; border-radius: 6px; padding: .25rem .6rem; font: inherit; font-size: .8rem; color: var(--accent-dark); cursor: pointer; }
.add-btn:hover { border-color: var(--accent); background: var(--mint-soft); }

.week-summary { display: grid; grid-template-columns: 1fr auto; gap: 1.5rem; align-items: end; }
.week-total { display: grid; gap: .2rem; }
.week-total span { color: var(--muted); font-size: .85rem; }
.week-total strong { font-family: var(--serif); font-weight: 400; font-size: 2.6rem; line-height: 1; font-variant-numeric: tabular-nums; }
.week-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; justify-content: flex-end; }
.week-actions label { min-width: 150px; }
.discount-input { display: flex; }
.discount-input input { border-radius: 8px 0 0 8px; min-width: 0; }
.discount-input select { width: auto; border-radius: 0 8px 8px 0; border-left: 0; padding-right: .4rem; }
.week-actions .discount-input input { width: 90px; }

/* ---------- product picker ---------- */
.picker { display: grid; gap: .9rem; }
.picker-days { display: flex; gap: .35rem; flex-wrap: wrap; }
.picker-days label { display: inline-flex; flex-direction: row; align-items: center; gap: 0; font-size: .82rem; position: relative; }
.picker-days input { position: absolute; opacity: 0; pointer-events: none; width: 1px; }
.picker-days span { border: 1px solid var(--line); padding: .3rem .7rem; border-radius: 999px; cursor: pointer; color: var(--muted); background: var(--surface); }
.picker-days input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.picker-days input:focus-visible + span { box-shadow: 0 0 0 3px var(--mint-soft); }
.picker-list { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.picker-cat { position: sticky; top: 0; background: var(--bg); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-dark); font-weight: 600; padding: .4rem .8rem; border-bottom: 1px solid var(--line); }
.pick { display: flex; align-items: center; gap: .75rem; padding: .45rem .8rem; border-bottom: 1px solid var(--line); }
.pick:last-child { border-bottom: 0; }
.pick .name { flex: 1; }
.pick .price { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; }
.pick.on { background: var(--mint-soft); }
.pick .qty span { min-width: 26px; }
.picker-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.picker-foot b { font-variant-numeric: tabular-nums; }

/* ---------- invoice paper ---------- */
.invoice-wrap { display: grid; grid-template-columns: minmax(0, 820px) 260px; gap: 1.5rem; justify-content: center; align-items: start; }
.invoice-side { position: sticky; top: 84px; display: grid; gap: .6rem; }
.invoice-side .btn { width: 100%; }
.invoice-side .card { display: grid; gap: .6rem; }
.paper { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: clamp(28px, 5vw, 56px); box-shadow: 0 30px 60px -40px rgba(30, 60, 50, .35); color: var(--ink); }
.paper-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; }
.paper-top .from img { max-height: 56px; max-width: 180px; display: block; margin-bottom: .75rem; }
.paper-top .from .biz { font-weight: 600; font-size: 1rem; }
.paper-top .from .sub { color: var(--muted); font-size: .85rem; }
.paper-title { text-align: right; }
.paper-title h1 { font-size: 3.4rem; line-height: .9; }
.paper-title .no { color: var(--muted); margin-top: .35rem; font-variant-numeric: tabular-nums; }
.paper-meta { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 1.25rem; margin: 2.25rem 0 2rem; padding: 1.1rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.paper-meta span { display: block; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: .2rem; }
.paper-meta b { font-weight: 500; }
.paper table { border: 0; }
.paper th { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--ink); padding: .5rem .6rem; background: none; }
.paper td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
.paper tr.day-row td { padding-top: 1.1rem; border-bottom: 0; font-weight: 600; font-size: .85rem; }
.paper tr.day-row td .muted { font-weight: 400; }
.paper tbody tr:last-child td { border-bottom: 1px solid var(--line); }
.paper-totals { display: grid; grid-template-columns: 1fr 300px; gap: 2rem; margin-top: 1.5rem; align-items: start; }
.paper-totals .lines { display: grid; gap: .35rem; }
.paper-totals .lines div { display: flex; justify-content: space-between; color: var(--muted); font-variant-numeric: tabular-nums; }
.amount-due { margin-top: .6rem; background: var(--mint-soft); border-radius: 10px; padding: 1rem 1.1rem; display: flex; justify-content: space-between; align-items: baseline; }
.amount-due span { font-weight: 500; color: var(--accent-dark); }
.amount-due strong { font-family: var(--serif); font-weight: 400; font-size: 2.2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.amount-due.settled { background: var(--subtle); }
.amount-due.settled span { color: var(--muted); }
.paper-bank { font-size: .85rem; line-height: 1.7; }
.paper-bank b { display: block; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 500; margin-bottom: .2rem; }
.paper-foot { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; color: var(--muted); font-size: .85rem; }
.paper-foot .thanks { font-family: var(--serif); font-size: 1.35rem; color: var(--ink); }
.stamp { display: inline-block; margin-top: .5rem; padding: .2rem .7rem; border-radius: 999px; font-size: .75rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.stamp.paid { background: var(--mint-soft); color: var(--accent-dark); }
.stamp.overdue { background: var(--owe-soft); color: var(--owe); }

/* ---------- payments tab ---------- */
.paylater { display: grid; gap: .5rem; }
.paylater-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto auto; gap: 1rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; text-decoration: none; }
.paylater-row:hover { border-color: var(--faint); }
.paylater-row.overdue { border-color: #ecc5b9; background: #fffaf8; }
.paylater-row .lbl { display: block; font-size: .72rem; color: var(--muted); }
.paylater-row .when { font-weight: 500; }

/* ---------- modal & toast ---------- */
.modal { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100% - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .25); }
.modal.wide { width: min(680px, calc(100% - 32px)); }
.modal::backdrop { background: rgba(26, 26, 26, .25); }
.modal-inner { padding: 1.5rem; display: grid; gap: 1rem; }
.modal-inner h2 { font-family: var(--serif); font-weight: 400; font-size: 1.8rem; }
.modal-inner > p { margin: -.5rem 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 8px; transition: transform .2s, opacity .2s, visibility .2s; z-index: 50; max-width: calc(100% - 32px); opacity: 0; visibility: hidden; }
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.toast.err { background: var(--owe); }

/* ---------- responsive ---------- */
@media (max-width: 1150px) {
  .days { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .invoice-wrap { grid-template-columns: 1fr; }
  .invoice-side { position: static; display: flex; flex-wrap: wrap; align-items: flex-start; }
  .invoice-side > * { flex: 1 1 180px; }
  .invoice-side > .card { flex-basis: 100%; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
  .week-summary { grid-template-columns: 1fr; }
  .week-actions { justify-content: flex-start; }
}
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .client-list { position: static; }
  .client-list .list { max-height: 260px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .paylater-row { grid-template-columns: 1fr 1fr; }
  .week-summary { grid-template-columns: 1fr; }
  .week-actions { justify-content: flex-start; }
}
@media (max-width: 640px) {
  .appbar { gap: .75rem; height: auto; flex-wrap: wrap; padding-top: .6rem; }
  .tabs { order: 3; flex-basis: 100%; height: 44px; }
  .appbar-end { margin-left: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .paper-top { flex-direction: column-reverse; }
  .paper-title { text-align: left; }
  .paper-meta { grid-template-columns: 1fr 1fr; }
  .paper-totals { grid-template-columns: 1fr; }
}

/* ---------- print: only the invoice paper ---------- */
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  .appbar, .invoice-side, .no-print, .toast, .modal { display: none !important; }
  .page { padding: 0; max-width: none; }
  .invoice-wrap { display: block; }
  .paper { border: 0; box-shadow: none; padding: 0; border-radius: 0; }
  .amount-due, .stamp, .pill { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
