/**
 * CX Chat support console.
 *
 * DESIGN NOTES (deliberate, please do not "tidy" these away)
 *
 * - ONE accent, injected from settings as --cx-accent. Channel identity is a
 *   2px left rule, not a colour wash, so three tags in a row stay legible
 *   instead of turning into confetti.
 * - Status is a solid 7px dot plus plain text. Never a pale tinted pill with
 *   darker text of the same hue: that is the most recognisable AI-design tell
 *   and it reads as decoration rather than information.
 * - Separation is whitespace first, hairlines second. Never a border AND a
 *   shadow on the same element.
 * - No pure white, no pure black. This is a screen an agent stares at all day.
 * - 4px rhythm throughout.
 *
 * PSYCHOLOGY
 * - An agent's real job is triage, so the list is optimised for scanning, not
 *   for reading: face, then name, then the one line of preview. A face is
 *   recognised faster than a name is read.
 * - The WhatsApp 24 hour window is shown as a live countdown, because it is a
 *   real deadline with a real consequence (after it, only a template can be
 *   sent). Honest urgency, never invented urgency.
 * - The composer is the only filled button on the screen. Everything else is a
 *   quiet text action, so the eye always lands on "reply".
 * - Destructive and irreversible actions are never adjacent to Send.
 */

:root {
	--cx-accent: #0b6bcb;

	/* Warm-neutral greys. A true #fff panel against #000 text reads harsh and
	   unfinished after an hour, let alone a shift. */
	--cx-ink: #14181f;
	--cx-ink-soft: #5c6672;
	--cx-ink-faint: #8b95a1;
	--cx-line: #e4e7ea;
	--cx-panel: #fbfbfa;
	--cx-canvas: #f2f2ef;
	--cx-raised: #ffffff;

	--cx-live: #16a34a;
	--cx-warn: #b45309;
	--cx-danger: #b32d2e;
	--cx-read: #2f8fd0;

	--cx-r-sm: 6px;
	--cx-r-md: 10px;
}

@media (prefers-color-scheme: dark) {
	:root {
		--cx-ink: #edeef0;
		--cx-ink-soft: #9aa3ad;
		--cx-ink-faint: #6f7883;
		--cx-line: #2b3037;
		--cx-panel: #1c2025;
		--cx-canvas: #14171b;
		--cx-raised: #232830;
	}
}

* { box-sizing: border-box; }

html, body {
	height: 100%;
	margin: 0;
}

body {
	font: 15px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: var(--cx-ink);
	background: var(--cx-canvas);
	-webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
	font: inherit;
	color: inherit;
}

/* ---------------------------------------------------------------- Login */

.cx-login {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 100vh;
	padding: 24px;
}

.cx-login-card {
	width: 100%;
	max-width: 368px;
	padding: 36px 32px;
	background: var(--cx-panel);
	border-radius: 14px;
	/* One soft shadow to lift the card. No border as well. */
	box-shadow: 0 10px 36px rgba(20, 24, 31, 0.1);
}

.cx-login-logo {
	display: block;
	max-height: 44px;
	margin: 0 auto 24px;
}

.cx-login-card h1 {
	margin: 0 0 28px;
	font-size: 21px;
	font-weight: 600;
	letter-spacing: -0.01em;
	text-align: center;
}

.cx-login-card input {
	display: block;
	width: 100%;
	height: 46px;
	margin-bottom: 12px;
	padding: 0 14px;
	border: 1px solid var(--cx-line);
	border-radius: var(--cx-r-md);
	background: var(--cx-raised);
}

.cx-login-card input:focus {
	outline: 2px solid var(--cx-accent);
	outline-offset: -1px;
	border-color: transparent;
}

.cx-login-card button {
	width: 100%;
	height: 48px;
	margin-top: 4px;
	border: 0;
	border-radius: var(--cx-r-md);
	background: var(--cx-accent);
	color: #fff;
	font-weight: 600;
	cursor: pointer;
}

.cx-login-card button:hover { filter: brightness(0.94); }

/* ---------------------------------------------------------------- Shell */

.cx-app {
	display: grid;
	grid-template-columns: 352px 1fr;
	height: 100vh;
}

.cx-side {
	display: flex;
	flex-direction: column;
	min-height: 0;
	background: var(--cx-panel);
	border-right: 1px solid var(--cx-line);
}

.cx-side-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 18px 20px 14px;
}

.cx-brand {
	display: flex;
	align-items: center;
	gap: 10px;
	font-size: 16px;
	font-weight: 600;
	letter-spacing: -0.01em;
}

.cx-brand img {
	max-height: 26px;
	border-radius: var(--cx-r-sm);
}

.cx-side-foot {
	padding: 12px 20px;
	border-top: 1px solid var(--cx-line);
	color: var(--cx-ink-faint);
	font-size: 12px;
}

/* -------------------------------------------------------------- Filters */

.cx-filters { padding: 0 20px 14px; }

