/* Margalla Crest: pine green and brass, with the contour lines of the Margalla Hills. */

:root {
  --stone: #f0f3f1;
  --panel: #ffffff;
  --panel-2: #e6ece8;
  --line: #d6ded9;
  --ink: #172019;
  --muted: #59665e;
  --pine: #1e4034;
  --pine-deep: #142e25;
  --pine-soft: #e2ebe5;
  --brass: #c9974a;
  --brass-ink: #2e1f06;
  --clay: #b4432f;
  --on-pine: #ffffff;
  --shadow: 0 10px 30px rgba(23, 32, 25, 0.13);
  --rail: 720px;
  --contour: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 40'%3E%3Cg fill='none' stroke='%231e4034' stroke-width='1.2'%3E%3Cpath d='M0 8C20 2 40 2 60 8S100 14 120 8'/%3E%3Cpath d='M0 18C20 11 40 11 60 18S100 25 120 18'/%3E%3Cpath d='M0 28C20 22 40 22 60 28S100 34 120 28'/%3E%3Cpath d='M0 37C20 32 40 32 60 37S100 42 120 37'/%3E%3C/g%3E%3Cpath d='M0 18C20 11 40 11 60 18S100 25 120 18' fill='none' stroke='%23c9974a' stroke-width='1.6'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --stone: #0f1915;
    --panel: #16241e;
    --panel-2: #1f3129;
    --line: #2a3d34;
    --ink: #e8efe9;
    --muted: #9fb0a5;
    --pine: #8cc3a6;
    --pine-deep: #a6d4bb;
    --pine-soft: #1f3a2f;
    --clay: #e27b63;
    --on-pine: #0d1a14;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    --contour: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 40'%3E%3Cg fill='none' stroke='%238cc3a6' stroke-width='1.2' opacity='.7'%3E%3Cpath d='M0 8C20 2 40 2 60 8S100 14 120 8'/%3E%3Cpath d='M0 18C20 11 40 11 60 18S100 25 120 18'/%3E%3Cpath d='M0 28C20 22 40 22 60 28S100 34 120 28'/%3E%3Cpath d='M0 37C20 32 40 32 60 37S100 42 120 37'/%3E%3C/g%3E%3Cpath d='M0 18C20 11 40 11 60 18S100 25 120 18' fill='none' stroke='%23c9974a' stroke-width='1.6'/%3E%3C/svg%3E");
  }
}
:root[data-theme="dark"] {
  --stone: #0f1915;
  --panel: #16241e;
  --panel-2: #1f3129;
  --line: #2a3d34;
  --ink: #e8efe9;
  --muted: #9fb0a5;
  --pine: #8cc3a6;
  --pine-deep: #a6d4bb;
  --pine-soft: #1f3a2f;
  --clay: #e27b63;
  --on-pine: #0d1a14;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--stone);
  color: var(--ink);
  font: 400 15.5px/1.55 "Figtree", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.wordmark, .display {
  font-family: "Gloock", Georgia, serif;
  font-weight: 400;
  line-height: 1.05;
}

/* Signature: the contour band. Still at rest; the hills drift while the assistant is working. */
.contours {
  flex: none;
  height: 26px;
  background: var(--contour) 0 50% / 78px 26px repeat-x;
  border-bottom: 1px solid var(--line);
}
.contours.busy { animation: drift 1.4s linear infinite; }
@keyframes drift { to { background-position-x: 78px; } }

/* ---------- Gate ---------- */

#gate { min-height: 100dvh; display: flex; flex-direction: column; }

.contours.tall {
  height: 120px;
  background-size: 240px 80px;
  background-repeat: repeat;
  border-bottom: 3px solid var(--pine);
}

#gate-form {
  width: min(440px, calc(100% - 32px));
  margin: auto;
  padding: 48px 0 64px;
  text-align: center;
}

#gate .wordmark { font-size: clamp(40px, 10vw, 64px); color: var(--pine); text-wrap: balance; }

.gate-tagline { font-size: 17px; font-weight: 500; margin-top: 16px; }

.gate-address { color: var(--muted); font-size: 14px; margin: 6px 0 36px; }

.gate-field {
  display: flex;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
}
.gate-field:focus-within { border-color: var(--pine); }

.gate-field input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  color: var(--ink);
  font: inherit;
  padding: 8px 10px;
}
.gate-field input::placeholder { color: var(--muted); }
.gate-field input:focus { outline: none; }

#gate-enter {
  background: var(--pine);
  color: var(--on-pine);
  font-weight: 600;
  border-radius: 6px;
  padding: 8px 20px;
}
#gate-enter:hover { background: var(--pine-deep); }
#gate-enter:disabled { opacity: 0.6; cursor: default; }

.gate-error { color: var(--clay); font-size: 14px; margin-top: 14px; }

