/* Mobile-first: owners see a phone layout with a bottom tab bar; office staff on wide screens get a sidebar. */
:root {
  /* Brand palette from the Comunidad Connect design: harbour blue, sun ochre accent, mist neutrals. Light only. */
  --bg: #F5F6F8; --surface: #FFFFFF; --surface-2: #EEF0F3; --ink: #14202E; --muted: #5B6878; --line: #E1E5EB;
  --accent: #18406B; --accent-ink: #FFFFFF; --accent-soft: #EEF3F9; --ochre: #E2A93B;
  --ok: #1E5B38; --ok-soft: #E8F3EC; --warn: #7A4E00; --warn-soft: #FBF1DC; --bad: #B42318; --bad-soft: #FBEAEA;
  --radius: 14px; --font: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --font-display: Manrope, "Noto Sans", -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
/* The page itself never scrolls: #app (sign-in, setup) or .main (inside the app) does, so the header and the
   bottom menu stay put and nothing bounces away on iPhone. */
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
#app { height: 100%; overflow-y: auto; overscroll-behavior: contain; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
img, video { max-width: 100%; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; margin: 0 0 8px; text-wrap: balance; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); } .small { font-size: 0.86rem; } .mono { font-family: ui-monospace, Menlo, monospace; font-size: 0.82rem; }
[hidden] { display: none !important; }

/* shell */
.shell { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.topbar { flex: none; position: relative; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: calc(var(--safe-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 10px; }
.brand { flex: none; display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 800; white-space: nowrap; }
/* The logo never shrinks, however long the community name or the staff language picker. */
.brand img { width: 36px; height: 36px; flex: none; }
/* Name next to the logo everywhere, as in the design: "Comunidad" bold, "Connect" lighter in harbour blue. */
/* Lockup from the design: two lines, "Comunidad" bold in ink, "Connect" regular in harbour blue. */
.brand { gap: 10px; }
.brand-name { display: flex; flex-direction: column; font-size: 17px; line-height: 1.05; letter-spacing: -0.01em; color: var(--ink); }
.brand-connect { font-weight: 500; color: var(--accent); }
.pick { display: contents; }
.pick-icon { display: none; }
.pick.solo select { pointer-events: auto; }
/* Phones: community and language pickers become small icons beside the bell. */
@media (max-width: 599px) {
  .topbar { gap: 4px; }
  .brand { margin-right: auto; }
  .topbar > .spacer { display: none; }
  .pick { display: inline-grid; position: relative; width: 40px; height: 40px; place-items: center; border-radius: 10px; color: var(--ink); flex: none; }
  .pick.solo { display: none; }
  .pick-icon { display: inline-flex; }
  .pick select { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; opacity: 0; font-size: 16px; padding: 0; border: 0; }
  .pick:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
  .iconbtn { width: 40px; height: 40px; display: inline-grid; place-items: center; }
}
button, a, select { -webkit-tap-highlight-color: transparent; }
.topbar select { max-width: 52vw; min-width: 0; flex: 1 1 auto; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 7px 10px; }
.spacer { flex: 1; }
.iconbtn { position: relative; border: 0; background: transparent; padding: 6px; border-radius: 10px; cursor: pointer; color: var(--ink); }
.iconbtn:focus-visible, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.badge { position: absolute; top: 0; right: 0; min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 4px; }
.main { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left)) 24px; }
.tabbar { flex: none; position: relative; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + var(--safe-bottom)); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: transparent; color: var(--muted); font-size: 11px; padding: 6px 2px; border-radius: 10px; cursor: pointer; position: relative; }
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }
.tab .badge { right: 22%; }
.tab.report svg { background: var(--accent); color: var(--accent-ink); border-radius: 50%; padding: 4px; width: 32px; height: 32px; margin-top: -6px; }

