:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --line: #ddd6cb;
  --text: #1c1916;
  --muted: #6e665c;
  --accent: #c76a12;
  --accent-ink: #ffffff;
  --urgent: #c42b2b;
  --urgent-soft: #fbe6e4;
  --progress: #9a6b00;
  --progress-soft: #fbf0d6;
  --fixed: #2f7d4a;
  --fixed-soft: #e2f2e6;
  --shadow: 0 1px 2px rgba(40, 30, 20, .08), 0 4px 16px rgba(40, 30, 20, .06);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f;
    --surface: #1e1a17;
    --surface-2: #29231f;
    --line: #3a322c;
    --text: #f2ede6;
    --muted: #a59a8e;
    --accent: #f08a24;
    --accent-ink: #1a1007;
    --urgent: #ff5a4f;
    --urgent-soft: #3d1a17;
    --progress: #f2c14e;
    --progress-soft: #3a2f14;
    --fixed: #5fcf88;
    --fixed-soft: #16301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(10px + var(--safe-t)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.topbar-in { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 10px; min-height: 40px; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -.01em; }
.topbar h1 small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--surface-2);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- tabs and chips ---------- */
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin: 14px 0 10px; }
.tab {
  flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 9px;
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab .n { font-weight: 500; opacity: .7; margin-left: 3px; }
.chips { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.chip {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 6px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- job list ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.job {
  display: flex; gap: 12px; padding: 10px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); text-decoration: none; color: inherit; border-left: 4px solid transparent;
}
.job.urgent { border-left-color: var(--urgent); }
.job .thumb { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; }
.job .body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.job .where { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .what { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.job .meta { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-top: auto; flex-wrap: wrap; }
.job .waiting { font-size: 13px; color: var(--progress); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 2px 7px; border-radius: 6px; }
.badge.urgent { background: var(--urgent-soft); color: var(--urgent); }
.badge.club { background: var(--surface-2); color: var(--muted); }
.badge.open { background: var(--surface-2); color: var(--text); }
.badge.in_progress { background: var(--progress-soft); color: var(--progress); }
.badge.fixed { background: var(--fixed-soft); color: var(--fixed); }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

.banner {
  display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: var(--radius);
  background: var(--progress-soft); margin: 12px 0 0; font-size: 14px;
}
.banner p { margin: 0; flex: 1; }
.banner button { flex: none; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 650; cursor: pointer;
  background: var(--surface-2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.fixed { background: var(--fixed); color: #fff; }
.btn.progress { background: var(--progress-soft); color: var(--progress); }
.btn.danger { background: var(--urgent-soft); color: var(--urgent); }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(20px + var(--safe-b)); z-index: 6;
  border-radius: 999px; padding: 15px 22px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); font-size: 16px;
}
.fab svg { width: 20px; height: 20px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 18px; margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 14px; font-weight: 600; }
.field > small { color: var(--muted); font-size: 13px; }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; outline: none;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  padding: 14px 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  font-weight: 650; cursor: pointer; text-align: center;
}
.seg button small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 2px; }
.seg button[aria-pressed="true"] { border-color: var(--text); }
.seg button.urgent[aria-pressed="true"] { border-color: var(--urgent); background: var(--urgent-soft); color: var(--urgent); }
.seg button.urgent[aria-pressed="true"] small { color: var(--urgent); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; }
.photos .ph button {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 999px; border: 0;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
}
.add-photo {
  aspect-ratio: 1; border-radius: 12px; border: 2px dashed var(--line); background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--muted); font-size: 13px; cursor: pointer; position: relative;
}
.add-photo svg { width: 26px; height: 26px; }
.add-photo input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.error { color: var(--urgent); font-size: 14px; margin: 0; }
.muted { color: var(--muted); }

/* ---------- job detail ---------- */
.hero { margin: 14px -16px 0; display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 0 16px; }
.hero img { height: 280px; width: auto; max-width: 88%; object-fit: cover; border-radius: var(--radius); scroll-snap-align: start; cursor: zoom-in; background: var(--surface-2); }
.hero img:only-child { width: 100%; max-width: 100%; }
.job-head { margin: 16px 0 6px; }
.job-head .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.job-head h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.01em; }
.job-head p { margin: 0; white-space: pre-line; }
.job-head .by { color: var(--muted); font-size: 14px; margin-top: 8px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0; }
.actions .btn:only-child { grid-column: 1 / -1; }

.timeline { list-style: none; padding: 0; margin: 8px 0 0; border-left: 2px solid var(--line); margin-left: 8px; }
.timeline li { position: relative; padding: 0 0 18px 18px; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 999px;
  background: var(--surface-2); border: 2px solid var(--line);
}
.timeline li.in_progress::before { background: var(--progress); border-color: var(--progress); }
.timeline li.fixed::before { background: var(--fixed); border-color: var(--fixed); }
.timeline li.reopened::before { background: var(--urgent); border-color: var(--urgent); }
.timeline .t-head { font-size: 14px; }
.timeline .t-head b { font-weight: 650; }
.timeline .t-when { color: var(--muted); font-size: 13px; }
.timeline .t-msg { margin: 4px 0 0; white-space: pre-line; }
.timeline .t-photos { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.timeline .t-photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 8px; }
.told { font-size: 13px; color: var(--muted); }
.told div { padding: 2px 0; }
.told .no { color: var(--urgent); }

/* ---------- sheet (bottom drawer for actions) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 640px; background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b)); max-height: 92vh; overflow-y: auto;
  animation: up .18s ease-out;
}
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.sheet .form { margin-top: 12px; }
.sheet .row { display: flex; gap: 8px; }
.sheet .row .btn { flex: 1; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }

.viewer { position: fixed; inset: 0; z-index: 30; background: #000; display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer button { position: absolute; top: calc(12px + var(--safe-t)); right: 12px; }

/* ---------- sign-in ---------- */
.signin { max-width: 380px; margin: 0 auto; padding: calc(60px + var(--safe-t)) 20px 40px; }
.signin .mark { width: 64px; height: 64px; margin-bottom: 18px; }
.signin h1 { margin: 0 0 4px; font-size: 26px; }

/* ---------- settings / users ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-top: 14px; }
.card h2 { font-size: 17px; margin: 0 0 4px; }
.card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.card .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.user { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.user:first-of-type { border-top: 0; }
.user .who { flex: 1; min-width: 0; }
.user .who div:first-child { font-weight: 600; }
.user .who div + div { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.user.off { opacity: .5; }
.steps { margin: 0 0 12px; padding-left: 20px; font-size: 14px; }
.steps li { margin: 4px 0; }

#toast {
  top: calc(14px + var(--safe-t)); bottom: auto;
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3); max-width: calc(100% - 32px);
}
.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 999px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* before / after on a fixed job */
.hero figure { margin: 0; position: relative; flex: none; max-width: 88%; scroll-snap-align: start; }
.hero figure:only-child { max-width: 100%; width: 100%; }
.hero figure img { max-width: 100%; }
.hero figure:only-child img { width: 100%; }
.hero figcaption {
  position: absolute; left: 10px; top: 10px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px; background: rgba(0, 0, 0, .6); color: #fff;
}
.hero figure.cap-fixed figcaption { background: var(--fixed); }
