:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #1b2430; --muted: #66707d; --line: #dde2e8;
  --brand: #1f4e79; --brand-ink: #ffffff; --accent: #e8f0f8; --warn: #fff4d6; --warn-ink: #7a5600;
  --err: #fde8e8; --err-ink: #9b1c1c; --ok: #e3f5e8; --ok-ink: #1d6b35;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d; --card: #1b232c; --ink: #e8edf2; --muted: #98a3b0; --line: #2c3743;
    --brand: #5aa0e0; --brand-ink: #08121c; --accent: #213244; --warn: #3b3112; --warn-ink: #f2cf72;
    --err: #3d1d1d; --err-ink: #f3a4a4; --ok: #17301f; --ok-ink: #8fd6a5;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 760px; margin: 0 auto; padding: 12px 14px 80px; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
h1 { font-size: 1.3rem; margin: .2rem 0 .6rem; line-height: 1.25; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
a { color: var(--brand); }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--brand); color: var(--brand-ink); padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top)); }
.top a.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.top nav { display: flex; align-items: center; gap: 10px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 8px 10px; border-radius: 8px; min-height: 40px; display: flex; align-items: center; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: 46px; width: 230px; background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); display: flex; flex-direction: column; gap: 4px; }
.menu-pop a, .linklike { padding: 10px 6px; color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; text-align: left; width: 100%; cursor: pointer; border-radius: 8px; }
.menu-pop a:hover, .linklike:hover { background: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.top .btn.primary { background: var(--brand-ink); color: var(--brand); border-color: var(--brand-ink); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: .9rem; }
.btn.big { min-height: 50px; font-size: 1.05rem; width: 100%; }
.btn.full { grid-column: 1 / -1; }
.btn[disabled] { opacity: .6; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 0 0 12px; }
.card.narrow { max-width: 420px; margin: 24px auto; }
.card.secret { background: var(--warn); color: var(--warn-ink); border-color: transparent; }
.secretbox { margin: 8px 0 0; padding: 10px; background: var(--card); color: var(--ink); border-radius: 8px; overflow-x: auto; user-select: all; font-size: 1rem; }
.flash, .notice { background: var(--ok); color: var(--ok-ink); padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; }
.notice { background: var(--warn); color: var(--warn-ink); }
.error { background: var(--err); color: var(--err-ink); padding: 10px 12px; border-radius: 10px; }

label { display: block; font-weight: 600; font-size: .92rem; }
input, select, textarea { display: block; width: 100%; margin-top: 6px; padding: 12px; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
textarea { resize: vertical; min-height: 84px; }
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0 8px 0 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { font-weight: 400; display: flex; align-items: flex-start; padding: 4px 0; }
.check input { margin-top: 4px; }

.search { display: flex; gap: 8px; margin-bottom: 10px; }
.search input { margin: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; align-items: center; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; font-size: .9rem; min-height: 38px; display: inline-flex; align-items: center; gap: 6px; }
.chip span { color: var(--muted); font-size: .8rem; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip.on span { color: inherit; opacity: .8; }

.joblist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.jobcard { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; color: inherit; text-decoration: none; }
.jobcard:active { background: var(--accent); }
.jobtitle { font-weight: 650; overflow-wrap: anywhere; }
.snippet { margin-top: 8px; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { font-size: .75rem; font-weight: 650; padding: 3px 8px; border-radius: 999px; background: var(--accent); color: var(--brand); }
.badge.wait { background: var(--warn); color: var(--warn-ink); }
.badge.done { background: var(--ok); color: var(--ok-ink); }
.badge[class*="out-"] { background: var(--err); color: var(--err-ink); }
.badge.share { background: var(--ok); color: var(--ok-ink); }
.badge.agent { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.kind { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.pager { display: flex; justify-content: space-between; margin-top: 14px; }

.crumb { margin: 4px 0 8px; }
.notes { margin-top: 8px; } .notes summary { cursor: pointer; font-weight: 600; font-size: .92rem; }
.plain { list-style: none; padding: 0; margin: 6px 0 0; }
.rows { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.kinds { display: flex; flex-wrap: wrap; gap: 8px; }
.kind input { position: absolute; opacity: 0; pointer-events: none; }
.kind span { display: inline-flex; align-items: center; min-height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; font-weight: 500; font-size: .9rem; background: var(--bg); cursor: pointer; }
.kind input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.kind input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.tl-title { margin: 14px 2px 8px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.upd { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.upd.kind-status_change { background: transparent; border-style: dashed; color: var(--muted); }
.upd.kind-payment_received { border-left-color: #2e9e57; } .upd.kind-po_received { border-left-color: #2e9e57; }
.upd.kind-quote_sent { border-left-color: #3b82c4; } .upd.kind-invoice { border-left-color: #7c5cc4; }
.upd.kind-closed { border-left-color: #c44545; } .upd.kind-waiting_client { border-left-color: #d9a21b; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: .85rem; margin-bottom: 4px; }

@media (min-width: 720px) { .row { flex-direction: row; justify-content: space-between; align-items: center; } }

.statuscard summary { cursor: pointer; font-weight: 650; min-height: 28px; }
.statuscard[open] summary { margin-bottom: 12px; }

.editlink { margin-left: auto; color: var(--muted); }

.navlink { color: inherit; text-decoration: none; padding: 8px 6px; }
.count { background: var(--brand-ink); color: var(--brand); border-radius: 999px; font-size: .75rem; font-weight: 700; padding: 1px 7px; }
.emailbody { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; max-height: 320px; overflow: auto; }
.emailform { display: flex; gap: 8px; margin-top: 8px; } .emailform input { margin: 0; }