.sidebar { display: none; }
@media (min-width: 980px) {
  .shell.staff { display: grid; grid-template: "top top" auto "side main" minmax(0, 1fr) / 230px minmax(0, 1fr); }
  .shell.staff .topbar { grid-area: top; }
  .shell.staff .sidebar { grid-area: side; display: flex; flex-direction: column; gap: 2px; padding: 16px 10px; border-right: 1px solid var(--line); background: var(--surface); overflow: auto; }
  .shell.staff .sidebar button { text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 10px; cursor: pointer; color: var(--ink); display: flex; gap: 10px; align-items: center; }
  .shell.staff .sidebar button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .shell.staff .sidebar svg { width: 20px; height: 20px; }
  .shell.staff .tabbar { display: none; }
  .shell.staff .main { grid-area: main; max-width: none; padding: 20px max(24px, calc((100% - 1100px) / 2)) 48px; }
}

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; justify-content: center; }
a.btn { text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.btn.danger { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); padding-inline: 6px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.block { width: 100%; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=month], input[type=number], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; width: 100%; font-weight: 400; }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.95rem; }
.check input { margin-top: 4px; width: 18px; height: 18px; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.pill.open { background: var(--accent-soft); color: var(--accent); }
.pill.in_progress { background: var(--warn-soft); color: var(--warn); }
.pill.waiting { background: var(--surface-2); color: var(--muted); }
.pill.resolved, .pill.closed { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.band-urgent { background: var(--bad); color: #fff; }
.pill.band-high { background: var(--bad-soft); color: var(--bad); }
.pill.band-medium { background: var(--warn-soft); color: var(--warn); }

.issue-card { display: flex; flex-direction: column; gap: 6px; cursor: pointer; text-align: left; width: 100%; border-left: 4px solid var(--line); }
.issue-card.safety { border-left-color: var(--bad); }
.issue-card.overdue { border-left-color: var(--warn); }
.issue-card:hover { border-color: var(--accent); }
.issue-card .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 0.82rem; color: var(--muted); }
.reporters { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--ink); }

.similar { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: var(--radius); padding: 14px; }
.similar .card { background: var(--surface); }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.msg.mine { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.msg.staff { border-left: 3px solid var(--accent); }
.msg.internal { background: var(--warn-soft); border-color: var(--warn); }
.msg .who { font-size: 0.78rem; font-weight: 700; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.event { align-self: center; font-size: 0.82rem; color: var(--muted); text-align: center; max-width: 92%; }
.event.escalation { color: var(--bad); font-weight: 600; }
.orig-toggle { font-size: 0.78rem; border: 0; background: none; color: var(--accent); padding: 0; cursor: pointer; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; height: 44px; }
.media { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.media img, .media video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.media a.file { display: grid; place-items: center; aspect-ratio: 1; border-radius: 10px; background: var(--surface-2); font-size: 0.8rem; padding: 6px; text-align: center; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; text-align: left; }
.kpi b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.kpi.alert b { color: var(--bad); }
.table-wrap { overflow-x: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; }
.main { overflow-x: hidden; }
/* Phones: every table becomes a list of cards, so nothing scrolls sideways. */
@media (max-width: 699px) {
  .table-wrap { border: 0; background: transparent; border-radius: 0; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; }
  .table-wrap td { border: 0; padding: 4px 0; display: grid; grid-template-columns: minmax(0, 42%) minmax(0, 1fr); column-gap: 12px; align-items: center; text-align: right; overflow-wrap: break-word; }
  .table-wrap td > * { grid-column: 2; justify-self: end; }
  .table-wrap td::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 6; text-align: left; font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  .table-wrap td[data-label=""] { display: block; text-align: left; }
  .table-wrap td[data-label=""]::before { display: none; }
  .table-wrap td[data-label=""] > * { justify-self: start; }
  .table-wrap td:first-child { font-weight: 600; }
  .table-wrap td:empty { display: none; }
  .table-wrap .row { justify-content: flex-end; }
  .table-wrap td[data-label=""] .row { justify-content: flex-start; }
  .table-wrap td input:not([type=checkbox]), .table-wrap td select { max-width: 60%; }
}

.progress { list-style: none; margin: 4px 0 0; padding: 0; display: flex; gap: 6px; }
.progress .step { flex: 1; font-size: 0.8rem; font-weight: 600; color: var(--muted); padding-top: 8px; border-top: 4px solid var(--line); }
.progress .step.done { border-top-color: var(--ok); color: var(--ok); }
.progress .step.current { border-top-color: var(--accent); color: var(--accent); }
.next { font-size: 1.02rem; margin: 0; }
.next.warn { color: var(--warn); }
@media (max-width: 340px) { .brand-name { display: none; } }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 0.86rem; }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.list-item { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.chatbox { display: flex; flex-direction: column; height: calc(100vh - 220px - var(--safe-bottom)); min-height: 320px; }
.chatbox .timeline { flex: 1; overflow-y: auto; padding: 4px 2px 12px; }
.drawer { position: fixed; inset: 0; z-index: 40; background: rgba(10, 15, 25, .45); display: flex; justify-content: flex-end; }
.drawer .panel { width: min(420px, 100%); height: 100%; background: var(--bg); overflow: auto; padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px); }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(10, 15, 25, .45); display: grid; place-items: end center; }
.modal .panel { width: min(560px, 100%); background: var(--surface); border-radius: 18px 18px 0 0; padding: 20px 16px calc(var(--safe-bottom) + 20px); }
@media (min-width: 640px) { .modal { place-items: center; } .modal .panel { border-radius: 18px; } }
#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: calc(100% - 32px); font-size: 0.92rem; }
.login { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-top) + 40px) 16px 40px; }
.login .logo { width: 56px; height: 56px; }
.login-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.or-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.or-divider::before, .or-divider::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.passkey-btn { min-height: 48px; font-size: 16px; }
.login-top .login-lang { width: auto; min-width: 140px; }
.demo-accounts button { text-align: left; }
@media (prefers-reduced-motion: no-preference) { .card, .btn, .kpi { transition: border-color .15s, background .15s; } }

