:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1f2a2e;
  --muted: #5f6b70;
  --border: #e3dfd6;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #e6f4f1;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff6dd;
  --info-soft: #e8f1fb;
  --info: #1d4f91;
  --success-soft: #e7f5ec;
  --success: #17663a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 42, 46, 0.06), 0 2px 8px rgba(31, 42, 46, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181a;
    --surface: #1b2326;
    --text: #e6ecee;
    --muted: #9aa8ad;
    --border: #2c3a3e;
    --primary: #2bb3a3;
    --primary-hover: #4cc7b8;
    --primary-soft: #16312e;
    --danger: #f2877d;
    --danger-soft: #3a1d1b;
    --warn: #f0c062;
    --warn-soft: #33290f;
    --info-soft: #172a40;
    --info: #9cc3f5;
    --success-soft: #15301f;
    --success: #7fd6a0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }
.card > h2:first-child, .card > form > h2:first-child { margin-top: 0; }
h3 { font-size: 1rem; margin: 0; }
img { max-width: 100%; }

/* Layout */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0.6rem 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.nav { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }
.nav a, .nav .linklike {
  color: var(--muted); text-decoration: none; padding: 0.4rem 0.65rem; border-radius: 8px; font-size: 0.95rem;
}
.nav a:hover, .nav .linklike:hover { color: var(--text); background: var(--bg); }
.nav a.active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.dot {
  display: inline-block; min-width: 1.3em; padding: 0 0.35em; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 0.75rem; font-weight: 700; text-align: center; line-height: 1.3em;
}
.container { max-width: 1080px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 2rem 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.narrow { max-width: 440px; margin: 2rem auto; }
.center { text-align: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; align-items: start; }
.grid2.tight { gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } .layout aside { order: -1; } }
.sticky { position: sticky; top: 1rem; }
@media (max-width: 860px) { .sticky { position: static; } }

.hero { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.hero-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.crumbs { margin: 0 0 0.75rem; font-size: 0.9rem; }
.crumbs a { text-decoration: none; }
.mt { margin-top: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 1.25rem; text-align: center; }
.plain { list-style: none; padding: 0; margin: 0; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 0.9rem; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.92rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.82rem; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem; width: 100%;
}
input[readonly] { background: var(--bg); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary);
}
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
legend { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.4rem; padding: 0; }
.check { flex-direction: row; align-items: center; gap: 0.6rem; font-weight: 400; }
.check input { width: auto; margin: 0; }
.radio-card {
  flex-direction: row; align-items: flex-start; gap: 0.7rem; font-weight: 400;
  border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.85rem; cursor: pointer;
}
.radio-card input { width: auto; margin-top: 0.3rem; }
.radio-card span { display: flex; flex-direction: column; }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.recipients { margin-left: 1.6rem; display: flex; flex-direction: column; gap: 0.35rem; }
.recipients[hidden] { display: none; }
.copy-row { display: flex; gap: 0.5rem; }
.copy-row input { font-size: 0.85rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600; font-size: 0.95rem; text-decoration: none; cursor: pointer;
  padding: 0.6rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); align-self: flex-start;
}
.btn:hover { border-color: var(--muted); color: var(--text); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; color: var(--primary); padding: 0; }
.linklike.danger { color: var(--danger); }
form.inline { display: inline; }
.chip {
  font: inherit; font-size: 0.82rem; padding: 0.25rem 0.65rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.templates { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }

/* Alerts & badges */
.alert { border-radius: 10px; padding: 0.75rem 1rem; margin-bottom: 1rem; font-size: 0.95rem; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--info); }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 0.15rem 0.55rem; border-radius: 999px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.status-new { background: var(--info-soft); color: var(--info); border-color: transparent; }
.status-in_progress { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.status-scheduled { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.status-resolved { background: var(--success-soft); color: var(--success); border-color: transparent; }
.urgency-emergency { background: var(--danger); color: #fff; border-color: transparent; }
.urgency-urgent { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* Lists */
.rows { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.row {
  display: flex; justify-content: space-between; gap: 1rem; padding: 0.85rem 1rem; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.row:hover { border-color: var(--primary); color: var(--text); }
.row.unread { border-left: 4px solid var(--primary); }
.row-main { min-width: 0; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 0.4rem; }
.row-meta { color: var(--muted); font-size: 0.87rem; overflow: hidden; }
.row-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; flex-shrink: 0; }
.row-side > div:first-child { display: flex; gap: 0.25rem; flex-wrap: wrap; justify-content: flex-end; }
.new-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }
.clip { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
@media (max-width: 560px) {
  .row { flex-direction: column; gap: 0.4rem; }
  .row-side { flex-direction: row; justify-content: space-between; align-items: center; text-align: left; }
}

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; display: flex; flex-direction: column; }
.stat .num { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat span:last-child { color: var(--muted); font-size: 0.85rem; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } .stat { padding: 0.7rem 0.85rem; } }
.stat.alarm { border-color: var(--danger); background: var(--danger-soft); }
.stat.alarm .num { color: var(--danger); }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: 0.5rem 0.9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: 0.9rem; }
.facts dd { margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
tr.inactive td { color: var(--muted); }

.unit { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.unit summary { cursor: pointer; }
.row-actions { display: flex; gap: 0.5rem; }

/* Ticket page */
.ticket-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.ticket-head h1 { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.timeline li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 1rem; }
.timeline li.from-landlord { border-left: 4px solid var(--primary); }
.timeline li.status { background: var(--bg); }
.timeline p { margin: 0.4rem 0 0; }
.meta { font-size: 0.82rem; color: var(--muted); }
.status-line { margin-top: 0.3rem; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.5rem; margin-top: 0.75rem; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.file-chip { font-size: 0.85rem; padding: 0.5rem; border: 1px solid var(--border); border-radius: 8px; overflow-wrap: anywhere; }
.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 0.4rem; }
.previews:empty { display: none; }
.previews img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }

/* Messages */
.chat { list-style: none; padding: 0; margin: 1rem 0; display: flex; flex-direction: column; gap: 0.8rem; }
.chat li { display: flex; flex-direction: column; max-width: 80%; }
.chat li.mine { align-self: flex-end; align-items: flex-end; }
.chat li.theirs { align-self: flex-start; }
.bubble { padding: 0.65rem 0.9rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); margin-top: 0.2rem; }
.mine .bubble { background: var(--primary); color: #fff; border-color: var(--primary); }
@media (max-width: 560px) { .chat li { max-width: 95%; } }
