:root {
  --primary: #7a2748; --accent: #e9a23b; --on-accent: #2b1a10;
  --bg: #faf6ef; --card: #ffffff; --ink: #2b2327; --muted: #6b5f64; --line: #e7dfd0;
  --new: #c0392b; --quoted: #b9791d; --confirmed: #2d7d56; --ready: #2a6fb0; --done: #7b7377; --cancelled: #9a9094;
  --font-body: 'DM Sans', system-ui, sans-serif; --font-head: 'Playfair Display', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1418; --card: #261d22; --ink: #f2ebee; --muted: #b3a6ac; --line: #43363d; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font-body); }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.2; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: #b3261e; font-weight: 600; margin: 8px 0; }
@media (prefers-color-scheme: dark) { .error { color: #ff9b94; } }
[hidden] { display: none !important; }

.demo-note { background: var(--accent); color: var(--on-accent); text-align: center; padding: 8px 12px; font-size: .9rem; font-weight: 600; }

.btn { border: 1.5px solid transparent; border-radius: 10px; padding: 10px 16px; font-weight: 700; cursor: pointer; background: var(--card); min-height: 44px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { border-color: var(--line); background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.danger { color: #b3261e; border-color: #e3b5b1; background: transparent; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.signin { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(420px, 100%); display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: .85rem; font-weight: 700; }
input, select, textarea { border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--card); min-height: 44px; width: 100%; }
textarea { resize: vertical; }

.top { background: var(--primary); color: #fff; position: sticky; top: 0; z-index: 5; }
.top-in { max-width: 1100px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; line-height: 1.15; color: inherit; text-decoration: none; }
.brand-text { display: grid; }
.brand-icon { border-radius: 50%; background: #fff; }
.brand-name { font-family: var(--font-head); font-weight: 700; font-size: 1.15rem; }
.brand-sub { font-size: .75rem; letter-spacing: .14em; text-transform: uppercase; opacity: .8; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.top .btn.primary { background: var(--accent); color: var(--on-accent); }
.top .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); }

.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; text-align: left; cursor: pointer; }
.stat b { display: block; font-family: var(--font-head); font-size: 1.9rem; line-height: 1.1; color: var(--primary); }
@media (prefers-color-scheme: dark) { .stat b { color: var(--accent); } }
.stat span { font-size: .82rem; color: var(--muted); font-weight: 600; }
.stat.hot b { color: var(--new); }

.bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: .88rem; cursor: pointer; min-height: 36px; }
.chip[aria-selected="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip em { font-style: normal; opacity: .7; margin-left: 4px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tools input { width: 220px; min-height: 36px; padding: 6px 12px; }

.day { margin: 22px 0 8px; display: flex; align-items: baseline; gap: 10px; }
.day h3 { font-size: 1.1rem; }
.day small { color: var(--muted); font-weight: 600; }
.day.late h3 { color: var(--new); }
.order { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 10px; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; cursor: pointer; text-align: left; width: 100%; }
.order:hover { border-color: var(--primary); }
.order .who { font-weight: 700; font-size: 1.02rem; }
.order .what { color: var(--muted); }
.order .right { text-align: right; display: grid; justify-items: end; gap: 4px; }
.order .money { font-weight: 700; }
.order .money small { display: block; font-weight: 500; color: var(--muted); }
.order .meta { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #fff; }
.pill.new { background: var(--new); } .pill.quoted { background: var(--quoted); } .pill.confirmed { background: var(--confirmed); }
.pill.ready { background: var(--ready); } .pill.done { background: var(--done); } .pill.cancelled { background: var(--cancelled); }
.flag { color: var(--new); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 48px 12px; border: 2px dashed var(--line); border-radius: 14px; }

.modal { position: fixed; inset: 0; background: rgba(20,10,15,.55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .modal { align-items: center; } }
.sheet { background: var(--bg); width: min(720px, 100%); max-height: 94vh; overflow: auto; border-radius: 18px 18px 0 0; }
@media (min-width: 700px) { .sheet { border-radius: 18px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.sheet-head h2 { font-size: 1.3rem; }
.x { border: 0; background: none; font-size: 2rem; line-height: 1; cursor: pointer; color: var(--muted); min-width: 44px; min-height: 44px; }
.sheet-body { padding: 16px 20px 28px; display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } }
.sect { font-size: .75rem; text-transform: uppercase; letter-spacing: .14em; font-weight: 800; color: var(--muted); margin-top: 8px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 1rem; }
.check input { width: 22px; height: 22px; min-height: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions a, .actions button { text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; }
.save-row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.readonly { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: .95rem; }
.readonly div { display: flex; gap: 8px; } .readonly b { min-width: 110px; color: var(--muted); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b2327; color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 30; }

@media print {
  .top, .bar, .stats, .demo-note, .modal, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  .order { break-inside: avoid; border-color: #bbb; }
}

@media (max-width: 600px) { .top { position: static; } .tools input { width: 100%; } }

.lines { display: grid; gap: 10px; }
.small-note { font-size: .9rem; margin: 0; }
.line { display: grid; grid-template-columns: 1fr 70px 90px 96px 78px 40px; gap: 6px 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.line input { min-height: 40px; padding: 6px 10px; }
.line .l-note { grid-column: 1 / 6; }
.l-total { text-align: right; font-weight: 700; }
.line-x { border: 0; background: none; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; min-height: 40px; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.add-row select { flex: 1 1 220px; width: auto; }
@media (max-width: 560px) {
  .line { grid-template-columns: 1fr 1fr 1fr 40px; }
  .line .l-name { grid-column: 1 / 5; }
  .line .l-qty { grid-column: 1; } .line .l-unit { grid-column: 2; } .line .l-price { grid-column: 3; }
  .l-total { grid-column: 4; font-size: .85rem; }
  .line .l-note { grid-column: 1 / 4; } .line-x { grid-column: 4; }
}

/* let grid children shrink below their default input width (keeps the phone layout inside the screen) */
.sheet-body > *, .line > *, .row2 > *, .add-row > * { min-width: 0; }
input, select, textarea { min-width: 0; }
.sheet { overflow-x: hidden; }

/* auto sign-in animation (demo) */
#signin-form.auto input { border-color: var(--accent); }
#signin-form.auto input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); outline: none; }
#signin-form { animation: rise .45s ease both; }
.btn.pressed { transform: scale(.96); filter: brightness(1.15); transition: transform .15s, filter .15s; }
#app.enter { animation: rise .5s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #signin-form, #app.enter { animation: none; } }

/* orders vs visits panel */
.metrics { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px 12px; margin-bottom: 20px; }
.m-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.m-head h2 { font-size: 1.15rem; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 6px 14px; font-weight: 700; font-size: .85rem; cursor: pointer; min-height: 34px; }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; }
.m-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.m-nums b { display: block; font-family: var(--font-head); font-size: 2rem; line-height: 1.1; color: var(--primary); }
@media (prefers-color-scheme: dark) { .m-nums b { color: var(--accent); } }
.m-nums span { font-size: .82rem; color: var(--muted); font-weight: 600; }
.m-chart { display: flex; align-items: flex-end; gap: 3px; height: 96px; border-bottom: 1px solid var(--line); }
.mbar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; }
.mbar i { display: block; width: 100%; background: color-mix(in srgb, var(--primary) 55%, transparent); border-radius: 3px 3px 0 0; }
.mbar .mo { font-size: .7rem; font-weight: 800; background: var(--accent); color: var(--on-accent); border-radius: 999px; padding: 0 6px; margin-bottom: 3px; line-height: 1.4; }
.mbar .mo:empty { display: none; }
.m-foot { font-size: .8rem; color: var(--muted); margin: 8px 0 0; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.key.v { background: color-mix(in srgb, var(--primary) 55%, transparent); }
.key.o { background: var(--accent); border-radius: 50%; }
@media (max-width: 600px) { .m-nums b { font-size: 1.6rem; } .m-nums span { font-size: .75rem; } }
@media print { .metrics { display: none !important; } }

/* customer photos */
.photos { display: flex; flex-wrap: wrap; gap: 10px; }
.ph { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--card); cursor: zoom-in; overflow: hidden; width: 110px; height: 110px; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(10,5,8,.88); display: flex; align-items: center; justify-content: center; padding: 20px; cursor: zoom-out; }
.lightbox img { max-width: min(92vw, 1100px); max-height: 88vh; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lightbox button { position: absolute; top: 50%; transform: translateY(-50%); border: 0; background: rgba(255,255,255,.16); color: #fff; font-size: 2.4rem; line-height: 1; width: 52px; height: 64px; border-radius: 12px; cursor: pointer; }
.lb-prev { left: 12px; } .lb-next { right: 12px; }
.lb-count { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); color: #fff; font-weight: 700; font-size: .9rem; }
