/* Trines indbakke — rent, lyst, venligt. Én accentfarve: støvet rosa. */

:root {
  --accent: #b66880;          /* støvet rosa */
  --accent-dark: #9a4f68;
  --accent-soft: #f6e7ec;
  --accent-softer: #fbf3f6;
  --bg: #faf8f7;
  --card: #ffffff;
  --text: #3a3340;
  --text-dim: #8a8090;
  --border: #eee5e9;
  --green: #4a9d6b;
  --green-soft: #e8f4ed;
  --yellow: #d9a13b;
  --yellow-soft: #faf2e0;
  --red: #c75454;
  --red-soft: #fbe9e9;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(58, 51, 64, 0.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

.hidden { display: none !important; }

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-dark);
  text-decoration: none;
}

.pending-badge {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}
.pending-badge:empty { display: none; }

.topbar nav { margin-left: auto; }

.status-link {
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
}
.status-link:hover { background: var(--accent-softer); color: var(--accent-dark); }

/* ---------- layout ---------- */

.layout {
  display: flex;
  gap: 18px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px;
  align-items: flex-start;
}

.list-pane { flex: 0 0 340px; min-width: 0; }
.detail-pane { flex: 1; min-width: 0; }

/* Mobil (én rude ad gangen) ligger samlet nederst i filen. */
.btn-back, .btn-next { display: none; }

/* ---------- kort ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
}

.welcome-card h2, .empty-card p { margin-top: 0; }
.welcome-card p { color: var(--text-dim); }
.empty-card { text-align: center; color: var(--text-dim); }

.kill-note {
  background: var(--red-soft);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
}
.kill-note a { color: var(--red); }

/* ---------- liste ---------- */

.inbox-list { list-style: none; margin: 0; padding: 0; }

.inbox-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.12s, transform 0.06s;
}
.inbox-item:hover { border-color: var(--accent); }
.inbox-item:active { transform: scale(0.99); }
.inbox-item.kind-escalation { border-left: 4px solid var(--red); }
.inbox-item.kind-question { border-left: 4px solid var(--yellow); }

.row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.client-name { font-weight: 700; }
.item-time { color: var(--text-dim); font-size: 0.8rem; white-space: nowrap; }

.row-bottom {
  display: block;
  margin-top: 5px;
}
.item-excerpt {
  display: block;
  color: var(--text-dim);
  font-size: 0.88rem;
  margin-top: 4px;
}

.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 1px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- forslags-kort ---------- */

.proposal-card {
  background: var(--accent-softer);
  border-color: var(--accent-soft);
}
.proposal-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.proposal-text { margin: 0 0 10px; font-weight: 500; }
.proposal-options { display: flex; flex-wrap: wrap; gap: 8px; }
.proposal-answered { opacity: 0.85; }

/* ---------- detalje / chat ---------- */

.detail-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.detail-header h2 { margin: 0; font-size: 1.2rem; }

.chat-scroll {
  max-height: 46vh;
  overflow-y: auto;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble-row { display: flex; flex-direction: column; max-width: 78%; }
.bubble-row.from-client { align-self: flex-start; align-items: flex-start; }
.bubble-row.from-trine { align-self: flex-end; align-items: flex-end; }

.bubble {
  padding: 9px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
}
.from-client .bubble {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.from-trine .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}

/* Billede, video og lydbesked i samtalen. Fast højde, så chatten kan scrolles ned før billedet er hentet. */
.bubble-media { white-space: normal; padding: 5px; }
.bubble-media img { display: block; height: 220px; max-width: 100%; object-fit: contain; border-radius: 12px; }
.bubble-media video { display: block; width: 280px; max-width: 100%; height: 200px; border-radius: 12px; background: #000; }
.bubble-media audio { display: block; width: 260px; max-width: 100%; }
.media-caption { white-space: pre-wrap; padding: 6px 8px 2px; }
.media-fallback { display: none; white-space: pre-wrap; padding: 4px 8px; }
.media-fallback small { display: block; opacity: 0.75; font-size: 0.78rem; margin-top: 3px; }
.media-fejl .media-el, .media-fejl .media-caption { display: none; }
.media-fejl .media-fallback { display: block; }

.bubble-time {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 2px;
  padding: 0 4px;
}

.new-message { margin-top: 6px; }
.new-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
}
.bubble-new {
  border: 2px solid var(--accent) !important;
  background: var(--accent-softer) !important;
}

/* ---------- udkast ---------- */

.draft-box, .escalation-box { margin-top: 16px; }

.draft-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 8px;
}

