:root {
  --bg: #faf7f5;
  --surface: #ffffff;
  --surface-2: #f4efec;
  --border: #e7dfda;
  --text: #2a2226;
  --muted: #7a6d72;
  --brand: #b23a5b;
  --brand-dark: #8f2b47;
  --brand-soft: #fbe9ee;
  --leaf: #2f7a5b;
  --leaf-soft: #e3f3ec;
  --amber: #b7791f;
  --amber-soft: #fdf2dc;
  --blue: #2f6db3;
  --blue-soft: #e5effa;
  --violet: #6b4fbb;
  --violet-soft: #efeafb;
  --red: #c0392b;
  --red-soft: #fbe5e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(42, 34, 38, .06), 0 4px 16px rgba(42, 34, 38, .04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* the rest exist so a theme only has to redefine variables, never rules */
  --input-bg: #ffffff;
  --row-hover: #fdfbfa;
  --callout-border: #f3cbd7;
  --focus-ring: rgba(178, 58, 91, .25);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: #2a2226; color: #f3e9ec; padding: 1.25rem .9rem; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: .25rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.15rem; color: #fff;
  padding: 0 .5rem 1rem; }
.brand:hover { text-decoration: none; }
.brand svg { flex: none; }
.sidebar .shop { font-size: .8rem; color: #bfaeb5; padding: 0 .5rem .9rem; border-bottom: 1px solid #44383d; margin-bottom: .6rem; }
.nav a { display: flex; align-items: center; gap: .6rem; color: #e6d9de; padding: .55rem .65rem; border-radius: 8px; font-size: .94rem; }
.nav a:hover { background: #3a2f34; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.sidebar .spacer { flex: 1; }
.sidebar .me { font-size: .82rem; color: #bfaeb5; padding: .5rem; border-top: 1px solid #44383d; }
.sidebar .me button { background: none; border: 0; color: #f3c6d3; padding: 0; cursor: pointer; font: inherit; }
.main { padding: 1.75rem 2rem 3rem; min-width: 0; overflow-x: hidden; }
.topbar { display: none; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.stack > * + * { margin-top: 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card > h2:first-child, .card > h3:first-child { margin-bottom: .8rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .8rem; }
.card-head h2, .card-head h3 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 1rem 1.2rem 0; }

.stat { display: flex; flex-direction: column; gap: .2rem; }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat .value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.01em; }
.stat .sub { font-size: .82rem; color: var(--muted); }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: .5rem .9rem; border-radius: 8px; font: inherit; font-size: .92rem;
  font-weight: 500; cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn-success:hover { background: #276b4f; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-link { background: none; border: 0; color: var(--brand); padding: 0; cursor: pointer; font: inherit; }
.btn-link.danger { color: var(--red); }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
.field { margin-bottom: .9rem; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date],
input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--input-bg);
  font: inherit; color: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus-ring); border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.row { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.inline-form { display: inline; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 140px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--input-bg); }
.segmented label { margin: 0; padding: .5rem .9rem; cursor: pointer; font-weight: 500; font-size: .9rem; }
.segmented input { display: none; }
.segmented input:checked + span { color: var(--brand); }
.segmented label:has(input:checked) { background: var(--brand-soft); color: var(--brand); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:hover { background: var(--row-hover); }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; white-space: nowrap; }
tfoot td { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.s-new { background: var(--blue-soft); color: var(--blue); }
.s-designing { background: var(--violet-soft); color: var(--violet); }
.s-ready { background: var(--amber-soft); color: var(--amber); }
.s-out_for_delivery { background: var(--brand-soft); color: var(--brand); }
.s-delivered { background: var(--leaf-soft); color: var(--leaf); }
.s-cancelled { background: #eee; color: #777; text-decoration: line-through; }
.p-paid { background: var(--leaf-soft); color: var(--leaf); }
.p-partial { background: var(--amber-soft); color: var(--amber); }
.p-unpaid { background: var(--red-soft); color: var(--red); }
.tag { background: var(--surface-2); color: var(--muted); }

/* ---------- flash ---------- */
.flashes { margin-bottom: 1rem; display: grid; gap: .5rem; }
.flash { padding: .7rem 1rem; border-radius: 8px; border: 1px solid; font-size: .92rem; }
.flash.success { background: var(--leaf-soft); border-color: #bfe3d3; color: #1f5a42; }
.flash.error { background: var(--red-soft); border-color: #f2c4bd; color: #8f2a1f; }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: .8rem; overflow-x: auto; padding-bottom: .5rem; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: .7rem; min-height: 200px; }
.column h3 { display: flex; justify-content: space-between; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .6rem; }
.ticket { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .65rem .75rem; margin-bottom: .6rem; box-shadow: var(--shadow); font-size: .88rem; }
.ticket .t-head { display: flex; justify-content: space-between; gap: .4rem; font-weight: 600; }
.ticket .t-body { color: var(--muted); margin: .25rem 0 .5rem; }
.ticket .t-foot { display: flex; justify-content: space-between; align-items: center; gap: .4rem; }

/* ---------- items editor ---------- */
.items-table td { padding: .4rem; border: 0; }
.items-table th { background: none; padding: .4rem; }
.items-table input { padding: .45rem .55rem; }
.totals { margin-left: auto; max-width: 320px; }
.totals div { display: flex; justify-content: space-between; padding: .25rem 0; }
.totals .grand { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--border); margin-top: .3rem; padding-top: .5rem; }

.autocomplete { position: relative; }
.ac-list { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); margin-top: 2px; max-height: 260px; overflow-y: auto; }
.ac-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: .55rem .75rem; cursor: pointer; font: inherit; }
.ac-list button:hover, .ac-list button.hl { background: var(--brand-soft); }
.chosen { display: flex; justify-content: space-between; align-items: center; background: var(--brand-soft); border-radius: 8px; padding: .55rem .75rem; }

/* ---------- misc ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: .35rem .75rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.timeline li { padding: .35rem 0 .35rem .9rem; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); position: absolute; left: -5px; top: .7rem; }
.message-box { background: var(--surface-2); border-radius: 8px; padding: .8rem 1rem; font-style: italic; white-space: pre-wrap; }
.pagination { display: flex; gap: .4rem; justify-content: center; padding: 1rem; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding-top: .5rem; }
.bars .bar { flex: 1; display: flex; gap: 1px; align-items: flex-end; height: 100%; position: relative; }
.bars .bar span { flex: 1; border-radius: 3px 3px 0 0; min-height: 1px; }
.bars .bar .b-sales { background: var(--brand); }
.bars .bar .b-paid { background: var(--leaf); opacity: .75; }
.bars .bar:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; font-size: .75rem; padding: .3rem .5rem; border-radius: 6px; white-space: pre; z-index: 5; }
.bars-axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: .3rem; }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: .3rem; }
.meter span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.callout { background: var(--brand-soft); border: 1px solid var(--callout-border); border-radius: var(--radius); padding: 1rem 1.2rem; }
.due { color: var(--brand); font-weight: 600; }

/* ---------- auth & landing ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem;
  background: radial-gradient(circle at 20% 10%, var(--brand-soft) 0, transparent 45%), radial-gradient(circle at 80% 90%, var(--leaf-soft) 0, transparent 40%), var(--bg); }
.auth .card { width: 100%; max-width: 440px; padding: 2rem; }
.auth .brand { color: var(--text); justify-content: center; padding-bottom: 1.25rem; }
.landing { max-width: 1040px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.landing header { display: flex; justify-content: space-between; align-items: center; }
.landing header .brand { color: var(--text); padding: 0; }
.lang-pick { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); }
.lang-pick select { width: auto; padding: .35rem 1.6rem .35rem .4rem; font-size: .85rem; }
.hero { text-align: center; padding: 4.5rem 0 3rem; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.1rem); letter-spacing: -.02em; max-width: 760px; margin: 0 auto 1rem; }
.hero p { font-size: 1.15rem; color: var(--muted); max-width: 620px; margin: 0 auto 1.75rem; }
.features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.features .card h3 { color: var(--brand); }

/* ---------- print ---------- */
.print-page { max-width: 760px; margin: 0 auto; padding: 1.5rem; background: #fff; }
.print-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-bottom: 1rem; }
@media print {
  .no-print, .sidebar, .topbar, .print-actions { display: none !important; }
  body { background: #fff; }
  .app { display: block; }
  .main { padding: 0; }
  .card { box-shadow: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; background: #2a2226; color: #fff; position: sticky; top: 0; z-index: 40; }
  .topbar .brand { padding: 0; font-size: 1.05rem; }
  .topbar button { background: none; border: 0; color: #fff; cursor: pointer; padding: .25rem; }
  .main { padding: 1.1rem 1rem 3rem; }
  .grid-2, .grid-3, .features { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kv { grid-template-columns: 110px 1fr; }
  .hide-sm { display: none; }
  /* The landing header is a brand on one side and two buttons on the other. On a
     phone the buttons wrap and climb over the brand, so let the row wrap instead. */
  .landing header { flex-wrap: wrap; justify-content: center; gap: .6rem; }
  .landing header .brand { padding-bottom: 0; }
  .hero { padding: 2.5rem 0 2rem; }
}

.prod-grid { display: grid; grid-template-columns: minmax(160px, 2fr) minmax(100px, 1fr) 110px 60px 80px 130px; gap: .5rem; align-items: center; padding: .5rem .8rem; }

/* ---------- theme picker ---------- */
.themes { display: flex; flex-wrap: wrap; gap: .5rem; }
.themes input { position: absolute; opacity: 0; width: 0; height: 0; }
.themes label { display: flex; align-items: center; gap: .5rem; margin: 0; font-size: .88rem;
  font-weight: 500; border: 1px solid var(--border); border-radius: 999px;
  padding: .3rem .75rem .3rem .35rem; cursor: pointer; background: var(--surface); }
.themes label:hover { background: var(--surface-2); }
.themes input:checked + label { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.themes input:focus-visible + label { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.themes .chip { width: 22px; height: 22px; border-radius: 50%; flex: none; border: 1px solid rgba(0, 0, 0, .15); }

/* ---------- themes ----------
   A shop picks one on its Settings page; base.html puts it on <html data-theme>.
   Each one only redefines variables — no rule below depends on which is active. */

[data-theme="plum"] {
  --bg: #faf6f9; --surface-2: #f2ecf1; --border: #e4dae2;
  --brand: #7c3a73; --brand-dark: #5f2b58; --brand-soft: #f5e9f3;
  --callout-border: #e6cfe2; --focus-ring: rgba(124, 58, 115, .25); --row-hover: #fdfafc;
}

[data-theme="sage"] {
  --bg: #f6faf7; --surface-2: #ecf3ee; --border: #d9e5dd;
  --brand: #3d7a5c; --brand-dark: #2c5c45; --brand-soft: #e6f2eb;
  --callout-border: #c9e0d3; --focus-ring: rgba(61, 122, 92, .25); --row-hover: #fafdfb;
}

[data-theme="amber"] {
  --bg: #fdf9f3; --surface-2: #f6efe3; --border: #e8dcc8;
  --brand: #a9681c; --brand-dark: #855114; --brand-soft: #fcefdd;
  --callout-border: #ecd9b6; --focus-ring: rgba(169, 104, 28, .25); --row-hover: #fefcf8;
}

[data-theme="indigo"] {
  --bg: #f6f7fc; --surface-2: #eceef7; --border: #dadded;
  --brand: #43549b; --brand-dark: #333f79; --brand-soft: #e9ecf9;
  --callout-border: #ccd3ef; --focus-ring: rgba(67, 84, 155, .25); --row-hover: #fafbfe;
}

[data-theme="night"] {
  --bg: #1b1619; --surface: #241e21; --surface-2: #2e2529; --border: #3c3137;
  --text: #f1e8eb; --muted: #a9979e;
  --brand: #d56b8c; --brand-dark: #e6809f; --brand-soft: #3a2630;
  --input-bg: #2e2529; --row-hover: #2b2328; --callout-border: #5a3a47;
  --focus-ring: rgba(213, 107, 140, .35);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 16px rgba(0, 0, 0, .25);
}

/* Dark mode needs these few extras: they are the spots where a light sheet of
   paper is assumed rather than a surface colour. */
[data-theme="night"] .print-page { background: var(--surface); }
[data-theme="night"] .s-cancelled { background: #3a3238; color: #b4a6ac; }
[data-theme="night"] select option { background: var(--input-bg); color: var(--text); }
@media print {
  [data-theme="night"] { --bg: #fff; --surface: #fff; --surface-2: #fff; --text: #000;
    --muted: #444; --border: #ccc; --input-bg: #fff; }
}

/* The web shop's window: a card per product, photograph first. */
.shop-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.shop-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
             display: flex; flex-direction: column; }
.shop-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.shop-card-blank { aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center;
                   background: var(--row-hover); color: var(--muted); font-size: .9rem; }
.shop-card-body { padding: .75rem; display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.shop-card-body h3 { margin: 0; font-size: 1rem; }
.shop-card-body p { margin: 0; font-size: .9rem; }
.shop-price { font-weight: 700; font-size: 1.1rem; }
.shop-card form { margin-top: auto; }
