/* Kinpany Design Tokens (Product Experience v1) - the same palette used
   across all four Kinpany apps, sourced from the existing brand mark
   (kinpany-visit-pwa/public/favicon.svg): --accent is that mark's own
   primary purple. This app keeps its existing, deliberately plain
   "operations console" structure (ADR-24: efficiency over decoration) -
   only the token values change here, not the layout/components. */
:root {
  color-scheme: light dark;
  --border: #ddd6ec;
  --muted: #6b6478;
  --accent: #7e14ff;
  --accent-contrast: #fff;
  --danger: #b3261e;
  --warning: #92600a;
  --success: #1e7b34;
  --bg-subtle: #f6f4fb;
  --bg: #fff;
  --text: #1a1625;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(30, 10, 60, 0.06), 0 4px 10px rgba(30, 10, 60, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --border: #362f47;
    --muted: #a79fc0;
    --accent: #b98bff;
    --accent-contrast: #1a0f2e;
    --bg-subtle: #211c2e;
    --bg: #16121f;
    --text: #eee6fb;
  }
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

header h1 { font-size: 1.1rem; margin: 0; }

.brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.brand__mark { display: block; flex: none; }
.brand__product { font-weight: 400; color: var(--muted); }

#top-bar { display: flex; align-items: center; gap: 0.5rem 1.25rem; font-size: 0.9rem; flex-wrap: wrap; max-width: 100%; }
/* The eight views wrap onto further rows on a phone instead of pushing the whole page wider than the screen. */
#top-bar nav { display: flex; gap: 0.4rem; flex-wrap: wrap; }
#top-bar nav button {
  background: transparent;
  color: var(--accent);
  border: 1px solid transparent;
}
#top-bar nav button.nav-active {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-weight: 600;
}

main { padding: 1.25rem; max-width: 960px; margin: 0 auto; }

form.stack { display: flex; flex-direction: column; gap: 0.75rem; max-width: 320px; }

/* Product Experience v1 (section 4, login/onboarding). */
.auth-card {
  max-width: 380px;
  margin: 10vh auto 0;
  padding: 2rem 1.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-subtle);
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-card__mark { display: block; margin: 0 auto 0.75rem; }
.auth-card h2 { margin: 0 0 0.5rem; }
.auth-card .stack { max-width: none; text-align: left; margin-top: 1.25rem; }
.auth-card__hint { font-size: 0.82rem; color: var(--muted); margin: 1rem 0 0; }
.btn-block { width: 100%; min-height: 44px; }

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }

input[type="text"], input[type="password"], select, textarea {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
}

textarea { width: 100%; display: block; margin: 0.5rem 0; resize: vertical; }

.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

button {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
}

button.secondary { background: transparent; color: var(--accent); }
button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; flex-wrap: wrap; gap: 0.5rem; }
.toolbar h2 { margin: 0; }

.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.5rem 0; }
.row input, .row select { flex: 1 1 180px; }

.panel { border: 1px solid var(--border); border-radius: 6px; padding: 0.9rem; margin: 1rem 0; }
.panel h3 { margin-top: 0; }

.error-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  background: #fdecea;
  color: var(--danger);
  border: 1px solid #f5c6c2;
  border-radius: 4px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.notice-banner {
  background: #e6f4ea;
  color: #1e7b34;
  border: 1px solid #bfe3c9;
  border-radius: 4px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }

/* Product Experience v1 (section 4, "responsive"): every table in this
   app is otherwise plain HTML with no wrapper element per view - rather
   than touch every view file individually, the table itself becomes its
   own horizontally-scrollable region below the point its columns
   realistically fit, so a data-heavy table (Inspectors, Work Orders)
   never forces the whole page to scroll sideways on a phone/tablet. */
