:root {
  --bg: #f4f4f5;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e4e4e7;
  --brand: #e8671d;
  --brand-dark: #3c3c3c; --brand-soft: #fdf0e8; --brand-line: #f3b48e;
  --ok: #1f7a4d;
  --err: #b42318;
  --warn: #9a6700;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand-dark); }
h1 { font-size: 1.5rem; margin: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
h3 { font-size: 1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: 0 1rem; background: var(--brand-dark); color: #fff; min-height: 52px; position: sticky; top: 0; z-index: 10; }
.topbar a { color: #fff; text-decoration: none; }
.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: .02em; display: inline-flex; align-items: center; gap: .5rem; }
.brand img { height: 46px; max-width: 140px; object-fit: contain; background: #fff; border-radius: 6px; padding: 3px 6px; }
.topbar { min-height: 60px; border-bottom: 3px solid var(--brand); }
header.topbar nav a.active { background: var(--brand); opacity: 1; }
.welcome { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1rem; }
.welcome img { height: 84px; max-width: 220px; object-fit: contain; background: #fff; border-radius: var(--radius); padding: 6px 10px; border: 1px solid var(--line); }
.welcome .hello { font-size: 1.35rem; font-weight: 700; }
.welcome .today { color: var(--muted); }
.login-logo { max-height: 80px; max-width: 240px; object-fit: contain; align-self: center; }
.settings-tabs { margin-bottom: 1rem; }
.logo-preview { max-height: 70px; max-width: 260px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }
input[type=color] { height: 42px; padding: 2px; width: 90px; }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
.topbar nav { display: flex; gap: .25rem; flex: 1; }
.topbar nav a { padding: .45rem .7rem; border-radius: 6px; opacity: .85; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.15); opacity: 1; }
.topbar .user { display: flex; gap: 1rem; }
.topbar .user .muted { color: #dddddd; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; margin-left: auto; cursor: pointer; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.bottom-actions { margin-top: 1rem; }

/* Cards and forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
label { display: flex; flex-direction: column; gap: .25rem; font-weight: 600; font-size: .85rem; color: #3b3f45; }
label.inline { flex-direction: row; align-items: center; gap: .4rem; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); padding: .5rem .6rem; border: 1px solid #d4d4d8; border-radius: 6px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-line); outline-offset: -1px; border-color: var(--brand-line); }
input[readonly] { background: #fafafa; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem 1rem; }
.form-grid.cols3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.span4 { grid-column: 1 / -1; }
.new-customer { background: var(--brand-soft); border: 1px dashed var(--brand-line); border-radius: 6px; padding: .75rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.filters input[name=s] { max-width: 320px; }
.filters select, .filters input[type=date] { width: auto; }
.inline-form { display: flex; gap: .35rem; align-items: center; }
.inline-form input { width: 140px; }
.details { display: grid; gap: .4rem; }
.details b { display: inline-block; min-width: 80px; color: var(--muted); font-weight: 600; }

.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .5rem .9rem; border: 1px solid #d4d4d8; background: #fff; color: var(--ink); border-radius: 6px; cursor: pointer; font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f1f1f1; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--err); border-color: #e7b4ae; }
.btn.small { padding: .3rem .55rem; font-size: .85rem; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: .25rem .4rem; }
.icon-btn:hover { color: var(--err); }

.flash { padding: .7rem .9rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #e9f6ef; border-color: #b6e0c8; color: var(--ok); }
.flash.err { background: #fdecea; border-color: #f3b8b2; color: var(--err); }
.flash.warn { background: #fff6e0; border-color: #f0d68a; color: var(--warn); }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .55rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
thead th { background: #f7f7f8; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
th.r, td.r { text-align: right; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: var(--brand-soft); }
tfoot td { background: #f7f7f8; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 99px; background: #eee; color: #444; text-transform: uppercase; letter-spacing: .03em; }
.badge.sent { background: #e6f0ff; color: #1d4ed8; }
.badge.accepted { background: #fff4d6; color: #8a5a00; }
.badge.invoiced { background: #f3e8ff; color: #6b21a8; }
.badge.paid { background: #e3f6ea; color: var(--ok); }
.badge.cancelled { background: #f1f1f1; color: #888; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stat-v { font-size: 1.6rem; font-weight: 700; }
.stat-l { color: var(--muted); font-size: .85rem; }

/* Quote item grid */
table.items td { padding: .25rem .25rem; }
table.items input { padding: .35rem .4rem; font-size: .85rem; }
table.items td.no { color: var(--muted); text-align: center; width: 28px; }
.w-xs { width: 70px; } .w-s { width: 100px; } .w-n { width: 78px; } .w-q { width: 52px; } .w-l { width: 210px; }
.out-note { font-size: .78rem; color: var(--ok); white-space: nowrap; }
.out-note.warn { color: var(--err); font-weight: 700; }
.out-auto, .out-unit { color: var(--muted); white-space: nowrap; }
.out-line { white-space: nowrap; }

.bottom-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; margin-top: 1rem; }
.bottom-grid .card { display: flex; flex-direction: column; gap: .75rem; }
.totals > div { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px dashed var(--line); }
.totals > div.big { font-size: 1.15rem; }
.totals > div.muted { border: 0; }

/* Price grid */
table.grid th, table.grid td { padding: .2rem; text-align: center; }
table.grid tbody th { background: #f7f7f8; font-size: .8rem; white-space: nowrap; padding: .2rem .5rem; }
table.grid input { width: 72px; padding: .3rem; text-align: right; font-size: .82rem; }
.grid-wrap { max-height: 70vh; }
.tabs { display: flex; gap: .25rem; }
.tabs a { padding: .45rem .8rem; border-radius: 6px; text-decoration: none; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Login */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.login-box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: .9rem; box-shadow: 0 10px 30px rgba(60,40,20,.08); }
.login-box.wide { max-width: 560px; }
.login-box h1 { color: var(--brand-dark); }
.login-box h3 { margin: .75rem 0 0; }
.login-box .btn { justify-content: center; }

/* Price lists */
.wrap-tabs { flex-wrap: wrap; }
tr.inactive td { color: #999; }
table.grid input.empty { background: #fdecea; border-color: #f3b8b2; }
table.grid th .rm { display: inline-flex; flex-direction: row; align-items: center; gap: 2px; margin-left: 4px; font-size: .7rem; color: var(--err); cursor: pointer; font-weight: 400; }
table.grid th .rm input { width: auto; margin: 0; }
.card.inset { background: var(--brand-soft); margin: 0; }
.card.inset label.inline { margin: .4rem 0; }
#price-check .stat-v { font-size: 1.3rem; }

/* Invoice & job statuses */
.badge.unpaid { background: #fdecea; color: var(--err); }
.badge.partial { background: #fff4d6; color: #8a5a00; }
.badge.declined { background: #f1f1f1; color: #888; }
.badge.scheduled { background: #e6f0ff; color: #1d4ed8; }
.badge.confirmed { background: #e3f6ea; color: var(--ok); }
.badge.in_progress { background: #fff4d6; color: #8a5a00; }
.badge.done { background: #f1f1f1; color: #666; }
.badge.type { background: var(--brand-soft); color: var(--brand-dark); }
.overdue { color: var(--err); font-weight: 700; }
tr.late-row td { background: #fff7f6; }
table.list.static tbody tr { cursor: default; }
.linkbar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; background: var(--brand-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: 1rem; }
a.stat { text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--brand-line); }
.stat-v small { font-size: .8rem; display: block; }
.bottom-grid.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.attach { background: var(--brand-soft); border: 1px dashed var(--brand-line); border-radius: 6px; padding: .6rem .8rem; }

/* Upcoming work */
.day-head { margin-top: 1.5rem; }
.day-head.overdue { color: var(--err); }
.jobs { display: flex; flex-direction: column; gap: .5rem; }
.job { display: flex; gap: 1rem; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--brand-line); border-radius: var(--radius); padding: .75rem 1rem; }
.job.late { border-left-color: var(--err); }
.job.done, .job.cancelled { opacity: .7; border-left-color: #bbb; }
.job-time { min-width: 52px; display: flex; flex-direction: column; font-size: 1rem; }
.job-time span { font-size: .8rem; color: var(--muted); }
.job-main { flex: 1; min-width: 0; }
.job-top { display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: center; }
.job-top a { text-decoration: none; }
.job-meta { color: var(--muted); font-size: .88rem; margin-top: .25rem; overflow-wrap: anywhere; }
.job-details { margin-top: .35rem; font-size: .9rem; }
.cal-nav { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.cal-nav h2 { margin: 0; min-width: 160px; text-align: center; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: #f7f7f8; padding: .4rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; color: var(--muted); text-align: center; }
.cal-day { background: #fff; min-height: 104px; padding: .3rem; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day.other { background: #fafafa; }
.cal-day.other .cal-num a { color: #bbb; }
.cal-day.today { background: var(--brand-soft); }
.cal-num a { font-weight: 700; font-size: .85rem; text-decoration: none; color: var(--ink); }
.cal-job { display: block; font-size: .75rem; line-height: 1.25; padding: 2px 5px; border-radius: 4px; background: var(--brand-soft); color: var(--brand-dark); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-job small { display: block; color: var(--muted); }
.cal-job.done { background: #eee; color: #777; }
.cal-job.confirmed { background: #e3f6ea; color: var(--ok); }

@media print {
  .topbar, .no-print, .filters, .flash, .bottom-actions { display: none !important; }
  body { background: #fff; }
  .wrap { padding: 0; max-width: none; }
  .card, .job, .table-wrap { break-inside: avoid; border-color: #ccc; }
  input, select, textarea { border: 0; padding: 0; resize: none; }
}

@media (max-width: 900px) {
  .bottom-grid.even { grid-template-columns: minmax(0, 1fr); }
  .calendar { font-size: .8rem; }
  .cal-day { min-height: 70px; }
  .cal-job small { display: none; }
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .menu-btn { display: block; }
  .topbar nav, .topbar .user { display: none; width: 100%; flex-direction: column; padding-bottom: .5rem; }
  body.nav-open .topbar nav, body.nav-open .topbar .user { display: flex; }
  .form-grid, .form-grid.cols3, .form-grid.cols4, .bottom-grid { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3, .span4 { grid-column: auto; }
  .filters input[name=s] { max-width: none; }
}
