:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #f0eee9; --border: #e2ded6;
  --text: #1d1c1a; --muted: #6b675f; --accent: #c2410c; --accent-ink: #fff; --link: #9a3412;
  --in: #f0eee9; --out: #fde9dc; --bot: #eef1f4;
  --c-size: #b45309; --c-missing: #7c3aed; --c-onsite: #0369a1; --c-damage: #b91c1c; --c-measure: #0f766e; --c-general: #57534e;
  --ok: #15803d; --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --surface: #1f1e1c; --surface-2: #2a2826; --border: #353330;
    --text: #ece9e4; --muted: #a29d94; --accent: #f97316; --accent-ink: #1a0d04; --link: #fdba74;
    --in: #2a2826; --out: #43281a; --bot: #232a31;
    --c-size: #f59e0b; --c-missing: #a78bfa; --c-onsite: #38bdf8; --c-damage: #f87171; --c-measure: #2dd4bf; --c-general: #a8a29e;
    --ok: #4ade80; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--link); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .2rem; letter-spacing: -.01em; } h2 { font-size: 1.1rem; margin: 0 0 .6rem; } h3 { font-size: .95rem; margin: 0 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .85em; } .nowrap { white-space: nowrap; }
img { max-width: 100%; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.2rem; padding: .6rem 1.2rem;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); } .logo { color: var(--accent); }
.topbar nav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; } .topbar nav a { color: var(--muted); font-weight: 500; }
.topbar nav a.active { color: var(--text); } .topbar nav a.dev { margin-left: auto; font-size: .85em; }
.me { background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: .25rem .7rem; color: var(--text); cursor: pointer; font: inherit; }

main { max-width: 1100px; margin: 0 auto; padding: 1.2rem 1.2rem 4rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.stack > * + * { margin-top: .8rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .8rem; }

button, .btn { font: inherit; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .4rem .8rem; cursor: pointer; display: inline-flex; align-items: center; gap: .3rem; }
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.link { border: none; background: none; padding: 0; color: var(--link); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; width: 100%; }
textarea { resize: vertical; min-height: 2.6rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label { display: block; font-size: .82rem; color: var(--muted); font-weight: 500; }
label > input, label > select, label > textarea { margin-top: .2rem; }
label.check { display: inline-flex; align-items: center; gap: .35rem; color: var(--text); font-size: .9rem; }
label.check input { width: auto; margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; margin: 0; } legend { color: var(--muted); padding: 0 .3rem; }

/* search */
.search-hero { margin: 1.5rem 0 1rem; }
.search-hero input { font-size: 1.15rem; padding: .75rem 1rem; border-radius: 12px; }
.results { list-style: none; padding: 0; margin: 0; }
.results li a { display: flex; gap: .8rem; align-items: center; padding: .6rem .8rem; border-radius: 8px; color: var(--text); }
.results li a:hover, .results li a.kbd { background: var(--surface-2); text-decoration: none; }
.kind-ico { width: 2rem; height: 2rem; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); flex: none; font-size: 1rem; }
.pill { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.open { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.cat { font-weight: 600; font-size: .75rem; padding: .1rem .55rem; border-radius: 99px; color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); white-space: nowrap; }
.cat-size { --c: var(--c-size); } .cat-missing { --c: var(--c-missing); } .cat-onsite { --c: var(--c-onsite); } .cat-damage { --c: var(--c-damage); } .cat-measure { --c: var(--c-measure); } .cat-general { --c: var(--c-general); }

/* inbox */
.inbox { list-style: none; padding: 0; margin: 0; }
.inbox li { display: flex; gap: .8rem; padding: .7rem .2rem; border-top: 1px solid var(--border); align-items: flex-start; }
.inbox li.clickable { cursor: pointer; border-radius: 8px; }
.inbox li.clickable:hover { background: var(--surface-2); }
.inbox .thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; }
.inbox .body { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.waiting { color: var(--accent); font-weight: 600; font-size: .78rem; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: .8rem; overflow-x: auto; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: .5rem .8rem; font-weight: 500; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .count { font-size: .75em; color: var(--muted); margin-left: .2rem; }

/* subject */
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .4rem 1rem; margin-top: .8rem; }
.facts div span { display: block; font-size: .75rem; color: var(--muted); }
.units { display: flex; flex-wrap: wrap; gap: .4rem; }
.units a { padding: .3rem .7rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

.note { border-left: 4px solid var(--c); }
.note.resolved { opacity: .72; }
.note-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.scope { font-size: .75rem; color: var(--muted); border: 1px dashed var(--border); padding: .05rem .45rem; border-radius: 6px; }
.thread { display: flex; flex-direction: column; gap: .45rem; margin: .8rem 0; }
.msg { max-width: min(78%, 560px); padding: .5rem .7rem; border-radius: 12px; background: var(--in); align-self: flex-start; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg.bot { background: var(--bot); font-size: .9em; }
.msg.comment { background: transparent; border: 1px dashed var(--border); }
.msg .meta { font-size: .72rem; color: var(--muted); margin-bottom: .15rem; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .35rem; margin-top: .4rem; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: zoom-in; display: block; background: var(--surface-2); }
.photos.big { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
[data-note] > .note .photos.big { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .5rem; }
.damage-desc { background: color-mix(in srgb, var(--c-damage) 8%, transparent); border-radius: 8px; padding: .5rem .7rem; }
table { border-collapse: collapse; width: 100%; } th, td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
th { color: var(--muted); font-weight: 500; font-size: .78rem; }
.table-wrap { overflow-x: auto; }
.reply { display: flex; gap: .5rem; align-items: flex-end; }
.reply textarea { min-height: 2.4rem; }
details > summary { cursor: pointer; color: var(--link); font-size: .88rem; list-style: none; } details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: .5rem; }
.resolve { margin-left: auto; }

.file-card { display: grid; grid-template-columns: 180px 1fr; gap: 1rem; }
@media (max-width: 600px) { .file-card { grid-template-columns: 1fr; } }
.preview { aspect-ratio: 4/3; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; border: 1px solid var(--border); }
.preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; cursor: zoom-in; }
.preview .ext { font-weight: 700; font-size: 1.4rem; color: var(--muted); }
.versions { list-style: none; padding: 0; margin: .4rem 0 0; font-size: .88rem; } .versions li { padding: .2rem 0; }

/* simulator */
.phone { max-width: 420px; }
.sms-log { display: flex; flex-direction: column; gap: .4rem; max-height: 60vh; overflow-y: auto; padding: .5rem; background: var(--surface-2); border-radius: 10px; }
.sms-log .msg { max-width: 85%; }

#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 50; padding: 1rem; }
#lightbox img { max-height: 92vh; max-width: 96vw; border-radius: 6px; }
#lightbox .close { position: absolute; top: 1rem; right: 1rem; font-size: 1.6rem; background: none; color: #fff; border: none; }
#toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 8px; z-index: 60; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
