:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --text: #1c2321;
  --muted: #667066;
  --border: #e2e5e0;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --accent-soft: #e4f0ee;
  --tenant-bubble: #e8f4f2;
  --assistant-bubble: #ffffff;
  --danger: #b91c1c;
  --danger-bg: #fdecec;
  --warn-bg: #fff7e6;
  --warn-text: #92600a;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --surface: #1d2325;
    --text: #e7ece9;
    --muted: #93a19a;
    --border: #2b3234;
    --accent: #2dd4bf;
    --accent-contrast: #06201d;
    --accent-soft: #17302c;
    --tenant-bubble: #22302d;
    --assistant-bubble: #232a2c;
    --danger: #f87171;
    --danger-bg: #2a1616;
    --warn-bg: #2a220f;
    --warn-text: #f0c96a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header.topbar {
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 5;
}

header.topbar h1 {
  font-size: 16px;
  margin: 0;
}

header.topbar .tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

select, input[type="text"], textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-contrast);
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-wrap {
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px;
  gap: 10px;
}

.bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.bubble.tenant {
  align-self: flex-end;
  background: var(--tenant-bubble);
  border-bottom-right-radius: 3px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.bubble img {
  display: block;
  max-width: 100%;
  border-radius: 8px;
  margin-bottom: 6px;
}

.decision-card {
  margin: 0 12px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.decision-card summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.decision-card .body {
  padding: 0 14px 14px;
  font-size: 13.5px;
}

.decision-card .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}

.decision-card .row:last-child { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge.emergency { background: var(--danger-bg); color: var(--danger); }
.badge.tenant { background: var(--warn-bg); color: var(--warn-text); }
.badge.landlord { background: #e6f0ff; color: #1d4ed8; }
.badge.shared { background: #f1e6ff; color: #7c3aed; }
.badge.pending { background: var(--border); color: var(--muted); }

.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  bottom: 0;
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 120px;
}

.composer .attach {
  display: flex;
  align-items: center;
}

.composer .attach input { display: none; }
.composer .attach label,
.composer #micBtn {
  margin: 0;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 18px;
  background: transparent;
  color: var(--text);
}

.composer #micBtn.recording {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.empty {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 40px 20px;
}

/* Owner portal */
nav.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px 0;
}

nav.tabs button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

nav.tabs button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.list-item .top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.list-item .title {
  font-weight: 700;
  font-size: 14.5px;
}

.list-item .meta {
  font-size: 12.5px;
  color: var(--muted);
}

.detail-back {
  padding: 12px;
}

.field-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.field-row > div { flex: 1; }

.transcript {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.pill-select {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-select button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-weight: 600;
  font-size: 13px;
}

.pill-select button.selected {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

/* ---- Portal shell (owner + vendor): dark sidebar + main content ---- */

:root {
  --sb-bg: #14181a;
  --sb-text: #e7ece9;
  --sb-muted: #8b9a93;
  --sb-active-bg: #1f2725;
  --sb-border: #262e2b;
}

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sb-bg);
  color: var(--sb-text);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  gap: 18px;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.sidebar .brand .mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  flex-shrink: 0;
}

.sidebar .brand .name {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 15px;
}

.sidebar .portal-label {
  font-size: 11.5px;
  color: var(--sb-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 6px;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  color: var(--sb-text);
  border: none;
  border-left: 3px solid transparent;
  border-radius: 0 8px 8px 0;
  padding: 9px 10px 9px 9px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}

.sidebar nav button.active {
  background: var(--sb-active-bg);
  border-left-color: var(--accent);
  font-weight: 700;
}

.sidebar nav button .count {
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}

.sidebar .vendor-id {
  margin-top: auto;
  padding: 10px 6px 0;
  border-top: 1px solid var(--sb-border);
  font-size: 12.5px;
  color: var(--sb-muted);
}

.sidebar .vendor-id strong {
  display: block;
  color: var(--sb-text);
  font-size: 13.5px;
}

.shell-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 20px 4px;
  flex-wrap: wrap;
}

.page-head h2 {
  margin: 0 0 4px;
  font-size: 21px;
}

.page-head .sub {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.lang-toggle button {
  background: var(--surface);
  color: var(--muted);
  border: none;
  border-radius: 0;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
}

.lang-toggle button.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.page-body { padding: 4px 20px 32px; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 10px 12px;
    gap: 14px;
    overflow-x: auto;
  }
  .sidebar .portal-label { display: none; }
  .sidebar nav { flex-direction: row; }
  .sidebar nav button { border-left: none; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0; white-space: nowrap; }
  .sidebar nav button.active { border-bottom-color: var(--accent); }
  .sidebar .vendor-id { margin-top: 0; padding: 0 0 0 10px; border-top: none; border-left: 1px solid var(--sb-border); }
}

/* Filter pills with counts (Inbox / Jobs) */
.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 10px 0 16px;
}

.filter-pills button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
}

.filter-pills button .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.filter-pills button.active .n { color: var(--accent-contrast); opacity: 0.85; }

.filter-pills button.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Stepper */
.stepper {
  margin: 6px 0 18px;
}

.stepper .labels {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.stepper .labels .done { color: var(--text); font-weight: 700; }

.stepper .track {
  display: flex;
  gap: 4px;
}

.stepper .track span {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
}

.stepper .track span.done { background: var(--accent); }

.stepper .track span.emergency { background: var(--danger); }

/* Evidence-beside-decision ticket layout */
.evidence-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px) {
  .evidence-grid { grid-template-columns: 1fr; }
}

.decision-panel {
  position: sticky;
  top: 16px;
}

.who-pays {
  margin: 4px 0 14px;
}

.who-pays .labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.who-pays .bar {
  display: flex;
  gap: 3px;
  cursor: pointer;
}

.who-pays .bar .seg {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
}

.who-pays .bar .seg.fill { background: var(--accent); }

.who-pays .call {
  font-size: 20px;
  font-weight: 700;
  margin: 10px 0 2px;
}

.stat-row {
  display: flex;
  gap: 24px;
  margin: 10px 0 14px;
}

.stat-row .stat .k {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 2px;
}

.stat-row .stat .v {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cap-bar {
  margin: 10px 0 14px;
}

.cap-bar .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

.cap-bar .bar {
  display: flex;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cap-bar .bar .cap {
  background: var(--warn-bg);
  color: var(--warn-text);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
}

.cap-bar .bar .rest {
  background: var(--accent-soft, var(--tenant-bubble));
  color: var(--accent);
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reasoning-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  margin: 0 0 14px;
}

.citation {
  font-size: 12px;
  color: var(--muted);
  margin: -10px 0 14px;
}

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }

table.data th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

table.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }

.list-detail {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 760px) {
  .list-detail { grid-template-columns: 1fr; }
}

.list-detail .list-col { display: flex; flex-direction: column; gap: 8px; }

.list-detail .list-item { margin: 0; cursor: pointer; }
.list-detail .list-item.active { border-color: var(--accent); }

/* Quick-reply chips (mirrors WhatsApp interactive buttons in the simulator) */
.quick-replies {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 4px 0 4px 4px;
}

.quick-replies button {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
}