.cx-filters input {
	width: 100%;
	height: 40px;
	margin-bottom: 12px;
	padding: 0 14px;
	border: 1px solid var(--cx-line);
	border-radius: 999px;
	background: var(--cx-raised);
}

.cx-filters input:focus {
	outline: 2px solid var(--cx-accent);
	outline-offset: -1px;
	border-color: transparent;
}

.cx-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.cx-chip {
	height: 28px;
	padding: 0 12px;
	border: 1px solid var(--cx-line);
	border-radius: 999px;
	background: transparent;
	color: var(--cx-ink-soft);
	font-size: 12.5px;
	font-weight: 500;
	cursor: pointer;
}

.cx-chip:hover { border-color: var(--cx-ink-faint); }

/* An active chip inverts to a SOLID accent with white text. A real state change,
   not a tinted pill with same-hue text on it. */
.cx-chip.is-on {
	border-color: var(--cx-accent);
	background: var(--cx-accent);
	color: #fff;
	font-weight: 600;
}

/* --------------------------------------------------------------- Avatar */

.cx-avatar {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	object-fit: cover;
	background: var(--cx-line);
	color: #fff;
	font-size: 15px;
	font-weight: 600;
}

.cx-avatar-sm {
	width: 32px;
	height: 32px;
	font-size: 13px;
}

/* ----------------------------------------------------------------- List */

.cx-list {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
}

.cx-row {
	position: relative;
	display: grid;
	grid-template-columns: 40px 1fr;
	gap: 12px;
	width: 100%;
	padding: 12px 20px;
	border: 0;
	background: transparent;
	text-align: left;
	cursor: pointer;
}

.cx-row + .cx-row::before {
	content: "";
	position: absolute;
	top: 0;
	left: 72px;
	right: 20px;
	height: 1px;
	background: var(--cx-line);
}

.cx-row:hover { background: rgba(20, 24, 31, 0.03); }

.cx-row.is-active { background: rgba(20, 24, 31, 0.05); }

/* The selected row gets a spine in the accent, which registers in peripheral
   vision without the agent having to look for it. */
.cx-row.is-active::after {
	content: "";
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	width: 3px;
	background: var(--cx-accent);
}

.cx-row-main { min-width: 0; }

.cx-row-top {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 8px;
}

.cx-row-name {
	overflow: hidden;
	font-size: 14.5px;
	font-weight: 600;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.cx-row-time {
	flex: none;
	color: var(--cx-ink-faint);
	font-size: 11.5px;
}

.cx-row-bot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-top: 1px;
}

.cx-row-prev {
	overflow: hidden;
	color: var(--cx-ink-soft);
	font-size: 13px;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.cx-unread {
	flex: none;
	min-width: 20px;
	height: 20px;
	padding: 0 6px;
	border-radius: 999px;
	background: var(--cx-accent);
	color: #fff;
	font-size: 11.5px;
	font-weight: 600;
	line-height: 20px;
	text-align: center;
}

.cx-row-meta {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-top: 6px;
}

.cx-pin-dot { color: var(--cx-accent); }

.cx-empty {
	padding: 40px 20px;
	color: var(--cx-ink-faint);
	text-align: center;
}

/* ----------------------------------------------------------------- Tags */

/* Plain text with a channel-coloured rule. Not a filled pill: an agent reads
   three of these per row, and three filled pills is noise. */
.cx-tag {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 0 0 0 7px;
	border-left: 2px solid var(--cx-ink-faint);
	color: var(--cx-ink-soft);
	font-size: 11.5px;
	font-weight: 600;
	white-space: nowrap;
}

.cx-tag-whatsapp { border-left-color: #1f8f6f; }
.cx-tag-web      { border-left-color: #3a6fbf; }
.cx-tag-app      { border-left-color: #7a52b3; }

/* A human is on this chat: the one thing worth a solid fill in the list, and
   used at most once per row. */
.cx-tag-human {
	padding: 2px 8px;
	border-left: 0;
	border-radius: 999px;
	background: var(--cx-accent);
	color: #fff;
}

.cx-tag-done {
	border-left-color: var(--cx-live);
	color: var(--cx-ink-faint);
}

/* ----------------------------------------------------------------- Main */

.cx-main {
	display: flex;
	flex-direction: column;
	min-height: 0;
	background: var(--cx-canvas);
}

.cx-blank {
	display: flex;
	flex: 1;
	align-items: center;
	justify-content: center;
	color: var(--cx-ink-faint);
}

.cx-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 14px 24px;
	background: var(--cx-panel);
	border-bottom: 1px solid var(--cx-line);
}

.cx-head-id {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
}

.cx-head h2 {
	margin: 0;
	font-size: 16px;
	font-weight: 600;
	letter-spacing: -0.01em;
}

.cx-head-meta {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-top: 2px;
}

.cx-head-actions {
	display: flex;
	align-items: center;
	gap: 18px;
}

.cx-link {
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--cx-accent);
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	white-space: nowrap;
}

.cx-link:hover { text-decoration: underline; }
.cx-link:disabled { color: var(--cx-ink-faint); cursor: default; text-decoration: none; }

/* Status: solid dot plus plain text. */
.cx-state {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: var(--cx-ink-soft);
	font-size: 12.5px;
}

.cx-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--cx-ink-faint);
}