.conf {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 12px;
}
.conf .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.conf-high { background: var(--green-soft); color: var(--green); }
.conf-high .dot { background: var(--green); }
.conf-mid { background: var(--yellow-soft); color: var(--yellow); }
.conf-mid .dot { background: var(--yellow); }
.conf-low { background: var(--red-soft); color: var(--red); }
.conf-low .dot { background: var(--red); }

textarea, input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
  color: inherit;
  background: var(--card);
  resize: none;
}
textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.why-wrap { margin-top: 8px; }
.why-wrap input { font-size: 0.9rem; }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* ---------- knapper ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  transition: filter 0.12s, transform 0.06s;
}
.btn:hover { filter: brightness(0.95); }
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--green); color: #fff; }
.btn-secondary { background: var(--accent); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--bg); }

.btn-chip {
  background: var(--card);
  color: var(--accent-dark);
  border: 1px solid var(--accent-soft);
  padding: 7px 14px;
  font-size: 0.88rem;
}
.btn-chip:hover { background: var(--accent-soft); }

/* Når udkastet er ændret: fremhæv "Ret & send" frem for "Send" */
form.is-edited .btn-send { opacity: 0.45; }
form.is-edited .btn-edit-send { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- spørgsmål & eskalering ---------- */

.soft-flags { margin-top: 16px; background: var(--yellow-soft); border-left: 4px solid var(--yellow); border-radius: 10px; padding: 10px 14px; }
.soft-flags-intro { margin: 0 0 4px; font-weight: 600; font-size: 0.9rem; }
.soft-flags ul { margin: 0; padding-left: 18px; }
.soft-flags li { font-size: 0.9rem; line-height: 1.4; }
.lint-note { margin: 8px 0 0; color: var(--text-dim); font-size: 0.8rem; line-height: 1.4; }
.attach-icon { margin-left: 4px; font-size: 0.85rem; }

.escalation-banner {
  background: var(--red-soft);
  color: var(--red);
  font-weight: 700;
  font-size: 1.05rem;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.escalation-reason { color: var(--text-dim); }

/* ---------- kvittering ---------- */

.resolved-card { text-align: center; padding: 38px 24px; }
.resolved-icon { font-size: 2.4rem; }
.resolved-headline { margin: 10px 0 4px; font-size: 1.2rem; }
.resolved-sub { color: var(--text-dim); margin: 0 0 14px; }
.resolved-next { color: var(--text-dim); font-size: 0.9rem; margin-top: 22px; }
.outcome-blocked .resolved-headline { color: var(--accent-dark); }
.outcome-sent .resolved-headline { color: var(--green); }
.outcome-failed { border: 2px solid var(--red); background: var(--red-soft); }
.outcome-failed .resolved-headline { color: var(--red); }

.flash {
  border-radius: 10px;
  padding: 12px 16px;
  margin: 10px 0;
  font-weight: 600;
}
.flash-warn { background: var(--yellow-soft); color: var(--yellow); }

.done-card { text-align: center; color: var(--text-dim); }

/* ---------- status-side ---------- */

.status-page { flex: 1; max-width: 720px; margin: 0 auto; }

.kill-card { text-align: center; padding: 26px 22px; }
.kill-card h2 { margin-top: 0; }
.kill-card p { color: var(--text-dim); }
.kill-card.is-killed { border-color: var(--red); background: var(--red-soft); }
.kill-card.is-killed p { color: var(--text); }

.btn-kill {
  background: var(--red);
  color: #fff;
  font-size: 1.05rem;
  padding: 14px 28px;
}
.btn-reopen {
  background: var(--green);
  color: #fff;
  font-size: 1.05rem;
  padding: 14px 28px;
}

.autonomy-list, .event-list { list-style: none; margin: 0; padding: 0; }
.autonomy-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.autonomy-list li:last-child { border-bottom: none; }
.autonomy-cat { font-weight: 700; }
.autonomy-mode { color: var(--text-dim); }
.autonomy-mode.mode-auto { color: var(--green); font-weight: 600; }
.autonomy-mode.mode-candidate { color: var(--yellow); font-weight: 600; }

.event-list li {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
}
.event-list li:last-child { border-bottom: none; }
.event-time {
  color: var(--text-dim);
  font-size: 0.82rem;
  white-space: nowrap;
  flex: 0 0 110px;
}
.event-label { font-size: 0.92rem; }

.status-page a { color: var(--accent-dark); }

/* on-demand hentning */
.fetch-card { display: flex; flex-direction: column; gap: 6px; padding: 14px; }
.btn-fetch {
  background: var(--accent, #c4789a); color: #fff; border: none;
  padding: 12px 16px; border-radius: 12px; font-size: 1.05rem; font-weight: 600;
  cursor: pointer; width: 100%;
}
.btn-fetch:hover { filter: brightness(0.95); }
.fetch-status { font-weight: 600; }
.fetch-last { color: #888; }
/* Et fejlet run må ALDRIG se ud som et roligt "intet nyt". */
.fetch-warn { color: #b3261e; font-weight: 600; display: block;
              margin-top: 6px; line-height: 1.45; max-width: 46em; }

/* Den automatiske hentning: login virker ikke, så listen ikke ligner en tom indbakke. */
.down-banner { border: 2px solid var(--red); background: var(--red-soft); color: #8a2d2d;
               font-weight: 600; line-height: 1.45; }
/* Kortets udkast er skrevet om, fordi klienten skrev igen. */
.redraft-note { margin: 12px 0 0; padding: 8px 12px; border-radius: 10px; font-size: 0.9rem;
                background: var(--accent-softer); color: var(--accent-dark); font-weight: 600; }
.kept-text summary { cursor: pointer; font-weight: 600; margin-top: 6px; }
.kept-text pre { white-space: pre-wrap; font: inherit; margin: 6px 0 0; }

/* ---------- mobil: iPhone først ----------
   Listen og samtalen vises én ad gangen. body.vis-samtale (sat i base.html) lægger
   samtalen over listen i fuld skærm; .detail-pane scroller historikken, navnet står
   fast øverst og svarfeltet fast nederst over tastaturet (--vv-h fra visualViewport). */

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: 2px 10px;
    padding: calc(env(safe-area-inset-top) + 6px) max(12px, env(safe-area-inset-right))
             4px max(12px, env(safe-area-inset-left));
  }
  .brand { min-height: 44px; display: inline-flex; align-items: center; }
  .topbar nav { margin-left: 0; width: 100%; display: flex; }
  .status-link {
    flex: 1;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 8px;
  }

  .layout {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 12px max(12px, env(safe-area-inset-right))
             calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .list-pane { flex: 1 1 auto; width: 100%; }
  .status-page { width: 100%; min-width: 0; } /* ellers gør månedstabellen siden bredere end skærmen */
  .btn, .btn-chip { min-height: 44px; }
  .why-wrap input { font-size: 16px; } /* under 16px zoomer iOS ind ved fokus */

  /* Listen: velkomstkortet står over listen og viser kun stop- og læringsnoterne. */
  .detail-pane { width: 100%; order: -1; }
  body:not(.vis-samtale) .detail-pane:not(:has(.welcome-card)) { display: none; }
  .welcome-card h2, .welcome-card > p:not([class]) { display: none; }
  .welcome-card:not(:has(.kill-note, .learning-note)) { display: none; }
  .welcome-card { padding: 4px 14px; }
  .welcome-card p { margin: 8px 0; }

  /* Samtalen */
  body.vis-samtale { overflow: hidden; }
  body.vis-samtale .detail-pane {
    position: fixed;
    left: 0;
    right: 0;
    top: var(--vv-top, 0px);
    height: var(--vv-h, 100dvh);
    z-index: 20;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    display: flex;
    flex-direction: column;
  }
  body.vis-samtale .btn-back {
    display: inline-flex;
    align-items: center;
    position: fixed;
    top: calc(var(--vv-top, 0px) + env(safe-area-inset-top) + 6px);
    left: max(4px, env(safe-area-inset-left));
    z-index: 21;
    min-height: 44px;
    padding: 0 12px 0 8px;
    border: none;
    background: none;
    font: inherit;
    font-size: 1.05rem;
    color: var(--accent-dark);
    cursor: pointer;
  }
  /* Kvittering og andre korte svar: fri af tilbage-knappen */
  body.vis-samtale .detail-pane > .card:not(.detail-card),
  body.vis-samtale .detail-pane > .flash {
    margin: calc(env(safe-area-inset-top) + 64px) 12px 12px;
  }
  .resolved-next { display: none; }
  .btn-next { display: inline-flex; align-items: center; margin-top: 18px; }

  .detail-card {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  .detail-card .detail-header {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0;
    gap: 2px 8px;
    min-height: calc(env(safe-area-inset-top) + 56px);
    padding: calc(env(safe-area-inset-top) + 8px) max(12px, env(safe-area-inset-right)) 8px 112px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    align-items: center;
  }
  .detail-card .detail-header h2 { font-size: 1.05rem; width: 100%; }
  .detail-card .chat-scroll {
    flex: 1 0 auto;
    max-height: none;
    overflow: visible;
    border: none;
    border-radius: 0;
    padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
  }
  .detail-card .bubble-row { max-width: 82%; }
  .detail-card .escalation-box, .detail-card .soft-flags, .detail-card .redraft-note { margin: 0 12px 12px; }
  .detail-card .escalation-banner { font-size: 0.95rem; padding: 10px 12px; margin-bottom: 4px; }
  .detail-card .escalation-reason { margin: 0 0 4px; font-size: 0.9rem; }

  /* Svarfeltet: sammenfoldet viser det de første linjer, med fokus hele udkastet. */
  .detail-card .draft-box {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 0;
    padding: 6px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom))
             max(12px, env(safe-area-inset-left));
    background: var(--card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(58, 51, 64, 0.06);
  }
  .detail-card .draft-box:focus-within { padding-bottom: 8px; } /* tastaturet dækker hjem-stregen */
  .detail-card .draft-label { margin-bottom: 4px; font-size: 0.9rem; }
  .detail-card .draft-label .conf { font-size: 0.8rem; padding: 2px 10px; }
  .detail-card .draft-text {
    max-height: calc(3lh + 22px);
    overflow-y: auto;
    padding: 10px 12px;
  }
  .detail-card .draft-box:focus-within .draft-text { max-height: calc(var(--vv-h, 100dvh) * 0.4); }
  .detail-card .draft-box:focus-within .lint-note { display: none; }
  .detail-card .why-wrap { margin-top: 6px; }
  .detail-card .actions { flex-wrap: nowrap; gap: 6px; margin-top: 8px; }
  .detail-card .actions .btn { flex: 1 1 auto; padding: 8px 10px; white-space: nowrap; }
  .detail-card .lint-note { margin-top: 6px; }
}

/* ---------- login (kun den hostede udgave) ---------- */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 6px; }
.login-card .brand { font-size: 1.35rem; margin: 4px 0 12px; text-align: center; }
.login-card label { font-weight: 600; font-size: 0.95rem; margin-top: 8px; }
.login-card input {
  font: inherit;
  font-size: 16px; /* under 16px zoomer iOS ind ved fokus */
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-btn { min-height: 48px; margin-top: 18px; }
.login-error { margin: 0 0 4px; }
.logout-form { margin-top: 10px; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.action-help { margin: 6px 0 0; color: var(--text-dim); font-size: 0.8rem; line-height: 1.4; }
.detail-card .actions-secondary { flex-wrap: wrap; }
.detail-card .actions-secondary .btn { flex: 1 1 auto; white-space: normal; }
.detail-card .detail-status { margin: 12px; }