/* report: ten issue-type tiles */
.type-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.type-tile { min-height: 76px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px; padding: 10px 12px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); text-align: left; cursor: pointer; font-size: 1rem; line-height: 1.25; }
.type-tile:hover, .type-tile:focus-visible { border-color: var(--accent); outline: none; }
.type-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.type-tile.urgent .type-icon { background: var(--bad-soft); color: var(--bad); }
@media (min-width: 700px) { .type-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

/* top bar language picker (office) */
.lang-picker { flex: 0 0 auto !important; max-width: 140px !important; }

/* analytics */
.small-btn { padding: 6px 10px; font-size: 0.85rem; min-height: 36px; }
.legend::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend.created::before { background: var(--accent); }
.legend.resolved::before { background: var(--ok); }
.bar-chart { display: grid; gap: 6px; height: 200px; align-items: end; border-bottom: 1px solid var(--line); }
.bar-col { height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; border: 0; background: transparent; padding: 0; cursor: pointer; border-radius: 6px; }
.bar-col:hover, .bar-col:focus-visible { background: var(--surface-2); outline: none; }
.bar { width: 40%; min-height: 2px; border-radius: 4px 4px 0 0; }
.bar.created { background: var(--accent); }
.bar.resolved { background: var(--ok); }
.bar-labels { display: grid; gap: 6px; font-size: 0.75rem; color: var(--muted); text-align: center; }
.grid-wide { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 12px; }
.hbar { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) 2.5rem; gap: 10px; align-items: center; min-height: 34px; border: 0; background: transparent; color: var(--ink); text-align: left; cursor: pointer; border-radius: 8px; padding: 2px 4px; }
.hbar:hover, .hbar:focus-visible { background: var(--surface-2); outline: none; }
.hbar b { text-align: right; }
.hbar-track { height: 12px; border-radius: 6px; background: var(--surface-2); }
.hbar-track span { display: block; height: 12px; border-radius: 6px; background: var(--accent); }
.list-item.linkish { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; color: inherit; }
.good { color: var(--ok); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }
.small-btn svg { width: 18px; height: 18px; }

/* owner home: fixed and closed issues collapsed into one group */
.done-group > summary { list-style: none; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); cursor: pointer; }
.done-group > summary::-webkit-details-marker { display: none; }
.done-group > summary::after { content: "›"; display: inline-block; margin-left: auto; font-size: 1.4rem; color: var(--muted); transition: transform .15s; }
.done-group[open] > summary::after { transform: rotate(90deg); }
.done-group[open] > summary { margin-bottom: 12px; }

/* sign out at the bottom of the office side menu */
.shell.staff .sidebar .sign-out { margin-top: auto; color: var(--muted); border-top: 1px solid var(--line); border-radius: 0; padding-top: 14px; }
.sidebar .sign-out { display: none; }
@media (min-width: 980px) { .shell.staff .sidebar .sign-out { display: flex; } }
