:root {
  --black: #1A1A1A;
  --ink: #111;
  --red: #E63946;
  --red-dark: #c0303b;
  --bg: #f3f3f4;
  --card: #fff;
  --line: #e5e7eb;
  --muted: #6B7280;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(0,0,0,.06);
  --head: 'Montserrat', system-ui, sans-serif;
  --body: 'Open Sans', system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--body); font-size: 16px; color: var(--ink); background: var(--bg); }
h1, h2, h3 { font-family: var(--head); margin: 0; }
h3 { font-size: 1rem; margin-bottom: 12px; }
a { color: var(--red-dark); }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; font-size: 16px; }

.demo-banner { background: #fff4d6; color: #7a5200; padding: 8px 16px; font-size: .85rem; text-align: center; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg,#0f0f0f 0%,#1a1a1a 60%,#1f1f1f 100%); padding: 16px; }
.login-card { background: #151515; border: 1px solid #2a2a2a; color: #fff; border-radius: 20px; padding: 36px 28px; text-align: center; width: 100%; max-width: 380px; }
.login-logo { width: 220px; max-width: 80%; }
.login-card h1 { margin: 12px 0 6px; font-size: 1.4rem; }
.login-card p { color: #bbb; }
.login-msg { color: #ff8a93 !important; min-height: 1.2em; }

/* ---------- shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--black); color: #fff; display: flex; align-items: center;
  justify-content: space-between; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; }
.topbar-logo { height: 34px; }
.topbar-right { display: flex; gap: 8px; align-items: center; min-width: 0; }
.sync, .device-chip { background: #2a2a2a; color: #eee; border: 0; border-radius: 99px; padding: 5px 11px; font-size: .8rem;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.device-chip { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; display: inline-block; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.sync[data-state="pending"] .dot { background: #fbbf24; }
.sync[data-state="offline"] .dot { background: #9ca3af; }

.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 50px; z-index: 15; }
.tabs button { flex: 1; background: none; border: 0; padding: 10px 4px; color: var(--muted); font-family: var(--head); font-weight: 700;
  font-size: .8rem; display: flex; flex-direction: column; align-items: center; gap: 2px; border-bottom: 3px solid transparent; }
.tabs button.active { color: var(--red); border-bottom-color: var(--red); }
.tabs .ico { font-size: 1.15rem; line-height: 1; }

main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 110px; }

@media (max-width: 700px) {
  .tabs { position: fixed; bottom: 0; top: auto; left: 0; right: 0; border-top: 1px solid var(--line); border-bottom: 0;
    padding-bottom: var(--safe-b); }
  .tabs button { border-bottom: 0; border-top: 3px solid transparent; }
  .tabs button.active { border-top-color: var(--red); }
  main { padding: 12px 12px calc(140px + var(--safe-b)); }
  .topbar-logo { height: 28px; }
}

.fab { position: fixed; right: 18px; bottom: 24px; z-index: 25; background: var(--red); color: #fff; border: 0; border-radius: 99px;
  padding: 14px 22px; font-family: var(--head); font-weight: 800; box-shadow: 0 6px 20px rgba(230,57,70,.45); }
.fab:hover { background: var(--red-dark); }
@media (max-width: 700px) { .fab { bottom: calc(78px + var(--safe-b)); right: 14px; } }

/* ---------- common ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 10px; padding: 10px 16px;
  border: 1px solid transparent; font-family: var(--head); font-weight: 700; font-size: .9rem; text-decoration: none; min-height: 42px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-lg { padding: 14px 24px; font-size: 1rem; width: 100%; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: #bbb; }
.btn-danger { background: #b91c1c; color: #fff; }
.btn-danger-ghost { background: none; border-color: #f3c4c7; color: #b91c1c; width: 100%; margin-top: 8px; }
.iconbtn { background: none; border: 0; font-size: 1.2rem; padding: 6px 10px; border-radius: 8px; color: inherit; min-width: 40px; min-height: 40px; }
.iconbtn:hover { background: rgba(0,0,0,.06); }
.linkbtn { background: none; border: 0; color: var(--red-dark); text-decoration: underline; padding: 2px 4px; font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.actions:empty { display: none; }
.actions.end { justify-content: flex-end; }
.fine { color: var(--muted); font-size: .85rem; margin: 4px 0; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.owed { color: #b91c1c; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.muted { color: var(--muted); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.toolbar input[type=search] { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 7px 14px; white-space: nowrap; font-size: .85rem; font-weight: 600; }
.chip.on { background: var(--black); color: #fff; border-color: var(--black); }

/* ---------- form fields ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: .8rem; font-weight: 600; color: #444; }
.field input, .field select, .field textarea, .crew-row select, .crew-row input, .photo-add select {
  width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 9px; background: #fff; color: var(--ink); min-height: 44px; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .crew-row :focus { outline: 2px solid var(--red); outline-offset: -1px; border-color: transparent; }
.field.gate input { font-family: ui-monospace, monospace; font-weight: 700; font-size: 1.1rem; background: #fffbea; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; font-weight: 600; font-size: .95rem; }
.check input { width: 20px; height: 20px; accent-color: var(--red); }
.check.small { font-size: .85rem; margin: 0; }
.grid { display: grid; gap: 0 12px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.field-end { display: flex; align-items: flex-end; padding-bottom: 8px; }
@media (max-width: 520px) { .g3 { grid-template-columns: 1fr 1fr; } .g3 > :first-child { grid-column: 1 / -1; } .g2 { grid-template-columns: 1fr; } }
.balance { font-family: var(--head); font-size: 1.05rem; margin-top: 4px; }

/* ---------- job cards ---------- */
.job-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.job-card { text-align: left; background: #fff; border: 0; border-left: 5px solid var(--st); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px; color: inherit; display: flex; flex-direction: column; gap: 6px; }
.job-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); }
.jc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.jc-date { font-size: .82rem; color: var(--muted); font-weight: 600; }
.jc-title { font-family: var(--head); font-weight: 700; }
.jc-meta { display: flex; flex-direction: column; gap: 2px; font-size: .88rem; color: #333; }
.jc-money { display: flex; flex-wrap: wrap; gap: 10px; font-size: .85rem; font-weight: 700; }
.jc-money:empty { display: none; }
.badge { color: #fff; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }

/* ---------- job editor sheet ---------- */
dialog { border: 0; padding: 0; color: inherit; }
dialog::backdrop { background: rgba(0,0,0,.55); }
.sheet { width: 100%; max-width: 760px; height: 100%; max-height: 100%; margin: 0 auto; border-radius: 0; background: var(--bg); }
@media (min-width: 761px) { .sheet { height: calc(100% - 40px); max-height: calc(100% - 40px); margin-top: 20px; border-radius: 16px; } }
.sheet form { display: flex; flex-direction: column; height: 100%; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--black); color: #fff; }
.sheet-head h2 { flex: 1; font-size: 1.1rem; }
.sheet-body { flex: 1; overflow-y: auto; padding: 14px 14px calc(40px + var(--safe-b)); -webkit-overflow-scrolling: touch; }

.crew-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto auto auto; gap: 8px; align-items: center; margin-bottom: 10px;
  padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
.crew-row:has(input[data-k=hours]) { grid-template-columns: 1.3fr 1fr 1fr .8fr auto auto auto; }
.crew-amt { font-weight: 700; font-family: var(--head); min-width: 60px; text-align: right; }
@media (max-width: 560px) {
  .crew-row, .crew-row:has(input[data-k=hours]) { grid-template-columns: 1fr 1fr; }
  .crew-row select[data-k=workerId] { grid-column: 1 / -1; }
  .crew-amt { text-align: left; }
}

.review { display: flex; flex-direction: column; gap: 4px; background: #fafafa; border-radius: 10px; padding: 12px; margin-top: 4px; }

.hist { border-left: 3px solid var(--line); padding: 4px 0 8px 10px; margin-bottom: 8px; font-size: .9rem; }
.hist-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.hist ul { margin: 4px 0 0; padding-left: 18px; }
.hist li { margin: 2px 0; word-break: break-word; }
.hist .f { font-weight: 600; }
.hist s { color: var(--muted); }
.activity { max-height: 520px; overflow-y: auto; }

/* ---------- photos ---------- */
.photo-add { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.photo-add select { width: auto; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumb { position: relative; padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: #ddd; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tlabel { position: absolute; left: 0; bottom: 0; right: 0; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff;
  font-size: .72rem; font-weight: 700; padding: 10px 6px 4px; text-align: left; }
.tag { position: absolute; top: 5px; font-size: .65rem; font-weight: 800; color: #fff; border-radius: 6px; padding: 2px 5px; }
.tag.w { right: 5px; background: var(--ok); }
.tag.g { right: 5px; top: 24px; background: #2563eb; }
.pg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.tip { border-left: 4px solid var(--red); }

.photo-viewer { width: 100%; max-width: 900px; max-height: 100%; background: #111; color: #fff; border-radius: 0; }
@media (max-width: 900px) { .photo-viewer { height: 100%; margin: 0; } }
@media (min-width: 901px) { .photo-viewer { border-radius: 14px; max-height: calc(100% - 40px); } }
.pv-head { display: flex; justify-content: space-between; gap: 8px; padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top)); }
.pv-head .fine { color: #aaa; }
.pv-img { display: grid; place-items: center; background: #000; }
.pv-img img { max-width: 100%; max-height: 60vh; display: block; }
.pv-img img.loading { filter: blur(6px); }
.pv-actions { padding: 12px 14px calc(16px + var(--safe-b)); }
.pv-actions .btn-danger-ghost { color: #ff8a93; border-color: #5a2a2e; }

/* ---------- costs & profit ---------- */
.cost-group { border-bottom: 1px solid var(--line); padding: 8px 0 10px; }
.cost-head { display: flex; justify-content: space-between; font-size: .92rem; margin-bottom: 6px; }
.cost-row { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.cost-row.has-where { grid-template-columns: 1.4fr 1fr 110px auto; }
.cost-row input { width: 100%; min-width: 0; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 9px; min-height: 44px; }
@media (max-width: 560px) {
  .cost-row.has-where { grid-template-columns: 1fr 110px auto; }
  .cost-row.has-where [data-ck=where] { grid-column: 1 / 2; grid-row: 2; }
}
.builder { background: #f0f7ff; border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.builder > b { display: block; margin-bottom: 8px; }
.builder .btn { width: 100%; margin-top: 6px; }
.pl { background: #fafafa; border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.pl-line { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: .93rem; }
.pl-total { border-top: 2px solid var(--line); margin-top: 6px; padding-top: 8px; font-family: var(--head); font-weight: 800; font-size: 1.05rem; }
.stat-profit { border: 2px solid #bbf7d0; }
.stat small, .row-link small { font-size: .75em; color: var(--muted); font-weight: 600; }
.row-link .fine { display: block; margin: 2px 0 0; }

/* ---------- Square ---------- */
.sq { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 12px; background: #fcfcfc; }
.sq-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.sq-line { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.sq-line .fine { display: block; margin: 0; }
.sq-inv { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-top: 8px; font-size: .92rem; }
.sq-inv.open { border-color: #fcd34d; background: #fffdf5; }
.btn-sq { background: #111; color: #fff; }
.btn-sq:hover { background: #333; }
.inv-status { font-weight: 700; }
.inv-status.s-PAID { color: var(--ok); }
.inv-status.s-UNPAID, .inv-status.s-PARTIALLY_PAID, .inv-status.s-SCHEDULED, .inv-status.s-PAYMENT_PENDING { color: var(--warn); }
.inv-status.s-CANCELED, .inv-status.s-FAILED, .inv-status.s-REFUNDED { color: var(--muted); }

/* ---------- tools checklist ---------- */
.tool-row { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.tool-row .check { margin: 8px 0; flex: 1; }
.tool-add { display: flex; gap: 8px; margin: 12px 0 8px; }
.tool-add input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 9px; min-height: 44px; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin-top: 8px; }
.chips.wrap .chip { font-size: .8rem; padding: 6px 11px; }
.copy-tools { width: 100%; margin-top: 4px; }

/* ---------- weather ---------- */
.wx { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: .88rem; }
.wx-main { font-weight: 600; }
.wx-rain.hi { color: #1d4ed8; font-weight: 700; }
.wx-warn { background: #fef3c7; color: #92400e; font-weight: 700; border-radius: 6px; padding: 1px 6px; }
.wx-note { flex-basis: 100%; }
.wx-box { background: #f0f7ff; border-radius: 10px; padding: 10px 12px; margin: 4px 0 8px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.wx-box:empty { display: none; }

/* ---------- today panel ---------- */
#today-panel { margin-bottom: 14px; }
.today-title { margin: 2px 2px 10px; }
.today-job { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); border-left: 5px solid var(--st);
  padding: 12px 14px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.tj-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.tj-gate { background: #fffbea; border-radius: 8px; padding: 6px 10px; font-size: .95rem; }
.tj-gate b { font-family: ui-monospace, monospace; font-size: 1.1rem; }
.tj-tools { display: flex; flex-wrap: wrap; gap: 2px 14px; background: #fafafa; border-radius: 8px; padding: 8px 10px; }
.tj-tools .fine { flex-basis: 100%; margin: 0 0 4px; }

/* ---------- money ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat span { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat b { font-family: var(--head); font-size: 1.25rem; }
.worker { border-bottom: 1px solid var(--line); padding: 8px 0; }
.worker summary { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; cursor: pointer; list-style: none; }
.worker summary::before { content: '▸'; color: var(--muted); }
.worker[open] summary::before { content: '▾'; }
.pay-line { display: flex; align-items: center; gap: 10px; padding: 8px 0 8px 18px; font-size: .9rem; }
.pay-line span { flex: 1; }
.pay-line input { width: 20px; height: 20px; accent-color: var(--red); }
.row-link { display: flex; justify-content: space-between; gap: 10px; width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 10px 0; text-align: left; color: inherit; }

/* ---------- small dialog & toast ---------- */
.small-dialog { width: calc(100% - 32px); max-width: 420px; border-radius: 16px; background: #fff; }
.fd { padding: 20px; }
.fd h3 { margin-bottom: 8px; }
.toast { position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; background: #222; color: #fff;
  padding: 12px 18px; border-radius: 10px; z-index: 1000; transition: .25s; max-width: calc(100% - 32px); font-size: .92rem; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }
@media (max-width: 700px) { .toast { bottom: calc(150px + var(--safe-b)); } }

/* ---------- FullCalendar brand tweaks ---------- */
#calendar { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.fc { --fc-button-bg-color: var(--black); --fc-button-border-color: var(--black); --fc-button-hover-bg-color: #333;
  --fc-button-active-bg-color: var(--red); --fc-button-active-border-color: var(--red); --fc-today-bg-color: #fff1f2; --fc-border-color: #eee; }
.fc .fc-toolbar-title { font-family: var(--head); font-size: 1.15rem; }
.fc .fc-button { font-family: var(--head); font-weight: 700; font-size: .8rem; text-transform: none; }
.fc .fc-event { cursor: pointer; font-size: .8rem; }
.fc .fc-list-event-title { font-weight: 600; }
.fc a { color: inherit; text-decoration: none; }
@media (max-width: 700px) { #calendar { padding: 8px; } .fc .fc-toolbar { gap: 6px; } .fc .fc-toolbar-title { font-size: 1rem; } }