@media (max-width: 720px) {
  table { display: block; overflow-x: auto; white-space: nowrap; }
}
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg-subtle); }
li.clickable { cursor: pointer; padding: 0.2rem 0; }
li.clickable:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.8rem; }
.badge.status-open { background: #e6f4ea; color: #1e7b34; }
.badge.status-completed { background: #e8eefb; color: var(--accent); }
.badge.status-cancelled { background: #eee; color: var(--muted); }
.badge.lifecycle-active { background: #e6f4ea; color: #1e7b34; }
.badge.lifecycle-deactivated { background: #eee; color: var(--muted); }
.badge.lifecycle-unknown { background: #fdf3e3; color: var(--warning); }

.fields dt { font-weight: 600; font-size: 0.85rem; color: var(--muted); }
.fields dd { margin: 0 0 0.5rem 0; }

.muted { color: var(--muted); font-size: 0.9rem; }

.credential-reveal {
  border: 2px solid var(--warning);
  border-radius: 6px;
  padding: 0.9rem;
  background: #fffaf0;
}
.credential-reveal .warning { color: var(--warning); font-weight: 600; margin-top: 0; }
.credential-reveal input { width: 100%; }

/* Back Office Operations v1 (migration 0003) */

.badge.availability-available { background: #e6f4ea; color: #1e7b34; }
.badge.availability-unavailable { background: #fdecea; color: var(--danger); }
.badge.availability-temporarily_unavailable { background: #fdf3e3; color: var(--warning); }

.badge.priority-low { background: #eee; color: var(--muted); }
.badge.priority-normal { background: #e8eefb; color: var(--accent); }
.badge.priority-high { background: #fdf3e3; color: var(--warning); }
.badge.priority-urgent { background: #fdecea; color: var(--danger); font-weight: 600; }

.badge.inspector-status-unstarted { background: #eee; color: var(--muted); }
.badge.inspector-status-accepted { background: #e8eefb; color: var(--accent); }
.badge.inspector-status-in_progress { background: #fdf3e3; color: var(--warning); }
.badge.inspector-status-issue { background: #fdecea; color: var(--danger); font-weight: 600; }
.badge.inspector-status-completed { background: #e6f4ea; color: #1e7b34; }

.badge.event-recommended { background: #eee; color: var(--muted); }
.badge.event-assigned { background: #e6f4ea; color: #1e7b34; }
.badge.event-reassigned { background: #fdf3e3; color: var(--warning); }
.badge.event-unassigned { background: #fdecea; color: var(--danger); }

/* KINPANY Inspector P8 (approved P6-P9 implementation plan) - preserves
   the Complete/Not applicable/Not possible distinction (spec §5.3),
   never flattened to a generic "incomplete" look. */
.badge.exception-not_applicable { background: #e6f4ea; color: #1e7b34; }
.badge.exception-not_possible { background: #fdf3e3; color: var(--warning); }

.inspection-result { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.inspection-result__step { border: 1px solid var(--border); border-radius: 6px; padding: 0.6rem 0.8rem; }
.inspection-result__step ul { margin: 0.3rem 0 0; padding-left: 1.1rem; }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.35rem 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.4rem 0.15rem 0.7rem;
  font-size: 0.85rem;
}
.chip__remove {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0 0.3rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.inline-check { flex-direction: row; align-items: center; gap: 0.35rem; }

.coverage-verdict { font-size: 0.85rem; padding: 0.1rem 0.5rem; border-radius: 999px; }
.coverage-verdict.coverage-in { background: #e6f4ea; color: #1e7b34; }
.coverage-verdict.coverage-out { background: #fdecea; color: var(--danger); }
.coverage-verdict.coverage-unknown { background: #fdf3e3; color: var(--warning); }

.scatter-map { margin: 1rem 0; max-width: 320px; }
.scatter-map svg { display: block; border: 1px solid var(--border); border-radius: 8px; }

.dispatch-row--unassigned { background: #fdecea; }
.dispatch-row--unassigned:hover { background: #fbd9d5; }
.dispatch-row--issue { background: #fdf3e3; }

.candidate-list { list-style: decimal; padding-left: 1.4rem; margin: 0; }
.candidate { margin: 0 0 0.9rem; }
.candidate__header { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.candidate__score { font-weight: 700; color: var(--accent); }
.candidate__reasons { margin: 0.25rem 0 0; padding-left: 1.2rem; font-size: 0.85rem; color: var(--muted); }

.history-list { list-style: none; padding: 0; margin: 0; font-size: 0.9rem; }
.history-list li { padding: 0.3rem 0; border-bottom: 1px solid var(--border); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.75rem; margin: 0.75rem 0 1.25rem; }
.stat-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-subtle);
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.stat-tile:disabled { cursor: default; opacity: 1; }
.stat-tile__value { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.stat-tile__label { font-size: 0.85rem; color: var(--muted); }

/* Canonical Bookings (Phase 7). Status colours reuse the existing palette. */
.badge.booking-status-pending { background: #fdf3e3; color: var(--warning); }
.badge.booking-status-accepted { background: #e8eefb; color: var(--accent); }
.badge.booking-status-awaiting_payment { background: #fdf3e3; color: var(--warning); font-weight: 600; }
.badge.booking-status-paid { background: #e6f4ea; color: #1e7b34; }
.badge.booking-status-work_orders_created { background: #e6f4ea; color: #1e7b34; font-weight: 600; }
.badge.booking-status-declined { background: #eee; color: var(--muted); }

ol.lifecycle { display: flex; flex-wrap: wrap; gap: 0.35rem; list-style: none; padding: 0; margin: 0.75rem 0; font-size: 0.85rem; }
ol.lifecycle li { padding: 0.15rem 0.6rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
ol.lifecycle li + li::before { content: "→ "; }
ol.lifecycle li.done { color: var(--success); border-color: var(--success); }
ol.lifecycle li.current { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 600; }
ol.lifecycle li.current.declined { background: var(--muted); border-color: var(--muted); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1.25rem; margin: 0; }
dl.kv .kv-row { display: contents; }
dl.kv dt { color: var(--muted); font-size: 0.85rem; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { dl.kv { grid-template-columns: 1fr; } dl.kv dd { margin-bottom: 0.4rem; } }

/* Client Channel (client conversations) */
.channel-thread { list-style: none; padding: 0; margin: 1rem 0; display: flex; flex-direction: column; gap: 0.6rem; max-width: 46rem; }
.channel-message { border: 1px solid var(--border, #d0d5dd); border-radius: 8px; padding: 0.6rem 0.8rem; background: #fff; }
.channel-message p { margin: 0.3rem 0 0; white-space: pre-wrap; }
.channel-message--client { border-left: 4px solid #0e7c7b; }
.channel-message--operations { border-left: 4px solid #1f3a5f; background: #f5f8fc; }
.channel-message--system { color: #555; background: #fafafa; }
