:root {
  --brand: #983030;
  --brand-ink: #fff;
  --bg: #f6f5f3;
  --surface: #fff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e2e0dc;
  --chip: #eeece8;
  --orange: #c26a00;
  --orange-bg: #fff1dc;
  --red: #b42318;
  --red-bg: #fde8e6;
  --green: #1f7a3a;
  --green-bg: #e3f5e8;
  --blue: #1d5fa8;
  --blue-bg: #e4eefa;
  --gray-bg: #ecebe8;
  --link: #983030;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #983030; --bg: #141414; --surface: #1e1e20; --ink: #ececec; --muted: #a0a0a6; --line: #333336;
    --chip: #2a2a2d; --orange: #f0a64a; --orange-bg: #3a2a12; --red: #ff8a80; --red-bg: #3d1c1a;
    --green: #7fd69a; --green-bg: #173322; --blue: #8fbaf0; --blue-bg: #17283d; --gray-bg: #2a2a2d; --link: #DF7F7F;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #983030; --bg: #141414; --surface: #1e1e20; --ink: #ececec; --muted: #a0a0a6; --line: #333336;
  --chip: #2a2a2d; --orange: #f0a64a; --orange-bg: #3a2a12; --red: #ff8a80; --red-bg: #3d1c1a;
  --green: #7fd69a; --green-bg: #173322; --blue: #8fbaf0; --blue-bg: #17283d; --gray-bg: #2a2a2d; --link: #DF7F7F;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--link); }
h1 { font-size: 1.45rem; margin: .2em 0 .5em; }
h2 { font-size: 1.1rem; margin: .2em 0 .6em; }
h3 { font-size: .95rem; margin: 1em 0 .4em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; }

.topbar { background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 52px; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.nav { display: flex; align-items: center; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a, .nav .link { color: #fff; text-decoration: none; padding: 8px 10px; border-radius: 8px; opacity: .92; }
.nav a:hover, .nav .link:hover { background: rgba(255,255,255,.14); opacity: 1; }
.nav .nav-cta { background: #fff; color: var(--brand) !important; font-weight: 600; opacity: 1; }
.nav-spacer { flex: 1; }
.nav form { margin: 0; }
.who { font-size: .85rem; opacity: .85; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.4rem; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.login { width: 100%; max-width: 380px; text-align: center; }
.login.wide { max-width: 520px; text-align: left; }
.login h1 { color: var(--link); margin-bottom: 0; }
.plain { list-style: none; padding: 0; }
.plain li { padding: 4px 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--brand); color: #fff; border: 1px solid var(--brand); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 38px; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn.big { width: 100%; min-height: 48px; font-size: 1.05rem; margin-top: 8px; }
.btn[disabled] { opacity: .6; cursor: progress; }
button.link { background: none; border: 0; font: inherit; color: var(--link); cursor: pointer; padding: 0; }

.flash { display: block; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--green-bg); color: var(--green); text-decoration: none; }
.flash.error { background: var(--red-bg); color: var(--red); }
.flash.warn { background: var(--orange-bg); color: var(--orange); }

.head-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.head-row h1 { margin: 0; flex: 1 1 auto; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 8px 12px; font: inherit; color: var(--ink); cursor: pointer; }
.seg button.on { background: var(--chip); font-weight: 600; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
textarea { min-height: 80px; }
input[type="checkbox"] { width: auto; min-height: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; margin: 8px 0 12px; }
.filters > select, .filters > input { width: auto; min-width: 200px; flex: 1 1 200px; }
.filters details { flex: 1 1 100%; order: 5; }
.filters summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-top: 8px; }
.filter-grid label, .inline { font-size: .85rem; color: var(--muted); }
.inline { display: inline-flex; gap: 6px; align-items: center; min-height: 40px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.chip { background: var(--chip); color: var(--ink); text-decoration: none; padding: 6px 12px; border-radius: 999px; font-size: .88rem; border: 1px solid transparent; }
.chip b { margin-left: 4px; }
.chip.on { border-color: var(--ink); background: var(--surface); }
.summary-line { margin: 4px 0 12px; font-size: .9rem; }

.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--gray-bg); color: var(--muted); white-space: nowrap; }
.badge.big { font-size: .9rem; padding: 4px 12px; }
.badge.urgent { background: var(--red-bg); color: var(--red); }
.st-new-request { background: var(--blue-bg); color: var(--blue); }
.st-assigned, .st-in-progress { background: var(--orange-bg); color: var(--orange); }
.st-on-hold { background: var(--gray-bg); color: var(--muted); }
.st-completed { background: var(--green-bg); color: var(--green); }
.st-cannot-repair, .st-rejected { background: var(--red-bg); color: var(--red); }
.chip.st-new-request, .chip.st-assigned, .chip.st-in-progress, .chip.st-on-hold, .chip.st-completed, .chip.st-cannot-repair, .chip.st-rejected { color: var(--ink); background: var(--chip); }
.chip.on { background: var(--surface); }
.age { font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.age.orange { background: var(--orange-bg); color: var(--orange); }
.age.red { background: var(--red-bg); color: var(--red); }

.tickets { display: flex; flex-direction: column; gap: 8px; }
.ticket { display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.t-photos { display: flex; gap: 6px; flex: none; }
.thumb { position: relative; width: 76px; height: 76px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); padding: 0; background: var(--chip); cursor: zoom-in; display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb span { position: absolute; left: 0; right: 0; bottom: 0; font-size: .68rem; background: rgba(0,0,0,.55); color: #fff; text-align: center; }
.thumb.none { cursor: default; font-size: .7rem; color: var(--muted); text-align: center; padding: 4px; }
.t-main { min-width: 0; flex: 1; }
.t-top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.t-code { font-weight: 700; text-decoration: none; }
.t-summary { display: block; color: var(--ink); text-decoration: none; font-weight: 600; margin: 2px 0; }
.t-meta { display: flex; flex-wrap: wrap; gap: 2px 14px; color: var(--muted); font-size: .85rem; }
.tickets.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tickets.cards .ticket { flex-direction: column; }
.tickets.cards .thumb { width: 100%; height: 150px; flex: 1; }
.tickets.cards .t-photos .thumb.none { height: 150px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 16px 0; }

.detail-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.gallery { display: flex; gap: 8px; flex-wrap: wrap; }
.gallery .thumb { width: 110px; height: 110px; }
.comments { list-style: none; padding: 0; margin: 0 0 12px; }
.comments li { padding: 8px 0; border-top: 1px solid var(--line); }
.comment-form { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.history { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.history li { padding: 6px 0; border-top: 1px solid var(--line); }

.form { max-width: 720px; }
.field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 600; font-size: .9rem; }
.field.req > label::after { content: " *"; color: var(--red); }
.field .err { color: var(--red); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--red); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.previews { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 12px; }
.previews img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.access-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 12px; }

.table-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { border-collapse: collapse; width: 100%; font-size: .88rem; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
.grid td.detail { white-space: normal; min-width: 260px; }
.grid thead th { background: var(--chip); position: sticky; top: 0; }
.grid tfoot td, .grid tfoot th { font-weight: 600; background: var(--chip); }
.grid tr.inactive { opacity: .55; }
.grid tr.denied td { color: var(--red); }
.grid tr.overdue td:first-child { box-shadow: inset 3px 0 var(--red); }
.grid tr.due-soon td:first-child { box-shadow: inset 3px 0 var(--orange); }
.grid .actions { display: flex; gap: 6px; }
.grid .actions form { margin: 0; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 50; display: none; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 110px); border-radius: 6px; }
.lightbox .cap { color: #fff; margin-top: 10px; }
.lightbox .err { color: #fff; }
.lightbox button { position: absolute; background: rgba(255,255,255,.15); color: #fff; border: 0; font-size: 1.6rem; width: 46px; height: 46px; border-radius: 50%; cursor: pointer; }
.lb-close { top: 12px; right: 12px; }
.lb-prev { left: 12px; top: 50%; }
.lb-next { right: 12px; top: 50%; }

@media (max-width: 1000px) {
  .nav-toggle { display: block; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: 8px; }
  body.nav-open .nav { display: flex; }
  .nav-spacer { display: none; }
}
@media (max-width: 760px) {
  .detail-grid, .row2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .thumb { width: 64px; height: 64px; }
  .ticket { flex-direction: column-reverse; }
  .t-photos .thumb { width: 72px; height: 72px; }
  .filters > select, .filters > input { min-width: 0; flex-basis: 100%; }
}
