:root {
  --bg: #161616;
  --bg-panel: #1e1e1e;
  --bg-hover: #262626;
  --border: #2e2e2e;
  --text: #f0f0ee;
  --text-secondary: #a3a3a0;
  --text-tertiary: #707070;
  --accent: #4a7dff;
  --purple-bg: #2a2750; --purple-text: #b6aef0;
  --pink-bg: #3a2030; --pink-text: #f0aac6;
  --coral-bg: #3a2418; --coral-text: #f0a87e;
  --teal-bg: #16332b; --teal-text: #7ed9b8;
  --amber-bg: #3a2c10; --amber-text: #f0c060;
  --red-bg: #3a1818; --red-text: #f08a8a;
  --gray-bg: #2a2a2a; --gray-text: #c0c0c0;
}

* { box-sizing: border-box; }

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

#app { max-width: 96vw; margin: 0 auto; padding: 24px 20px 80px; }
#app:has(.split-layout) { max-width: 98vw; }

.details-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.details-grid .card { margin-bottom: 0; }

.header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.header h1 { font-size: 20px; font-weight: 600; margin: 0; }
.header .subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.header .right { display: flex; align-items: center; gap: 10px; }
.badge-note {
  font-size: 12px; color: var(--text-tertiary); border: 0.5px solid var(--border);
  border-radius: 6px; padding: 4px 10px;
}

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.dash-search-row { margin-bottom: 18px; }
.dash-search-row .form-input { width: 100%; font-size: 14px; padding: 10px 14px; }
.metric-card { background: var(--bg-panel); border-radius: 8px; padding: 14px 16px; }
.metric-card .label { font-size: 12px; color: var(--text-secondary); }
.metric-card .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.metric-card.attention .value { color: var(--red-text); }

.role-section { margin-bottom: 18px; border: 0.5px solid var(--border); border-radius: 10px; overflow: hidden; }
.role-header {
  background: #232323; padding: 12px 16px; display: flex; align-items: center;
  justify-content: space-between; cursor: pointer; user-select: none;
}
.role-header .title { font-weight: 600; font-size: 15px; }
.role-header .count { color: var(--text-secondary); font-size: 13px; margin-left: 8px; }
.role-body { padding: 4px 12px 12px; }
.role-body.collapsed { display: none; }

.status-group { margin: 10px 0; }
.status-group-header {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px;
  cursor: pointer; user-select: none;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.status-group-header .label { font-weight: 500; font-size: 13px; }
.status-group-header .count { color: var(--text-tertiary); font-size: 12px; }
.status-cases.collapsed { display: none; }

.case-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-panel); border: 0.5px solid var(--border); border-radius: 8px;
  padding: 10px 14px; margin: 6px 0; cursor: pointer;
}
.case-row:hover { background: var(--bg-hover); }
.case-row .name { font-weight: 500; }
.case-row .meta { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }
.case-row .right { display: flex; align-items: center; gap: 10px; }

