/* AI Estate Agent: the existing blue, white and slate palette, shared across all pages. */
:root {
  --bg: #f5f8fc;
  --surface: #fff;
  --surface-alt: #f8fafb;
  --ink: #162338;
  --muted: #63738a;
  --line: #dce5f0;
  --input-border: #cad6e4;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --light: #eaf2ff;
  --red: #b42332;
  --danger: #a33939;
  --danger-hover: #812727;
  --success: #16804a;
  --success-bg: #e9f8ef;
  --warning: #94620d;
  --warning-bg: #fff6e6;
  --danger-bg: #fff0f0;
  --neutral-bg: #eef2f7;
  --neutral-ink: #4b5a70;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgb(22 35 56 / 3%);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; color: var(--ink); }
h1 { margin: 0 0 10px; font-size: 28px; letter-spacing: -.8px; font-weight: 650; }
h2 { margin: 0 0 18px; font-size: 17px; letter-spacing: -.25px; font-weight: 650; }
h3 { margin: 0 0 8px; font-size: 15px; font-weight: 650; }
p { margin: 0 0 16px; }
.muted, .caption, .hint { color: var(--muted); }
.caption, .hint { font-size: 12px; line-height: 1.6; }
.hint { margin-top: 7px; }
.eyebrow { margin-bottom: 10px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: 1.6px; }
[hidden] { display: none !important; }

/* Header and existing horizontal navigation. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 4vw;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 4px rgb(22 35 56 / 2%);
}
.brand { display: flex; align-items: center; gap: 11px; flex-shrink: 0; color: var(--ink); font-size: 18px; font-weight: 600; letter-spacing: -.5px; }
.brand-mark { display: block; width: 100%; height: 100%; flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.brand strong { font-weight: 400; color: var(--muted); }
.brand-icon { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 22px; font-weight: 700; }
.main-nav { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-width: 0; }
.main-nav a { display: inline-flex; align-items: center; min-height: 42px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap; }
.main-nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.main-nav a[aria-current="page"] { background: var(--light); color: var(--accent); font-weight: 650; box-shadow: inset 0 -2px var(--accent); }
.account { display: flex; gap: 18px; align-items: center; flex-shrink: 0; }
.agent-status { color: var(--muted); font-size: 12px; white-space: nowrap; }
.agent-status[data-state="NORMAL"] { color: var(--success); }
.agent-status[data-state="EMERGENCY_STOP_ACTIVE"] { color: var(--red); }
.dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #16a05d; }
.agent-status[data-state="EMERGENCY_STOP_ACTIVE"] .dot { background: var(--red); }
.agent-status[data-state="UNKNOWN"] .dot { background: #d28a16; }
.agent-status:is([data-state="STOP_REQUESTED"], [data-state="RESUMING"], [data-state="STOP_FAILED_UNCONFIRMED"]) { color: #9a5b0c; }
.agent-status:is([data-state="STOP_REQUESTED"], [data-state="RESUMING"], [data-state="STOP_FAILED_UNCONFIRMED"]) .dot { background: #d28a16; }
.text-button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 10px; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-size: 12px; }
.text-button:hover { background: var(--bg); color: var(--ink); }
.container { max-width: 1200px; margin: auto; padding: 36px 28px; min-width: 0; }
.heading { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 28px; }
.heading > div { min-width: 0; }
.heading h1 { overflow-wrap: anywhere; }
.heading p { margin: 0; }
.heading .eyebrow { margin-bottom: 8px; }
.heading .muted { font-size: 14px; max-width: 72ch; }
.footer { display: flex; justify-content: space-between; gap: 14px; margin-top: 32px; padding-top: 22px; padding-bottom: 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.back { display: inline-flex; align-items: center; min-height: 36px; margin-bottom: 14px; font-size: 13px; }

/* Shared surfaces, spacing and dashboard metrics. */
.card, .stat, .status-card, .login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card { padding: 24px; min-width: 0; }
.card > :last-child { margin-bottom: 0; }
.section-gap { margin-top: 24px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 20px; }
.stat-label { display: block; color: var(--muted); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.stat-number { display: block; margin-top: auto; color: var(--accent); font-size: 30px; line-height: 1.2; font-weight: 650; letter-spacing: -1px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-link:hover { border-color: var(--accent); background: var(--light); text-decoration: none; }
.stat-detail { color: var(--accent); font-size: 11px; font-weight: 600; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(240px, 1fr); gap: 24px; align-items: start; }
.two-col > * { min-width: 0; }
.detail-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 18px; margin-bottom: 20px; color: var(--muted); font-size: 12px; }
.aside-icon { margin-bottom: 12px; color: var(--accent); font-size: 26px; }
.aside h2 { font-size: 16px; }
.aside p { color: var(--muted); font-size: 13px; }
.summary-line { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 13px; overflow-wrap: anywhere; }
.summary-line:last-child { border-bottom: 0; }
.summary-line span { color: var(--muted); }
.preview { white-space: pre-line; }

/* Button hierarchy, with stable touch targets and no layout movement on hover. */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; max-width: 100%; padding: 10px 16px; border: 1px solid var(--accent); border-radius: var(--radius-sm); background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; line-height: 1.5; text-decoration: none; white-space: nowrap; }
.button:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.button.secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.button.secondary:hover { background: var(--bg); border-color: var(--input-border); }
.button.danger { background: var(--danger); border-color: var(--danger); }
.button.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.button:disabled, .text-button:disabled { cursor: not-allowed; opacity: 1; background: var(--neutral-bg); border-color: var(--line); color: var(--neutral-ink); box-shadow: none; }
.form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.form-actions:empty { display: none; }
#emergency-stop { white-space: normal; text-align: center; }
.control-blocked { opacity: .45; pointer-events: none; }

/* Forms and filters use the same height, border and focus treatment. */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 20px; }
.field { min-width: 0; }
.field.full { grid-column: 1 / -1; }
label, .field-label { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 600; line-height: 1.5; }
input, select, textarea { display: block; width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px; border: 1px solid var(--input-border); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-size: 14px; line-height: 1.5; }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid #a8c5ff; outline-offset: 2px; }
input:disabled, select:disabled, textarea:disabled { background: var(--neutral-bg); border-color: var(--line); color: var(--neutral-ink); cursor: not-allowed; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--red); }
input[type="range"], input[type="checkbox"] { accent-color: var(--accent); }
input[type="checkbox"] { display: inline-block; width: 17px; height: 17px; min-height: 0; flex-shrink: 0; margin: 0; }
.options { display: flex; gap: 10px; flex-wrap: wrap; }
.options label { display: flex; align-items: center; gap: 9px; min-height: 44px; margin: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13px; font-weight: 400; cursor: pointer; }
.options label:has(input:checked) { background: var(--light); border-color: var(--accent); }
.crm-toolbar { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.crm-toolbar .field { min-width: 160px; flex: 1; }
.crm-toolbar .field.search { flex: 2; }
.crm-toolbar button { margin-bottom: 0; }

/* Tables remain tables; scrolling stays inside the table on small screens. */
.table-wrap { max-width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overscroll-behavior-x: contain; scrollbar-color: var(--input-border) var(--bg); }
.crm-table { width: 100%; min-width: 840px; border-collapse: collapse; font-size: 13px; line-height: 1.55; }
.crm-table th, .crm-table td { padding: 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.crm-table th { background: var(--surface-alt); color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .5px; text-transform: uppercase; white-space: nowrap; }
.crm-table tbody tr:hover { background: var(--bg); }
.crm-table tr:last-child td { border-bottom: 0; }
.crm-table td a { font-weight: 550; }
.crm-table .badge { white-space: nowrap; overflow-wrap: normal; }
.crm-pagination { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; }
.crm-pagination .form-actions { margin: 0; }
.crm-pagination button { padding: 8px 14px; }
.crm-kv { display: grid; grid-template-columns: minmax(130px, .5fr) minmax(0, 1fr); gap: 0 18px; }
.crm-kv > div { padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }

/* Status colours are retained; status text remains the primary indicator. */
.badge { display: inline-flex; align-items: center; min-height: 26px; max-width: 100%; padding: 4px 9px; border: 1px solid transparent; border-radius: 6px; background: var(--neutral-bg); color: var(--neutral-ink); font-size: 11px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.badge:is(.RUNNING, .COMPLETED, .connected, .ACTIVE, .Active, .Actif, .Connecté, .safety-active),
.status-card:is([data-status="ONLINE"], [data-status="CONNECTED"]) .badge { background: var(--success-bg); color: var(--success); }
.badge:is(.FAILED, .EMERGENCY_STOP_ACTIVE, .safety-stopped),
.status-card:is([data-status="error"], [data-status="FAILED"], [data-status="ERROR"], [data-status="UNHEALTHY"]) .badge { background: var(--danger-bg); color: var(--red); }
.badge:is(.WAITING, .RETRY_PENDING, .unknown, .disconnected),
.status-card:is([data-status="STARTING"], [data-status="CHECKING"]) .badge { background: var(--warning-bg); color: var(--warning); }
.badge:is(.Inactive, .Inactif, .Inconnu) { background: var(--neutral-bg); color: #5b6575; }
.status-card[data-status="degraded"] .badge, .badge.safety-unknown { background: #fff3dc; color: #87510a; }
.status-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.status-card { padding: 20px; min-width: 0; }
.status-card p { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.status-card .badge { margin-bottom: 5px; }
.status-card > .button { margin-top: 16px; }
.safety-panel { border-left: 3px solid var(--accent); }
.safety-panel .button { margin-top: 6px; }

/* Empty, error and partial states. Empty error containers consume no space. */
.empty { padding: 36px 20px; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface); color: var(--muted); text-align: center; font-size: 13px; }
.error { color: var(--red); font-size: 13px; white-space: pre-line; overflow-wrap: anywhere; }
.error:empty { display: none; }
.notice { margin-bottom: 18px; padding: 14px 16px; border: 1px solid #f0d7aa; border-radius: var(--radius-sm); background: #fff9ed; color: #775315; font-size: 13px; }
.unsupported { border-color: #edc6a9; background: #fffaf7; }

/* Searches and detail pages. */
.search-list { display: grid; gap: 16px; }
.search-card { padding: 22px 24px; }
.search-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.search-card-head h2 { margin-bottom: 6px; }
.search-card .form-actions { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.search-card .badge { white-space: nowrap; }
.search-form { max-width: 820px; }
.search-form .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.range-output { display: block; margin-top: 2px; color: var(--accent); font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.search-form input[type="range"] { padding: 10px 0; border: 0; background: transparent; }
.toggle-field { display: flex; align-items: center; gap: 9px; align-self: end; min-height: 44px; margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.commune-suggestions { position: relative; z-index: 2; display: grid; gap: 4px; max-height: 320px; overflow: auto; margin-top: 5px; }
.commune-option { display: flex; justify-content: space-between; align-items: center; gap: 15px; width: 100%; min-height: 44px; padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); text-align: left; }
.commune-option:hover, .commune-option:focus { background: var(--light); border-color: #9bbcff; }
.commune-option .caption { text-align: right; }
.listing { padding: 20px 0; border-top: 1px solid var(--line); }
.listing-head { display: flex; align-items: start; justify-content: space-between; gap: 15px; }
.listing-data { color: var(--muted); font-size: 13px; }
.listing small { color: var(--muted); }
.timeline { display: grid; }
.timeline-entry { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 18px; padding: 18px 0; border-top: 1px solid var(--line); }
.timeline-entry:first-child { border-top: 0; }
.timeline-entry p { margin: 0; overflow-wrap: anywhere; }
.timeline-entry .actor { margin-bottom: 3px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .7px; }
.timeline-entry .detail { white-space: pre-wrap; font-size: 13px; }
details { margin-top: 18px; font-size: 12px; }
summary { min-height: 36px; padding: 6px 0; font-weight: 600; cursor: pointer; }
details p { margin-top: 8px; overflow-wrap: anywhere; }
progress { display: block; width: 100%; height: 6px; margin: 10px 0; border: 0; border-radius: 6px; appearance: none; }
progress::-webkit-progress-bar { background: #e8eef0; border-radius: 6px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 6px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 6px; }
.progress { width: 100%; height: 6px; margin: 10px 0; overflow: hidden; border-radius: 6px; background: #e8eef0; }

/* Live view stays a passive image. Interactive auth keeps its own input surface. */
.live-frame { min-height: 100px; overflow: hidden; margin: 16px 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #eff2f4; }
.live-frame img { display: block; width: 100%; height: auto; cursor: default; pointer-events: none; user-select: none; }
.live-frame p { padding: 20px; }
.live-title, .live-url, .live-tabs { overflow-wrap: anywhere; }
.live-title { font-size: 14px; }
.live-url:empty, .live-title:empty { display: none; }
#live-status { margin-bottom: 10px; }
#live-step:not(:empty) { display: inline-block; margin-bottom: 12px; padding: 4px 9px; border-radius: 6px; background: var(--bg); }
.live-tabs { padding-left: 20px; color: var(--muted); font-size: 12px; }
.live-tabs li { margin: 6px 0; cursor: default; }
.auth-viewer { max-width: 100%; overflow: hidden; }
.auth-screen { width: 100%; max-height: min(72vh, 900px); overflow: auto; border-radius: var(--radius-sm); background: #111; touch-action: none; }
.auth-screen img { display: block; width: 100%; height: auto; min-height: 180px; object-fit: contain; cursor: crosshair; user-select: none; -webkit-user-drag: none; touch-action: none; }
.auth-viewer .form-actions { position: sticky; bottom: 0; padding: 12px 0; background: var(--surface); }
.auth-screen:focus { outline: 3px solid var(--accent); outline-offset: 3px; }
.auth-screen:focus:not(:focus-visible) { outline-color: #93c5fd; }

/* Approval cards, draft previews and native accessible switches. */

/* Local access form uses the same visual language. */
.login { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 440px; padding: 36px; }
.login-card .brand-icon { margin-bottom: 24px; }
.login-card h1 { font-size: 25px; }
.login-card form { margin-top: 26px; }
.login-card button { width: 100%; margin-top: 10px; }
.login-note { margin: 24px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

/* Focus is visible throughout; motion never changes element geometry. */
:is(button, a, input, select, textarea, summary, [tabindex]):focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
@media (prefers-reduced-motion: no-preference) {
  .button, .text-button, .main-nav a, .commune-option, input, select, textarea, .crm-table tbody tr { transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease; }
}

@media (max-width: 1180px) {
  .topbar { flex-wrap: wrap; gap: 12px 20px; }
  .main-nav { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .account { margin-left: auto; }
}
@media (max-width: 760px) {
  .container { padding: 26px 18px; }
  .topbar { padding: 12px 18px; }
  .brand { font-size: 16px; }
  .brand-icon { width: 34px; height: 34px; font-size: 20px; }
  .main-nav { gap: 3px; }
  .main-nav a { min-height: 44px; padding: 9px 10px; font-size: 12px; }
  .heading { align-items: flex-start; flex-direction: column; gap: 18px; margin-bottom: 22px; }
  h1 { font-size: 25px; }
  .two-col, .form-grid, .search-form .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid { gap: 20px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 16px; }
  .stat-number { font-size: 26px; }
  .card { padding: 20px; }
  .footer { flex-direction: column; gap: 8px; }
  .account { gap: 6px; }
  .agent-status { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
  .status-grid { grid-template-columns: minmax(0, 1fr); }
  .timeline-entry { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .crm-toolbar { padding: 16px; }
  .crm-toolbar .field, .crm-toolbar .field.search { min-width: 100%; }
  .crm-toolbar > .button { width: 100%; }
  .crm-table { min-width: 780px; }
  .crm-table th, .crm-table td { padding: 14px; }
  .crm-pagination { align-items: flex-start; flex-direction: column; }
  .crm-pagination .form-actions { width: 100%; }
  .crm-pagination .button { flex: 1; }
  .search-card-head, .listing-head { flex-direction: column; gap: 12px; }
  .search-card .form-actions .button { flex: 1; white-space: normal; }
  .commune-option { align-items: flex-start; flex-direction: column; gap: 2px; }
  .commune-option .caption { text-align: left; }
  .auth-screen { max-height: 65vh; }
  .auth-screen img { min-height: 160px; }
  .auth-viewer .form-actions .button { flex: 1; white-space: normal; }
}
@media (max-width: 480px) {
  .topbar { gap: 10px; }
  .account { gap: 2px; }
  .agent-status { max-width: 125px; font-size: 11px; }
  .text-button { padding: 8px 6px; font-size: 11px; }
  .card { padding: 18px; }
  .crm-kv { grid-template-columns: minmax(0, 1fr); }
  .summary-line { flex-wrap: wrap; gap: 4px 12px; }
  .form-actions .button { white-space: normal; }
  .login-card { padding: 28px 24px; }
  input, select, textarea { font-size: 16px; }
}

/* Account page: two equal forms, cards spaced like the rest of the app, inline delete confirmation. */
.account-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 24px; }
.account-page > .card { margin-bottom: 24px; }
.account-page .card form .field { margin-bottom: 14px; }
.inline-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-confirm input { max-width: 200px; }
.account-link { color: inherit; font-size: 13px; font-weight: 600; text-decoration: none; }
.account-link:hover { text-decoration: underline; }
.login-card .caption { margin: -2px 0 12px; }
@media (max-width: 760px) { .account-grid { grid-template-columns: minmax(0, 1fr); } }
.login-card form input { margin-bottom: 14px; }
.login-card form .caption { margin-top: -8px; }
.login-card form .error:not(:empty) { margin: -4px 0 8px; }
.two-step-secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; letter-spacing: .04em; overflow-wrap: anywhere; }
.two-step-setup { display: grid; gap: 8px; }
.account-page .inline-confirm select { max-width: 170px; }