/* ---------- Chat frame ---------- */

#chat { height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 28px);
  background: var(--panel);
}

.topbar-id { display: flex; align-items: baseline; gap: 14px; min-width: 0; }

.topbar .wordmark.sm { font-size: 24px; color: var(--pine); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pine); }
.status.closed .dot { background: var(--brass); }

.topbar-side { display: flex; align-items: center; gap: 6px; }

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--pine);
  color: var(--pine);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}
.pill-btn svg { width: 17px; height: 17px; }
.pill-btn:hover { background: var(--pine-soft); }

/* ---------- Messages ---------- */

#messages { flex: 1; overflow-y: auto; padding: 26px clamp(16px, 4vw, 28px); }

.rail { max-width: var(--rail); margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }

.msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: break-word; }
.msg.agent { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.user { align-self: flex-end; background: var(--pine); color: var(--on-pine); border-bottom-right-radius: 4px; }
.msg a { color: var(--pine); text-underline-offset: 2px; }
.msg.user a { color: inherit; font-weight: 600; }

.msg.note { align-self: center; max-width: 100%; background: none; border: 0; color: var(--clay); font-size: 13.5px; padding: 2px 0; }

.msg.typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.msg.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--pine); animation: pulse 1.1s ease-in-out infinite; }
.msg.typing i:nth-child(2) { animation-delay: 0.18s; }
.msg.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes pulse { 0%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* ---------- Listing cards ---------- */

.listing-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 2px 2px 10px;
  margin: 0 -2px;
}
.listing-strip .listing { flex: 0 0 min(300px, 84%); scroll-snap-align: start; }

.listing {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* The plate stands in for a photo: a contour patch tinted by purpose */
.plate {
  height: 64px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: var(--contour) 0 0 / 120px 40px, var(--pine-soft);
  font-size: 12.5px;
  font-weight: 700;
}
.plate span { background: var(--panel); padding: 2px 8px; border-radius: 4px; }
.plate.sale span:first-child { background: var(--pine); color: var(--on-pine); }
.plate.rent span:first-child { background: var(--brass); color: var(--brass-ink); }

.listing-body { padding: 12px 14px 14px; display: flex; flex-direction: column; flex: 1; }
.listing-price { font-family: "Gloock", Georgia, serif; font-size: 22px; line-height: 1.15; color: var(--pine); }
.listing-title { font-size: 15.5px; font-weight: 600; margin-top: 4px; }
.listing-where { color: var(--muted); font-size: 14px; }
.listing-specs { font-size: 13.5px; margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; }
.listing-specs .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--muted); margin: 0 8px; }
.listing-note { color: var(--muted); font-size: 13.5px; margin-top: 8px; }
.plan { font-size: 13.5px; font-weight: 600; color: var(--ink); background: rgba(201, 151, 74, 0.22); border-left: 3px solid var(--brass); padding: 4px 8px; border-radius: 4px; margin-top: 8px; }

.listing-actions { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 12px; flex-wrap: wrap; }
.act { font-size: 13.5px; font-weight: 600; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); }
.act:hover { border-color: var(--pine); }
.act.primary { background: var(--pine); color: var(--on-pine); border-color: var(--pine); }
.act.primary:hover { background: var(--pine-deep); }
.ref { margin-left: auto; color: var(--muted); font-size: 12.5px; }

/* ---------- Confirmation cards ---------- */

.card {
  align-self: flex-start;
  width: min(380px, 92%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--pine);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: card-in 0.35s ease-out;
}
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } }

