/* Back-office layout (TSplus design): navy header bar with the on-navy logo, cream page ground, white cards. */
body.admin { background: var(--surface); }
.admin-header {
  display: flex; align-items: center; gap: 24px; padding: 0 40px; min-height: 68px; background: var(--navy); color: #fff;
  box-shadow: 0 2px 12px rgba(27, 42, 65, .25);
}
.admin-header :focus-visible { outline-color: #fff; box-shadow: 0 0 0 5px rgba(240, 130, 31, .7); }
.admin-header .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; font-size: 19px; padding: 6px 0; }
.admin-header .brand:hover { color: #fff; }
.admin-header .brand img { display: block; width: 36px; height: 36px; }
.admin-nav { display: flex; gap: 6px; flex: 1; margin-left: 12px; }
.admin-nav a { text-decoration: none; color: var(--peach); font-weight: 600; padding: 8px 16px; border-radius: var(--radius-pill); transition: background-color .15s ease; }
.admin-nav a:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.admin-nav a.active { background: var(--brand); color: var(--navy); }
.admin-tsplus { display: block; width: auto; opacity: .95; }
.admin-account { display: flex; gap: 16px; align-items: center; }
.admin-account a { color: #fff; text-decoration: none; font-weight: 600; padding: 4px 8px; border-radius: var(--radius-sm); }
.admin-account a:hover, .admin-account a.active { color: var(--peach); background: rgba(255, 255, 255, .10); }
.admin-account .link-button { color: var(--peach); }
.admin-account .link-button:hover { color: #fff; }
.admin-main { max-width: 1200px; margin: 0 auto; padding: 40px; }

.page-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-header .badge { font-size: 14px; letter-spacing: 0; }

table.data { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); overflow: hidden; }
table.data th, table.data td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-tint); }
table.data th { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); background: var(--surface-tint); white-space: nowrap; }
table.data td a { font-weight: 600; }
table.data .help { margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
td.actions { display: table-cell; white-space: nowrap; }
td.actions a { margin-right: 12px; }
.form-narrow { max-width: 560px; }
.card dl { margin: 0; }
.card dt { color: var(--ink-soft); font-weight: 600; font-size: 13px; }
.card dd { margin: 0; }

/* Login */
body.login-page { background: var(--surface); }
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 420px; padding: 40px 32px 28px; margin: 0; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; font-size: 22px; }
.login-brand img { width: 48px; height: 48px; display: block; }
.login-card h1 { font-size: 28px; margin-bottom: 24px; }
.login-submit { width: 100%; margin-top: 8px; padding: 12px 20px; font-size: 15px; }
.login-footer { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; color: var(--ink-soft); font-size: 13px; }
.login-footer img { display: block; height: 40px; width: auto; }
.field.checkbox label { font-weight: 400; display: flex; gap: 8px; align-items: center; font-size: 15px; }
.field.checkbox input { width: auto; accent-color: var(--brand-text); }
.temp-password { display: inline-block; margin-top: 4px; padding: 2px 8px; background: var(--surface-raised); border: 1px dashed var(--brand-text); border-radius: var(--radius-sm); user-select: all; font-weight: 700; }
.status-page { max-width: 520px; margin: 0 auto; text-align: left; }
.status-code { font-size: 64px; font-weight: 700; letter-spacing: -.03em; line-height: 1; margin: 0 0 8px; color: var(--navy); }

@media (max-width: 900px) { .admin-tsplus { display: none; } }
@media (max-width: 720px) {
  .admin-header { flex-wrap: wrap; gap: 8px 16px; padding: 12px 16px; }
  .admin-nav { order: 3; flex-basis: 100%; margin-left: 0; flex-wrap: wrap; gap: 6px; }
  .admin-nav a { white-space: nowrap; padding: 6px 12px; font-size: 15px; }
  .admin-account { margin-left: auto; }
  .admin-main { padding: 24px 16px; }
  h1 { font-size: 28px; }
  table.data { display: block; overflow-x: auto; }
}

/* Long URLs wrap anywhere instead of forcing a 1-character column. */
table.data .cell-url { overflow-wrap: anywhere; min-width: 16rem; }

/* Small screens: each row becomes a card, one "label: value" line per cell; URLs take the full width. */
@media (max-width: 760px) {
  table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; width: 100%; }
  table.data.stack thead { display: none; }
  table.data.stack tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  table.data.stack tbody tr:last-child { border-bottom: 0; }
  table.data.stack td { border: 0; padding: 3px 0; display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: 8px; }
  table.data.stack td::before { content: attr(data-label); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); padding-top: 2px; }
  table.data.stack td.cell-url { grid-template-columns: 1fr; min-width: 0; gap: 2px; }
  table.data.stack td.cell-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; }
  table.data.stack td.cell-actions::before { content: none; }
  table.data.stack td:empty { display: none; }
  table.data.stack tbody tr:hover td { background: none; }
}

/* Conversations */
.filters .filters-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 2fr); gap: 0 16px; }
.filters .field { margin-bottom: 12px; }
.filters .help { margin: 12px 0 0; }
.pager { margin-top: 1rem; align-items: center; }
.muted { color: var(--ink-soft); margin: 0; }
.transcript { display: flex; flex-direction: column; gap: 12px; max-width: 860px; }
.transcript-msg { margin: 0; padding: 16px 20px; }
.transcript-msg.is-visitor { background: var(--surface-tint); border-color: var(--peach); align-self: flex-end; max-width: 85%; }
.transcript-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.transcript-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.transcript-sources { margin: 10px 0 0; padding-left: 1.5rem; font-size: 14px; }
@media (max-width: 760px) {
  .filters .filters-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .filters .filters-search { grid-column: 1 / -1; }
  .transcript-msg.is-visitor { max-width: 100%; }
}

