/*
 * The admin stylesheet.
 *
 * A plain file served by src/http/static.ts and linked from src/ui/layout.ts —
 * no bundler, no PostCSS, no build step (docs/ADR.md ADR-008). It is a single
 * file on purpose: the whole UI is a dozen pages, and one request that a browser
 * caches is fewer moving parts than a pipeline that can fail.
 */

:root {
  color-scheme: light dark;
}

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #f6f7f9;
  color: #16181d;
}

/* ---- shell ------------------------------------------------------------- */

header.app {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: #16181d;
  color: #f6f7f9;
}

header.app a {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}

header.app .brand {
  font-size: 1rem;
  letter-spacing: 0.01em;
}

header.app .spacer {
  flex: 1;
}

header.app .operator {
  opacity: 0.75;
  font-size: 0.85rem;
}

header.app .signout button {
  background: transparent;
  color: inherit;
  border: 1px solid #5b6270;
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}

nav.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  margin: 0;
  padding: 0.6rem 1.25rem;
  background: #22262e;
  color: #dfe3ea;
  font-size: 0.9rem;
}

nav.app-nav a {
  color: inherit;
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  opacity: 0.8;
}

nav.app-nav a:hover {
  background: #2f343e;
  opacity: 1;
}

nav.app-nav a[aria-current="page"] {
  background: #2f343e;
  opacity: 1;
  font-weight: 600;
}

main {
  max-width: 62rem;
  margin: 1.5rem auto;
  padding: 0 1.25rem;
}

/* ---- list filter tabs --------------------------------------------------- */

nav.list-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
}

nav.list-filter a {
  color: #1f6feb;
  text-decoration: none;
  padding: 0.25rem 0.7rem;
  border: 1px solid #d5dae1;
  border-radius: 999px;
}

nav.list-filter a:hover {
  background: #f1f4f8;
}

nav.list-filter a[aria-current="page"] {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
  font-weight: 600;
}

/* ---- surfaces ---------------------------------------------------------- */

.card {
  background: #fff;
  border: 1px solid #e3e6ea;
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card h1,
.card h2 {
  margin-top: 0;
}

.error {
  background: #fff1f0;
  border: 1px solid #f4c7c3;
  color: #a5120a;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 1rem;
}

.notice {
  background: #eef6ee;
  border: 1px solid #bfe0bf;
  color: #14531f;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 1rem;
}

.muted {
  color: #5b6270;
  font-size: 0.85rem;
}

/* ---- forms ------------------------------------------------------------- */

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="url"],
input[type="number"],
textarea,
select {
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.65rem;
  border: 1px solid #c9ced6;
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: inherit;
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid #1f6feb;
  outline-offset: 1px;
}