.pill { font-size: 11px; padding: 3px 9px; border-radius: 6px; font-weight: 500; white-space: nowrap; }
.pill.attention { background: var(--red-bg); color: var(--red-text); }
.pill.neutral { background: var(--gray-bg); color: var(--gray-text); }
.pill.new-reply { background: var(--accent); color: #fff; }

/* Case detail page */
.back-link { color: var(--text-secondary); font-size: 13px; cursor: pointer; margin-bottom: 12px; display: inline-block; }
.back-link:hover { color: var(--text); }

.case-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.case-title h2 { margin: 0; font-size: 18px; }

.tabs { display: flex; gap: 4px; border-bottom: 0.5px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 8px 14px; font-size: 13px; color: var(--text-secondary); cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab.disabled { color: var(--text-tertiary); cursor: default; }

.card { background: var(--bg-panel); border: 0.5px solid var(--border); border-radius: 10px; padding: 18px 20px; margin-bottom: 14px; }
.hero-stat .label { font-size: 12px; color: var(--text-secondary); }
.hero-stat .value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.status-badge {
  display: inline-block; background: var(--purple-bg); color: var(--purple-text);
  font-size: 14px; font-weight: 600; padding: 5px 14px; border-radius: 6px;
}
.hero-stat .value .dim { font-size: 13px; color: var(--text-secondary); font-weight: 400; }

.section-label { font-size: 11px; font-weight: 600; letter-spacing: .03em; color: var(--text-tertiary); text-transform: uppercase; margin: 16px 0 6px; }
.section-label-row { display: flex; align-items: center; justify-content: space-between; }
.section-label-row .form-button.small { margin: 0; }

.contact-suggestions {
  position: absolute; left: 134px; right: 0; top: 100%; z-index: 10;
  background: #232323; border: 0.5px solid var(--border); border-radius: 8px;
  max-height: 400px; overflow-y: auto; margin-top: 2px;
}
.contact-suggestion { padding: 8px 12px; font-size: 13px; cursor: pointer; }
.contact-suggestion:hover { background: var(--bg-hover); }
.contact-suggestion .dim { color: var(--text-tertiary); font-size: 12px; }
.section-label:first-child { margin-top: 0; }

table.kv { width: auto; border-collapse: collapse; }
table.kv td { padding: 5px 0; font-size: 13.5px; }
table.kv td.k { color: var(--text-secondary); width: 140px; padding-right: 16px; white-space: nowrap; }
table.kv td.v { text-align: left; font-weight: 500; }
table.kv td.v.dim { color: var(--text-tertiary); font-weight: 400; }
.divider { border-top: 0.5px solid var(--border); margin: 14px 0; }

table.roles { width: 100%; border-collapse: collapse; font-size: 13px; }
table.roles th { text-align: left; color: var(--text-tertiary); font-size: 11px; text-transform: uppercase; padding: 4px 8px; }
table.roles td { padding: 8px 8px; border-top: 0.5px solid var(--border); }

.doc-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-top: 0.5px solid var(--border); font-size: 13.5px; }
.doc-row:first-child { border-top: none; }
.doc-row .fname { color: var(--text-secondary); font-size: 12px; }

.thread-msg { padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; max-width: 80%; font-size: 13.5px; line-height: 1.5; }
.thread-msg.outbound { background: #1f2d4a; margin-left: auto; }
.thread-msg.inbound { background: #232323; }
.thread-msg.system { background: var(--gray-bg); color: var(--gray-text); font-size: 12.5px; max-width: 100%; }
.thread-msg .meta { font-size: 11px; color: var(--text-tertiary); margin-bottom: 3px; }
.attachment-chip { margin-top: 8px; }
.attachment-chip a {
  display: inline-block; font-size: 12px; color: var(--accent); text-decoration: none;
  background: #1a2540; border-radius: 6px; padding: 4px 10px;
}
.attachment-chip a:hover { text-decoration: underline; }

.compose { display: flex; gap: 8px; margin-top: 14px; }
.compose { flex-direction: column; }
.compose textarea {
  flex: 1; background: #232323; border: 0.5px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 12px 14px; font-family: inherit; font-size: 14px; line-height: 1.6;
  resize: vertical; min-height: 420px; width: 100%;
}
.attachment-picker { margin-top: 10px; }
.attachment-picker-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px;
}
.attachment-picker-row label { flex: 1; }
.attachment-picker-row .size { color: var(--text-tertiary); font-size: 12px; }
.attachment-total { font-size: 12.5px; color: var(--text-secondary); margin-top: 8px; }
.attachment-total.over-limit { color: var(--red-text); font-weight: 600; }
.attachment-error { background: var(--red-bg); color: var(--red-text); border-radius: 8px; padding: 10px 14px; margin-top: 10px; font-size: 13px; }
.compose button {
  background: var(--accent); color: white; border: none; border-radius: 8px;
  padding: 10px 18px; font-weight: 500; cursor: pointer; font-size: 13.5px; align-self: flex-start;
}

.form-row { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.form-label { width: 160px; flex-shrink: 0; color: var(--text-secondary); font-size: 15px; }
.form-input {
  flex: 1; min-width: 0; background: #232323; border: 0.5px solid var(--border); border-radius: 6px;
  color: var(--text); padding: 11px 14px; font-family: inherit; font-size: 16px;
}
.form-button {
  background: var(--accent); color: white; border: none; border-radius: 8px;
  padding: 12px 22px; font-weight: 500; cursor: pointer; font-size: 15px; margin-top: 8px;
}
.form-button.small { padding: 5px 10px; font-size: 12.5px; margin-top: 0; margin-left: 8px; }

.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-box {
  background: var(--bg-panel); border: 0.5px solid var(--border); border-radius: 10px;
  padding: 24px 26px; width: 420px; max-width: 90vw;
}
.modal-box .section-label { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .form-button { margin-top: 0; }
.modal-actions .form-button.secondary { background: var(--bg-hover); color: var(--text); }
.form-required { color: var(--red-text); }

.page-thumb-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.page-thumb {
  border: 2px solid var(--border); border-radius: 6px; padding: 4px; cursor: pointer;
  text-align: center; background: #1a1a1a;
}
.page-thumb img { display: block; max-width: 240px; max-height: 300px; }
.page-thumb-label { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }
.page-thumb.selected { border-color: var(--accent); background: #1f2d4a; }
/* The differences page-picker gets larger thumbnails so the line items are
   readable while choosing pages - scoped to that modal so the New Appraisal
   picker keeps its compact size. */
#diff-picker-overlay .page-thumb img { max-width: 360px; max-height: 470px; }
#diff-picker-overlay .page-thumb-label { font-size: 13px; }

.split-layout { display: flex; gap: 24px; align-items: flex-start; }
.split-left { flex: 0 0 38%; min-width: 0; min-height: 78vh; }
.split-left .card { min-height: 78vh; padding: 28px 32px; }
.split-left .section-label { font-size: 14px; margin-bottom: 18px; }
.split-right { flex: 1; min-width: 0; position: sticky; top: 16px; max-height: 95vh; overflow-y: auto; }
.large-page-preview { width: 100%; border-radius: 6px; border: 0.5px solid var(--border); }

.split-layout.doa-layout .split-left { flex: 0 0 50%; min-height: 0; }
.split-layout.doa-layout .split-left .card { min-height: 0; padding: 18px 20px; }
.split-layout.doa-layout .split-right { min-height: 90vh; }

.split-layout.homeowner-split .split-left,
.split-layout.homeowner-split .split-right { flex: 0 0 50%; min-height: 0; position: static; max-height: none; overflow-y: visible; }
.split-layout.homeowner-split .split-left .card,
.split-layout.homeowner-split .split-right .card { min-height: 0; padding: 18px 20px; }
.split-layout.homeowner-split .panel-title { font-weight: 600; font-size: 14px; margin-bottom: 10px; color: var(--text-secondary); }

.upload-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.upload-slot {
  background: var(--bg-panel); border: 0.5px solid var(--border); border-radius: 10px;
  padding: 16px 18px;
}
.upload-slot.empty { cursor: pointer; border-style: dashed; transition: border-color 0.15s; }
.upload-slot.empty:hover { border-color: var(--accent); }
.upload-slot.empty .placeholder-tab { padding: 14px 0; }
.upload-slot .doc-row { border-top: none; padding: 6px 0; }
.upload-slot.dragover { border-color: var(--accent); background: #1f2d4a; }

.photo-folder-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.photo-folder {
  position: relative;
  background: var(--bg-panel); border: 0.5px solid var(--border); border-radius: 10px;
  padding: 18px 12px; text-align: center; cursor: pointer; transition: border-color 0.15s;
}
.photo-folder:hover { border-color: var(--accent); }
.photo-folder-edit {
  position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,0.65); color: #fff; border: none; cursor: pointer; font-size: 11px; line-height: 1;
}
.doc-label-edit {
  background: none; border: none; color: var(--text-tertiary); cursor: pointer;
  font-size: 11px; margin-left: 6px; padding: 0; vertical-align: middle;
}
.doc-label-edit:hover { color: var(--accent); }
.role-remove { background: none; border: none; color: var(--text-tertiary); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.role-remove:hover { color: #b91c1c; }
.review-box { width: 92vw; max-width: 1150px; }
.review-split { display: flex; gap: 18px; margin-top: 14px; }
.review-pdf { flex: 1.5; min-width: 0; }
.review-pdf iframe { width: 100%; height: 72vh; border: 0.5px solid var(--border); border-radius: 8px; background: #fff; }
.review-form { flex: 1; min-width: 280px; }
@media (max-width: 820px) { .review-split { flex-direction: column; } .review-pdf iframe { height: 45vh; } }
.ar-suggestions { border: 0.5px solid var(--border); border-radius: 8px; margin: -4px 0 10px; max-height: 190px; overflow-y: auto; background: var(--bg-panel); }
.ar-suggestion { padding: 7px 10px; cursor: pointer; font-size: 13px; border-bottom: 0.5px solid var(--border); }
.ar-suggestion:last-child { border-bottom: none; }
.ar-suggestion:hover { background: var(--accent); color: #fff; }
.ar-suggestion:hover .dim { color: #fff; }
.doa-attachment-link { color: #ffcf33; font-weight: 700; text-decoration: underline; }
.doa-attachment-link:hover { color: #ffe066; }
.photo-folder-edit:hover { background: var(--accent); }
/* Rename/delete buttons stay out of the way until the folder tile is hovered */
.photo-folder .photo-folder-edit, .photo-folder .photo-remove { display: none; }
.photo-folder:hover .photo-folder-edit, .photo-folder:hover .photo-remove { display: block; }
.photo-folder-icon { font-size: 28px; margin-bottom: 6px; }
.photo-folder-name { font-size: 13px; font-weight: 600; }
.photo-folder-count { font-size: 11.5px; color: var(--text-tertiary); margin-top: 2px; }

.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px;
  border: 0.5px dashed var(--border); border-radius: 10px; padding: 12px; min-height: 80px;
}
.photo-grid.dragover { border-color: var(--accent); background: #1f2d4a; }
.photo-thumb { position: relative; }
.photo-thumb img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; display: block; }
.photo-thumb-name { font-size: 10.5px; color: var(--text-tertiary); margin-top: 3px; word-break: break-all; }
.photo-remove {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,0.65); color: #fff; border: none; cursor: pointer; font-size: 13px; line-height: 1;
}
.photo-remove:hover { background: #b91c1c; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 40px 20px;
  text-align: center; color: var(--text-secondary); cursor: pointer; font-size: 14px;
  margin-bottom: 12px; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.dragover { border-color: var(--accent); background: #1f2d4a; color: var(--text); }

.placeholder-tab { color: var(--text-tertiary); font-size: 13.5px; padding: 30px 0; text-align: center; }
.note { font-size: 12px; color: var(--text-tertiary); margin-top: 10px; }

select.status-select {
  background: #232323; color: var(--text); border: 0.5px solid var(--border);
  border-radius: 6px; padding: 6px 10px; font-size: 13px;
}

/* Final Report review form (AI-drafted, editable before PDF) */
.fr-section-head {
  font-size: 12px; font-weight: 600; color: var(--accent);
  text-transform: uppercase; letter-spacing: .04em;
  margin: 16px 0 6px; padding-bottom: 4px; border-bottom: 0.5px solid var(--border);
}
.fr-field { display: block; margin-bottom: 9px; }
.fr-field > span { display: block; font-size: 12px; color: var(--text-tertiary); margin-bottom: 3px; }
.fr-field input, .fr-field textarea {
  width: 100%; box-sizing: border-box;
  background: #232323; color: var(--text); border: 0.5px solid var(--border);
  border-radius: 6px; padding: 7px 10px; font-size: 13px; font-family: inherit; line-height: 1.45;
}
.fr-field textarea { resize: vertical; }

/* Auth screens (login / first-run set password) */
.auth-wrap { min-height: 78vh; display: flex; align-items: center; justify-content: center; padding: 40px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: #232323;
  border: 0.5px solid var(--border); border-radius: 12px; padding: 28px 26px;
}
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-card .subtitle { color: var(--text-tertiary); font-size: 13px; margin: 0 0 18px; }
.auth-card .form-label { display: block; margin: 12px 0 4px; font-size: 12px; color: var(--text-tertiary); }
.auth-card .form-input { width: 100%; box-sizing: border-box; }
.auth-card .form-button { width: 100%; margin-top: 18px; }
.auth-card .attachment-error { margin-bottom: 10px; }

/* --- Phone layout ------------------------------------------------------- */
/* The page itself must never be wider than the screen - inner containers
   (.tabs etc.) keep their own horizontal scrolling. */
html, body { max-width: 100vw; overflow-x: hidden; }
@media (max-width: 640px) {
  body { padding: 12px; }
  .header { flex-wrap: wrap; gap: 10px; }
  .header .right { flex-wrap: wrap; row-gap: 8px; justify-content: flex-start; }
  .card { padding: 12px; }
}