/* Customization */
.customization-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.customization-grid .card { margin: 0; }
.customization-grid textarea { min-height: 260px; resize: vertical; line-height: 1.5; }
.customization-grid h2 { margin-top: 0; font-size: 20px; }
.test-answer { margin-top: 16px; padding: 14px 16px; background: var(--surface-tint); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.test-answer p { margin: 0 0 8px; }
.test-answer p:last-child { margin-bottom: 0; }
.test-sources { margin: 6px 0 0; padding-left: 1.5rem; font-size: 14px; }
#test-result > strong { display: block; margin-top: 12px; }
#test-prompt { margin-top: 14px; }
#test-prompt summary { cursor: pointer; color: var(--brand-text); font-weight: 600; }
.prompt-preview { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; max-height: 360px; overflow: auto; }
@media (max-width: 960px) { .customization-grid { grid-template-columns: 1fr; } }

/* Analytics */
.flag { display: inline-block; width: 20px; height: 15px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(55, 41, 31, .12); vertical-align: -2px; object-fit: cover; }
.flag-spacer { display: inline-block; width: 20px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--radius-pill); background: var(--chip-neutral); color: var(--ink); font-size: 14px; font-weight: 600; text-decoration: none; border: 1px solid transparent; }
a.chip:hover { border-color: var(--brand); text-decoration: none; }
.chip.active { background: var(--brand); color: var(--ink-on-brand); }
.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.range-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filters .filters-submit { display: flex; align-items: flex-end; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 8px; }
.kpi { margin: 0; display: flex; flex-direction: column; gap: 4px; color: var(--ink); text-decoration: none; }
a.kpi:hover { border-color: var(--brand); text-decoration: none; }
.kpi-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.kpi-value { font-size: 34px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-note { font-size: 13px; color: var(--ink-soft); }
.chart-card h2, .analytics-grid h2 { font-size: 18px; margin: 0 0 12px; }
.chart-card h2 .help { font-weight: 400; font-size: 14px; }
.chart-time { width: 100%; height: 220px; display: block; overflow: visible; }
.chart-time .bar { fill: var(--brand); }
.chart-time .bar:hover { fill: var(--brand-strong); }
.chart-time .grid { stroke: var(--sand); stroke-width: 1; }
.chart-time .baseline { stroke: var(--input-border); stroke-width: 1; }
.chart-time .axis { fill: var(--ink-soft); font-size: 11px; font-family: var(--font); }
.analytics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.analytics-grid .card { margin: 0; }
.analytics-grid .span-2 { grid-column: 1 / -1; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bars li { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) 6.5rem; align-items: center; gap: 12px; font-size: 14px; }
.bars-2col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 32px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-label .code { color: var(--ink-soft); font-size: 12px; }
.bar-track { height: 10px; background: var(--surface-tint); border-radius: var(--radius-pill); overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); }
.bar-fill { display: block; height: 100%; background: var(--brand); border-radius: var(--radius-pill); }
.bar-fill.navy { background: var(--navy); }
.bar-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-pct { font-weight: 400; color: var(--ink-soft); font-size: 12px; margin-left: 4px; }
.stack-bar { display: flex; height: 14px; border-radius: var(--radius-pill); overflow: hidden; margin-bottom: 16px; background: var(--surface-tint); }
.stack-bar .seg { display: block; height: 100%; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: 0; }
.sentiment-positive { background: var(--positive); }
.sentiment-neutral { background: #8B97A6; }
.sentiment-frustrated { background: var(--negative); }
.sentiment-confused { background: var(--brand-light); }
.badge.sentiment-positive { background: var(--positive-bg); color: var(--positive-strong); }
.badge.sentiment-neutral { background: var(--chip-neutral); color: var(--ink-soft); }
.badge.sentiment-frustrated { background: var(--negative-bg); color: var(--negative); }
.badge.sentiment-confused { background: var(--peach); color: var(--ink); }
.insight-card { max-width: 860px; margin-bottom: 16px; }
.insight-card dl { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 24px; }
.insight-card .keywords { display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analytics-grid, .bars-2col { grid-template-columns: 1fr; }
  .insight-card dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .bars li { grid-template-columns: minmax(0, 1fr) 5.5rem; }
  .bars .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .kpi-value { font-size: 28px; }
}
.insight-card .span-3 { grid-column: span 3; }
.insight-card .span-4 { grid-column: 1 / -1; }
@media (max-width: 960px) { .insight-card .span-3 { grid-column: 1 / -1; } }
.filters input[type="date"] { min-width: 0; width: 100%; }
.chart-scroll { overflow-x: auto; }
@media (max-width: 720px) { .chart-time { min-width: 640px; } }
.filters .field { min-width: 0; }

/* Conversation deletion */
form.inline { display: inline; margin: 0; }
button.small { padding: 6px 12px; font-size: 13px; }
button.danger-outline { background: transparent; border-color: var(--negative); color: var(--negative); }
button.danger-outline:hover { background: var(--negative); border-color: var(--negative); color: #fff; box-shadow: none; }
td.cell-actions { text-align: right; white-space: nowrap; }
.page-header .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
table.data.stack td.cell-actions { justify-content: flex-start; }

/* Conversations table: smaller text so the date and the channel stay on one line */
table.data.conversations-table td { font-size: 13px; padding: 10px 12px; }
table.data.conversations-table th { font-size: 11px; padding: 10px 12px; }
table.data.conversations-table .badge { font-size: 11px; }
table.data.conversations-table td.nowrap { white-space: nowrap; }