button.primary {
  background: #1f6feb;
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

form.inline {
  display: inline-block;
  margin-right: 0.5rem;
}

.voice-picker-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

form[data-voice-preview] {
  display: none;
}

button[data-voice-preview-play]:disabled {
  opacity: 0.6;
  cursor: wait;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

span.days {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.4rem 0;
}

label.day {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 400;
}

label.day input {
  width: auto;
}

/* ---- data ------------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid #eceff2;
  vertical-align: top;
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #5b6270;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: #eceff2;
  color: #3d4350;
}

.badge[data-status="active"] {
  background: #e4f3e6;
  color: #14531f;
}

.badge[data-status="paused"] {
  background: #fdf0dc;
  color: #7a4a06;
}

.badge[data-status="archived"] {
  background: #eceff2;
  color: #5b6270;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background: #f1f3f6;
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
}

[data-simulate-when-fieldset] {
  border: 0;
  padding: 0;
  margin: 0 0 0.75rem;
  min-width: 0;
}

[data-simulate-when-fieldset] legend {
  font-weight: 600;
  margin-bottom: 0.35rem;
  padding: 0;
}

[data-simulate-when-choice] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.65rem;
  font-weight: 400;
  margin-bottom: 0.4rem;
}

[data-simulate-when-choice] input[type="radio"],
[data-simulate-when-choice] input[type="time"] {
  width: auto;
}

[data-simulate-when-choice] input[type="time"] {
  box-sizing: border-box;
  padding: 0.4rem 0.5rem;
  border: 1px solid #c9ced6;
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

[data-simulate-when-other] {
  margin: 0.35rem 0 0;
}

/* ---- simulate preview -------------------------------------------------- */

/*
 * The recovery preview is a <pre> so template newlines survive. A bare <pre>
 * is `white-space: pre`, which also refuses to wrap at spaces — a long
 * business name set the card's min-content width and spilled past it.
 * `pre-wrap` keeps the newlines and wraps the sentence; `overflow-wrap` /
 * `word-break` break a token with no spaces. `min-width: 0` lets the card
 * shrink inside any flex/grid ancestor instead of forcing the page wider.
 */
[data-simulate-preview] {
  max-width: 100%;
  min-width: 0;
}

.simulate-preview-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  min-width: 0;
  font: inherit;
}

/* ---- conversation messages --------------------------------------------- */

/*
 * A message body is a <pre> so an agent's newlines survive. A bare <pre> is
 * `white-space: pre`, which also refuses to wrap at spaces — a recovery text
 * with a long business name set the card's min-content width and pushed the
 * page into a horizontal scroll. `pre-wrap` keeps the newlines and wraps the
 * long line; `overflow-wrap: anywhere` breaks a token with no spaces in it, so
 * a URL or a bare E.164 cannot set a floor under the width either.
 */
.message-body {
  margin: 0.35rem 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  max-width: 100%;
}

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

.messages li.message {
  display: block;
  max-width: 100%;
  padding: 0.6rem 0;
  border-bottom: 1px solid #eceff2;
}

.messages li.message:last-child {
  border-bottom: 0;
}

/* A row's header line can carry a badge, a status and a timestamp. */
.messages li.message > .muted {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.6rem;
}

/* ---- calls row --------------------------------------------------------- */

/*
 * The phone numbers are the disclosure summary. Leave <details>'s own
 * display alone: overriding it drops the browser's disclosure box and the
 * notice paints over the next row. The summary keeps the column width; the
 * opened body uses width 0 / min-width 100% so a long notice wraps inside
 * the cell instead of widening it. The marker stays inside the summary so
 * it does not paint into the next column.
 */
.unread-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.35rem;
  border-radius: 999px;
  background: #c62828;
  vertical-align: middle;
}

table.calls [data-call-detail] {
  line-height: 1.5;
}

table.calls [data-call-detail]:not([open]) > :not(summary) {
  display: none;
}

table.calls [data-call-detail] > summary {
  cursor: pointer;
  line-height: 1.5;
  list-style-position: inside;
  color: inherit;
}

table.calls [data-call-detail] > summary [data-transfer-requested] {
  display: block;
  margin-top: 0.35rem;
}

table.calls [data-call-detail] > :not(summary) {
  width: 0;
  min-width: 100%;
}

/* ---- appointments calendar -------------------------------------------- */

table.calendar {
  table-layout: fixed;
}

table.calendar td {
  height: 5.5rem;
}

table.calendar td[data-outside] {
  color: #9aa1ad;
}

table.calendar a[data-appointment] {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

dialog[data-reschedule-dialog] {
  border: 1px solid #d7dbe2;
  border-radius: 8px;
  max-width: 28rem;
  width: calc(100% - 2rem);
  padding: 0.75rem 1rem;
  max-height: min(32rem, calc(100vh - 3rem));
  overflow: auto;
}

dialog[data-reschedule-dialog] h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

dialog[data-reschedule-dialog] form p {
  margin: 0.28rem 0;
}

dialog[data-reschedule-dialog] form label {
  margin-bottom: 0.08rem;
}

dialog[data-reschedule-dialog]::backdrop {
  background: rgb(20 24 32 / 35%);
}
