:root {
  --bg: #f4f2ee;
  --card: #fff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e3dfd8;
  --accent: #c2621d;
  --accent-dark: #9e4d12;
  --top: #23282e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent-dark); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: .5rem 0 .25rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn { background: #fff4e5; border: 1px solid #f3c58b; padding: .6rem .8rem; border-radius: 8px; }

/* Top bar */
.topbar { background: var(--top); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1.1rem; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.topbar .brand::before { content: "🔨 "; }
.topbar nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.topbar nav a, .topbar .linkbtn { color: #d8dde3; text-decoration: none; font-size: .95rem; }
.topbar nav a:hover, .topbar .linkbtn:hover { color: #fff; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 1.1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.narrow { max-width: 420px; margin: 3rem auto; }
.narrow-left { max-width: 460px; }
.login h1 { text-align: center; margin-bottom: 1rem; }

.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.sechead { display: flex; justify-content: space-between; align-items: baseline; }
.back { display: inline-block; margin-bottom: .6rem; text-decoration: none; }

/* Forms */
input, select, textarea { font: inherit; width: 100%; padding: .6rem .7rem; border: 1px solid #cfc9bf; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; font-size: .9rem; }
label input, label select, label textarea { margin-top: .3rem; font-weight: 400; }
.checkrow { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.checkrow input { width: auto; margin: 0; }
.stack > * + * { margin-top: .8rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.inline { display: inline; margin: 0; }

.btn { display: inline-block; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: .62rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--accent-dark); }
.btn-light { background: #ece8e1; color: var(--ink); }
.btn-light:hover { background: #e0dbd2; }
.btn-danger { background: #b42318; }
.btn-danger:hover { background: #8f1c13; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent-dark); cursor: pointer; text-decoration: underline; }
.linkbtn.danger { color: #b42318; }
.x { background: none; border: 0; font-size: 1.3rem; line-height: 1; color: #a09a91; cursor: pointer; padding: 0 .3rem; }
.x:hover { color: #b42318; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-ok { background: #e7f6ec; border: 1px solid #a6dbb6; color: #14532d; }
.flash-err { background: #fdecea; border: 1px solid #f3b4ae; color: #7a1d14; }

/* Job list */
.filters { display: flex; gap: .5rem; margin-bottom: .8rem; }
.tabs { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .4rem; margin-bottom: 1rem; scrollbar-width: thin; }
.tab { white-space: nowrap; padding: .35rem .8rem; border-radius: 999px; background: #e9e5de; color: var(--ink); text-decoration: none; font-size: .88rem; }
.tab.on { background: var(--top); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.jobcard { padding: 0; overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; transition: transform .1s, box-shadow .1s; margin: 0; }
.jobcard:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.08); }
.cover { position: relative; aspect-ratio: 16/9; background: #e9e5de; display: flex; align-items: center; justify-content: center; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.nocover { color: #a09a91; font-size: .85rem; }
.cover .badge { position: absolute; top: .6rem; left: .6rem; }
.jobbody { padding: .8rem 1rem 1rem; }
.jobbody h3 { margin: 0 0 .15rem; font-size: 1.05rem; }
.meta { display: flex; flex-wrap: wrap; gap: .3rem .8rem; margin-top: .5rem; font-size: .85rem; color: var(--muted); }
.overdue { color: #b42318; font-weight: 600; }
.empty { text-align: center; padding: 2.5rem 1rem; }

/* Status colors */
.badge, .chip { display: inline-block; padding: .2rem .65rem; border-radius: 999px; font-size: .78rem; font-weight: 700; border: 1px solid transparent; }
.st-lead { background: #eef2ff; color: #3730a3; }
.st-scheduled { background: #e0f2fe; color: #075985; }
.st-in-progress { background: #fff1e0; color: #9a3412; }
.st-on-hold { background: #f3f4f6; color: #4b5563; }
.st-completed { background: #dcfce7; color: #166534; }
.st-cancelled { background: #fde8e8; color: #9b1c1c; }

/* Job page */
.statusform { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip { cursor: pointer; opacity: .55; font: inherit; font-size: .82rem; font-weight: 600; padding: .3rem .8rem; }
.chip:hover { opacity: .85; }
.chip.on { opacity: 1; border-color: currentColor; }
.details { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .7rem 1.2rem; margin: 0; }
.details dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.desc { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.cols > .card { margin-bottom: 0; }
.cols + .card, .cols + * { margin-top: 1rem; }

.progress { height: 6px; background: #eee9e1; border-radius: 99px; overflow: hidden; margin-bottom: .6rem; }
.progress span { display: block; height: 100%; background: #22a05a; transition: width .3s; }
.todos { list-style: none; margin: 0 0 .8rem; padding: 0; }
.todos li { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid #f0ece6; }
.todos .ttext { flex: 1; word-break: break-word; }
.todos li.done .ttext { text-decoration: line-through; color: var(--muted); }
.check { width: 26px; height: 26px; flex: none; border: 2px solid #bdb6ab; border-radius: 7px; background: #fff; cursor: pointer; color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; padding: 0; }
.check:hover { border-color: #22a05a; }
.todos li.done .check { background: #22a05a; border-color: #22a05a; }
.addrow { display: flex; gap: .5rem; align-items: flex-start; }
.addrow textarea { min-height: 2.7rem; }

.note { border-top: 1px solid var(--line); padding: .7rem 0 .2rem; margin-top: .8rem; word-break: break-word; }
.notehead { display: flex; justify-content: space-between; align-items: center; }

.upload { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.upload > input { flex: 1; min-width: 180px; }
.filepick { position: relative; display: inline-block; font-weight: 600; }
.filepick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.filepick span { display: inline-block; padding: .6rem 1rem; border: 2px dashed #cfc9bf; border-radius: 8px; background: #faf8f5; }
.filepick:hover span { border-color: var(--accent); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; }
.gallery figure { margin: 0; background: #faf8f5; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.gallery img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.gallery figcaption { padding: .4rem .5rem .3rem; }
.capform input { border: 0; background: transparent; padding: .2rem; font-size: .88rem; }
.capform input:focus { background: #fff; }
.photometa { display: flex; justify-content: space-between; align-items: center; padding: 0 .2rem; }

#lightbox { position: fixed; inset: 0; background: rgba(10,12,14,.93); z-index: 100; display: flex; align-items: center; justify-content: center; }
#lightbox[hidden] { display: none; }
#lightbox figure { margin: 0; max-width: 92vw; max-height: 90vh; text-align: center; }
#lightbox img { max-width: 92vw; max-height: 82vh; object-fit: contain; border-radius: 6px; }
#lightbox figcaption { color: #ddd; margin-top: .5rem; }
#lightbox button { position: absolute; background: rgba(255,255,255,.12); color: #fff; border: 0; font-size: 2rem; width: 48px; height: 48px; border-radius: 50%; cursor: pointer; }
#lightbox button:hover { background: rgba(255,255,255,.25); }
.lbclose { top: 1rem; right: 1rem; }
.lbprev { left: 1rem; }
.lbnext { right: 1rem; }

.danger-zone { margin-top: 1rem; text-align: right; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .3rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); text-transform: uppercase; }
details summary { cursor: pointer; color: var(--accent-dark); }
details form { margin-top: .5rem; }

@media (max-width: 760px) {
  .cols { grid-template-columns: 1fr; }
  .cols > .card { margin-bottom: 0; }
  .wrap { padding: .8rem; }
  h1 { font-size: 1.35rem; }
}
@media (max-width: 480px) {
  .row2 { grid-template-columns: 1fr; }
  .topbar nav { gap: .7rem; font-size: .9rem; }
}
.center { text-align: center; margin-top: 1rem; }

/* Money */
.neg { color: #b42318 !important; }
.pos { color: #166534; font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7rem; margin-bottom: .9rem; }
.tile { background: #faf8f5; border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
.tile span { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tile b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.tiles.big .tile { background: var(--card); box-shadow: var(--shadow); padding: .9rem 1rem; }
.tiles.big .tile b { font-size: 1.6rem; }
.spendbar { height: 8px; background: #eee9e1; border-radius: 99px; overflow: hidden; margin-bottom: .3rem; }
.spendbar span { display: block; height: 100%; background: #eb6834; border-radius: 99px; }
.spendbar span.over { background: #b42318; }
.expform { display: grid; grid-template-columns: 150px 170px 1fr 120px auto; gap: .5rem; margin: 1rem 0 .6rem; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.exptable td { padding: .45rem .3rem; }
.table.compact td { padding: .35rem .3rem; }
.chartbox { position: relative; height: 300px; margin-bottom: .6rem; }
.tableview { margin: .4rem 0; }
.reportfilters { display: flex; gap: .5rem; }
.reportfilters select { width: auto; }
.minibar { height: 5px; background: #f0ece6; border-radius: 99px; margin-top: .3rem; overflow: hidden; max-width: 220px; }
.minibar span { display: block; height: 100%; background: #1baf7a; border-radius: 99px; }
.minibar span.neg { background: #b42318; }
.profittable td { vertical-align: middle; }
@media (max-width: 760px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .expform { grid-template-columns: 1fr 1fr; }
  .expform input[name=description] { grid-column: 1 / -1; }
  .chartbox { height: 240px; }
}
.nowrap { white-space: nowrap; }
.show-sm { display: none; }
@media (max-width: 760px) { .hide-sm { display: none; } .show-sm { display: block; } }
