/* HostViewApp Customer Portal — design system */
:root {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-elev: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-dim: #475569;
  --text-muted: #94a3b8;
  --brand: #0f172a;
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --shadow-md: 0 4px 6px -1px rgba(15,23,42,.1), 0 2px 4px -2px rgba(15,23,42,.08);
  --shadow-lg: 0 20px 25px -5px rgba(15,23,42,.15);
  --radius: 12px;
  --radius-sm: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, .btn {
  font: inherit;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 500;
  min-height: 40px;
  transition: all .15s;
}
button:hover, .btn:hover { background: var(--bg-elev); border-color: var(--accent); }
button.primary, .btn.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
button.primary:hover, .btn.primary:hover { background: #1e293b; }
button.accent, .btn.accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.accent:hover, .btn.accent:hover { background: var(--accent-dark); }
button.block { width: 100%; }
button.lg { padding: 14px 22px; font-size: 15px; min-height: 48px; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, textarea, select {
  font: inherit;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: auto;
  appearance: auto;
  width: auto;
  padding: 0;
  border-radius: 0;
  vertical-align: middle;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; font-weight: 500; }

/* ----- LOGIN ----- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #e0f2fe 0%, #f8fafc 100%);
}
.auth-card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  width: 100%;
  max-width: 420px;
}
.auth-card .logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 24px;
}
.logo-mark {
  width: 36px; height: 36px;
  background: var(--brand); color: #fff;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
}
.auth-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}
.auth-card .subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 24px;
}
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card .error { color: var(--danger); font-size: 13px; min-height: 18px; }
.auth-card .alt-link {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
}

/* ----- APP SHELL ----- */
.app { min-height: 100vh; }
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px;
}
.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
}
.topbar nav a.active { background: var(--bg-elev); color: var(--text); }
.topbar nav a:hover { color: var(--text); text-decoration: none; }
.topbar .right { display: flex; align-items: center; gap: 8px; }
.content { padding: 24px; max-width: 1100px; margin: 0 auto; }

/* ----- DASHBOARD CARDS ----- */
.welcome {
  margin-bottom: 24px;
}
.welcome h1 {
  font-size: 26px;
  margin: 0 0 4px;
  font-weight: 800;
}
.welcome .sub { color: var(--text-dim); font-size: 14px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.stat-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  font-weight: 600;
}
.stat-card .value {
  font-size: 26px;
  font-weight: 800;
  margin-top: 4px;
}
.stat-card .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin: 28px 0 12px;
}
.section-head h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}
.section-head a { font-size: 13px; }

/* ----- LIST CARDS ----- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all .15s;
}
.list-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.list-card .head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.list-card .name { font-weight: 700; font-size: 15px; }
.list-card .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--bg-elev);
  color: var(--text-dim);
}
.badge.scheduled { background: #fef3c7; color: #92400e; }
.badge.in_progress, .badge.in_transit, .badge.on_site { background: #dbeafe; color: #1e40af; }
.badge.completed { background: #dcfce7; color: #166534; }
.badge.invoiced { background: #f3e8ff; color: #6b21a8; }
.badge.paid { background: #dcfce7; color: #166534; }
.badge.cancelled { background: #f1f5f9; color: #475569; }
.badge.draft { background: #f1f5f9; color: #475569; }
.badge.sent { background: #dbeafe; color: #1e40af; }
.badge.unpaid { background: #fef3c7; color: #92400e; }

.empty {
  padding: 30px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

/* ----- DETAIL VIEWS ----- */
.detail h1 { font-size: 24px; margin: 0 0 4px; font-weight: 800; }
.detail .sub { color: var(--text-dim); font-size: 14px; margin-bottom: 24px; }
.detail section { margin-bottom: 28px; }
.detail h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin: 0 0 10px;
  font-weight: 700;
}
.kv {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 14px;
}
.kv .row {
  display: flex; justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.kv .row:last-child { border-bottom: none; }
.kv .k { color: var(--text-muted); font-size: 12px; }
.kv .v { font-weight: 600; text-align: right; }

/* ----- CHECKLIST RESULTS ----- */
.checklist-results {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 0;
}
.checklist-results .item {
  display: flex; gap: 12px; padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.checklist-results .item:last-child { border-bottom: none; }
.checklist-results .check {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  background: var(--bg-elev);
}
.checklist-results .item.done .check {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.checklist-results .item .body { flex: 1; min-width: 0; }
.checklist-results .room { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.checklist-results .task { font-size: 14px; }
.checklist-results .photo-thumb {
  margin-top: 6px;
  max-width: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ----- PHOTO GRID ----- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.photo-grid .photo {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
}
.photo-grid .photo img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.photo-grid .photo .label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 10px;
  padding: 4px 8px;
  font-weight: 600;
}

/* ----- ISSUES ----- */
.issue {
  background: #fef2f2;
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 8px;
}
.issue.acknowledged { background: #fefce8; border-left-color: var(--warn); }
.issue.resolved { background: #f0fdf4; border-left-color: var(--success); opacity: .85; }
.issue .head {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  font-weight: 600;
}
.issue .desc { font-size: 14px; color: var(--text); }

/* ----- MESSAGES ----- */
.thread {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 20px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg-elev);
  border-radius: var(--radius);
}
.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.mine {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg.theirs {
  background: var(--bg-card);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg .meta {
  font-size: 10px;
  opacity: .7;
  margin-top: 4px;
}

/* ----- MODAL ----- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  z-index: 100;
  display: none;
  align-items: flex-end;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal h2 { margin: 0 0 12px; font-size: 20px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions button { flex: 1; padding: 12px; }
@media (min-width: 768px) {
  .modal-overlay { align-items: center; justify-content: center; }
  .modal { max-width: 540px; border-radius: 16px; max-height: 80vh; }
}

/* ----- TOAST ----- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: var(--brand);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: all .25s;
  z-index: 200;
  box-shadow: var(--shadow-lg);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { background: var(--success); }
#toast.error { background: var(--danger); }

.loading { display: flex; justify-content: center; align-items: center; padding: 40px; color: var(--text-dim); gap: 10px; }
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- RESPONSIVE ----- */
@media (max-width: 768px) {
  .topbar {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 2px;
    padding-bottom: 4px;
  }
  .topbar nav a {
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .topbar .brand { font-size: 15px; }
  .content { padding: 16px; }
  .welcome h1 { font-size: 22px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* Sender name above each chat message */
.msg .sender {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
  opacity: 1;
}
.msg.mine .sender { text-align: right; }