.cx-dot-live { background: var(--cx-live); }
.cx-dot-warn { background: var(--cx-warn); }

/* The 24h reply window, as a real countdown. A genuine deadline with a genuine
   consequence, so it is worth the agent's attention. */
.cx-window { color: var(--cx-ink-soft); }
.cx-window.is-urgent { color: var(--cx-warn); font-weight: 600; }

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

.cx-body {
	flex: 1;
	min-height: 0;
	padding: 24px;
	overflow-y: auto;
}

.cx-msg {
	display: flex;
	margin-bottom: 10px;
}

.cx-msg.is-out { justify-content: flex-end; }

.cx-bubble {
	max-width: 60%;
	padding: 9px 13px;
	border-radius: 12px;
	background: var(--cx-raised);
	border: 1px solid var(--cx-line);
	border-bottom-left-radius: var(--cx-r-sm);
}

.cx-msg.is-out .cx-bubble {
	border-color: transparent;
	background: var(--cx-accent);
	color: #fff;
	border-radius: 12px;
	border-bottom-right-radius: var(--cx-r-sm);
}

.cx-who {
	margin-bottom: 2px;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	opacity: 0.75;
}

.cx-text { white-space: pre-wrap; word-wrap: break-word; }

.cx-meta {
	margin-top: 3px;
	font-size: 11px;
	text-align: right;
	color: var(--cx-ink-faint);
}

.cx-msg.is-out .cx-meta { color: rgba(255, 255, 255, 0.72); }

.cx-media {
	display: block;
	max-width: 100%;
	max-height: 280px;
	margin-bottom: 6px;
	border-radius: var(--cx-r-sm);
}

.cx-file {
	display: inline-block;
	margin-bottom: 6px;
	font-weight: 600;
	color: var(--cx-accent);
}

.cx-tick { margin-left: 4px; }
.cx-tick-read { color: var(--cx-read); }
.cx-tick-fail { color: #ffd9d9; font-weight: 700; }

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

.cx-compose {
	padding: 14px 24px 18px;
	background: var(--cx-panel);
	border-top: 1px solid var(--cx-line);
}

.cx-compose textarea {
	display: block;
	width: 100%;
	padding: 11px 14px;
	border: 1px solid var(--cx-line);
	border-radius: var(--cx-r-md);
	background: var(--cx-raised);
	resize: vertical;
}

.cx-compose textarea:focus {
	outline: 2px solid var(--cx-accent);
	outline-offset: -1px;
	border-color: transparent;
}

.cx-compose-actions {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-top: 10px;
}

/* The ONLY filled button on the screen. The eye should always find it. */
.cx-compose-actions button:last-child,
.cx-tpl button {
	height: 40px;
	padding: 0 22px;
	border: 0;
	border-radius: var(--cx-r-md);
	background: var(--cx-accent);
	color: #fff;
	font-weight: 600;
	cursor: pointer;
}

.cx-compose-actions button:last-child:hover { filter: brightness(0.94); }

.cx-compose-actions button:last-child:disabled {
	opacity: 0.5;
	cursor: default;
}

.cx-closed {
	padding: 16px 24px 20px;
	background: var(--cx-panel);
	border-top: 1px solid var(--cx-line);
	box-shadow: inset 3px 0 0 var(--cx-warn);
}

.cx-closed p {
	margin: 0 0 10px;
	color: var(--cx-ink-soft);
	font-size: 13px;
}

.cx-tpl {
	display: flex;
	gap: 10px;
}

.cx-tpl select {
	flex: 1;
	height: 40px;
	padding: 0 12px;
	border: 1px solid var(--cx-line);
	border-radius: var(--cx-r-md);
	background: var(--cx-raised);
}

/* --------------------------------------------------------------- Errors */

.cx-error {
	margin: 8px 0 0;
	color: var(--cx-danger);
	font-size: 13px;
}

.cx-error-bar {
	margin: 0;
	padding: 10px 24px;
	background: rgba(179, 45, 46, 0.07);
	box-shadow: inset 3px 0 0 var(--cx-danger);
}

/* --------------------------------------------------------------- Narrow */

@media (max-width: 900px) {
	.cx-app { grid-template-columns: 1fr; }

	/* One conversation at a time on a phone: the list steps aside the moment a
	   thread is open. */
	.cx-app:has(.cx-blank) .cx-main { display: none; }
	.cx-app:not(:has(.cx-blank)) .cx-side { display: none; }

	.cx-bubble { max-width: 86%; }
}