.card.finance { border-left-color: var(--brass); }
.card.cancelled { border-left-color: var(--clay); }
.card.cancelled .card-code { text-decoration: line-through; color: var(--muted); }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 16px 10px; }
.card-kind { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.card-title { font-size: 21px; margin-top: 4px; }
.card-title small { font-family: "Figtree", sans-serif; font-size: 14px; color: var(--muted); }
.card-code { font-family: "Gloock", Georgia, serif; font-size: 20px; color: var(--pine); white-space: nowrap; }

.card-rows { padding: 2px 16px 12px; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14.5px; }
.card-rows dt { color: var(--muted); }
.card-rows dd { font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }

.card-foot { padding: 10px 16px 12px; background: var(--pine-soft); font-size: 13.5px; }

/* ---------- Composer ---------- */

.composer { border-top: 1px solid var(--line); padding: 10px clamp(16px, 4vw, 28px) calc(14px + env(safe-area-inset-bottom)); background: var(--panel); }

.chips { max-width: var(--rail); margin: 0 auto 10px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.chip { flex: none; padding: 6px 13px; border-radius: 6px; background: var(--pine-soft); color: var(--pine); font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.chip:hover { background: var(--pine); color: var(--on-pine); }
.chip:first-child { background: var(--brass); color: var(--brass-ink); }

.compose-row, .record-row { max-width: var(--rail); margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; }

#input {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 132px;
  background: var(--stone);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
  padding: 10px 14px;
}
#input::placeholder { color: var(--muted); }
#input:focus { outline: none; border-color: var(--pine); }

.icon-btn { flex: none; color: var(--muted); display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { color: var(--ink); background: var(--panel-2); }

.icon-btn.round { width: 42px; height: 42px; background: var(--stone); border: 1px solid var(--line); }
.icon-btn.round.primary { background: var(--pine); border-color: var(--pine); color: var(--on-pine); }
.icon-btn.round.primary:hover { background: var(--pine-deep); }

.record-row { align-items: center; }

#wave { flex: 1; min-width: 0; height: 44px; background: var(--stone); border: 1px solid var(--pine); border-radius: 10px; }

#rec-time { color: var(--pine); font-size: 13px; font-variant-numeric: tabular-nums; min-width: 38px; text-align: center; }

#rec-cancel:hover { color: var(--clay); }

.voice { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.vp-btn { flex: none; width: 32px; height: 32px; border-radius: 50%; background: rgba(255, 255, 255, 0.2); display: grid; place-items: center; }
.vp-btn svg { width: 14px; height: 14px; }
.vp-track { flex: 1; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.3); overflow: hidden; }
.vp-fill { height: 100%; width: 0; background: currentColor; }
.vp-time { font-size: 12px; font-variant-numeric: tabular-nums; opacity: 0.8; }
.transcript { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.25); font-size: 13.5px; font-style: italic; opacity: 0.9; }

/* ---------- Listings sheet ---------- */

.sheet { position: fixed; inset: 0; z-index: 10; display: flex; justify-content: flex-end; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(15, 25, 21, 0.5); animation: fade 0.2s ease-out; }
@keyframes fade { from { opacity: 0; } }

.sheet-panel {
  position: relative;
  width: min(520px, 100%);
  height: 100%;
  background: var(--stone);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: slide-in 0.25s ease-out;
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }

.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 16px 16px 6px 20px; background: var(--panel); }
.sheet-head h2 { font-size: 30px; color: var(--pine); }
.sheet-count { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

.filter-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px 12px; background: var(--panel); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tabs button { flex: none; padding: 5px 12px; border-radius: 6px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.filter-tabs button[aria-pressed="true"] { background: var(--pine); color: var(--on-pine); }

.sheet-body { flex: 1; overflow-y: auto; padding: 16px 20px 28px; display: flex; flex-direction: column; gap: 14px; }
.sheet-body .listing { flex: none; }
.sheet-note { color: var(--muted); padding-top: 8px; }

/* ---------- Agent dashboard ---------- */

body.admin { min-height: 100%; }
body.admin .topbar { position: sticky; top: 0; z-index: 2; }

.admin-main { max-width: 960px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 28px) 64px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stats div { background: var(--panel); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.stats strong { font-family: "Gloock", Georgia, serif; font-weight: 400; font-size: 28px; line-height: 1.1; color: var(--pine); font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: 13.5px; }

.admin-tabs { display: flex; align-items: center; gap: 6px; margin: 28px 0 8px; }
.admin-tabs button { padding: 7px 16px; border-radius: 6px; font-weight: 600; color: var(--muted); }
.admin-tabs button[aria-selected="true"] { background: var(--pine); color: var(--on-pine); }
.refreshed { margin-left: auto; color: var(--muted); font-size: 13px; }

.day { font-size: 22px; margin: 26px 0 8px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row.dim { opacity: 0.55; }
.row-main { display: flex; gap: 16px; min-width: 0; }
.row-time { flex: none; width: 76px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--pine); }
.row-title { font-weight: 600; }
.row-sub { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.row-sub a { color: inherit; }
.muted { color: var(--muted); font-weight: 400; }

.status-select { flex: none; font: inherit; font-size: 14px; font-weight: 600; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.status-select.s-confirmed, .status-select.s-new { border-color: var(--pine); color: var(--pine); }
.status-select.s-contacted, .status-select.s-matched { border-color: var(--brass); }
.status-select.s-cancelled, .status-select.s-no_show { color: var(--clay); }

.empty { color: var(--muted); padding: 32px 0; }

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row { flex-direction: column; align-items: stretch; gap: 8px; }
  .row-time { width: 64px; }
  .status-select { align-self: flex-end; }
}

@media (max-width: 520px) {
  .topbar .wordmark.sm { font-size: 20px; }
  .topbar-id { flex-direction: column; gap: 2px; }
  .msg { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
  .contours.busy { animation: none; opacity: 0.6; }
  .msg.typing i { animation: none; opacity: 0.7; }
  .card, .sheet-panel, .sheet-scrim { animation: none; }
}
