:root {
  --bg: #f3f6f8;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #667785;
  --line: #d9e2e8;
  --primary: #0c7c86;
  --primary-dark: #075d65;
  --danger: #b42318;
  --warning: #b54708;
  --incoming: #eaf6ff;
  --outgoing: #eaf8ee;
  --internal: #fff7db;
  --system: #f1f3f5;
  --shadow: 0 14px 38px rgba(29, 55, 66, 0.16);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button, .button-link { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 0.55rem 0.8rem; cursor: pointer; color: var(--text); text-decoration: none; }
button:hover, .button-link:hover { border-color: #9fb2bd; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
button.primary, .primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 650; }
button.primary:hover, .primary:hover { background: var(--primary-dark); }
button.secondary, .secondary { background: #fff; }
button.danger, .danger { background: #fff4f3; color: var(--danger); border-color: #f3b4ae; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.brand-mark { width: 46px; height: 46px; border-radius: 14px; display: inline-grid; place-items: center; color: white; background: linear-gradient(135deg, #0c7c86, #28a0ad); font-size: 1.35rem; font-weight: 800; box-shadow: var(--shadow); }
.brand-mark.small { width: 32px; height: 32px; border-radius: 9px; font-size: 1rem; box-shadow: none; }
.badge { min-width: 1.45rem; height: 1.45rem; border-radius: 999px; padding: 0 0.4rem; display: inline-flex; align-items: center; justify-content: center; background: #d92d20; color: #fff; font-weight: 750; font-size: 0.78rem; }
.alert { border-radius: 8px; padding: 0.7rem 0.8rem; margin: 0.75rem 0; }
.alert.error { color: #7a271a; background: #fef3f2; border: 1px solid #fecdca; }
.stack-form { display: grid; gap: 0.85rem; }
.stack-form label, .grid-form label, .dialog-form label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.9rem; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 0.65rem 0.72rem; background: #fff; color: var(--text); }
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(12, 124, 134, 0.15); border-color: var(--primary); }
textarea { resize: vertical; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at top left, #d9f2f4, transparent 45%), var(--bg); }
.login-card { width: min(420px, 100%); background: var(--panel); padding: 2rem; border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { margin-bottom: 0.15rem; }
.login-card .muted { margin-top: 0; }

/* Shared top bar */
.topbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.55rem 1rem; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-brand, .topbar-actions { display: flex; align-items: center; gap: 0.65rem; }
.topbar-actions form { margin: 0; }
.topbar-actions select { width: auto; min-width: 100px; padding: 0.48rem 0.55rem; }
.agent-name { font-weight: 650; }


.toast-container { position: fixed; top: 72px; right: 18px; z-index: 100; display: grid; gap: 0.7rem; width: min(380px, calc(100vw - 36px)); }
.chat-toast { background: #fff; border: 1px solid #f3b4ae; border-left: 5px solid #d92d20; border-radius: 12px; box-shadow: var(--shadow); padding: 0.85rem; animation: toast-in .2s ease-out; }
.chat-toast.escalated { border-color: #f2c083; border-left-color: #b54708; }
.chat-toast-head { display: flex; justify-content: space-between; gap: 0.7rem; align-items: center; }
.chat-toast-title { font-weight: 800; }
.chat-toast-meta { color: var(--muted); font-size: 0.82rem; margin: 0.35rem 0 0.65rem; }
.chat-toast-actions { display: flex; justify-content: flex-end; gap: 0.45rem; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Agent console */
.agent-page { height: 100vh; overflow: hidden; }
.agent-shell { height: 100vh; display: flex; flex-direction: column; }
.agent-grid { min-height: 0; flex: 1; display: grid; grid-template-columns: 320px minmax(420px, 1fr) 300px; gap: 0; }
.queue-panel, .conversation-panel, .customer-panel { background: var(--panel); min-height: 0; }
.queue-panel { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.customer-panel { border-left: 1px solid var(--line); padding: 1rem; overflow-y: auto; }
.customer-panel h3 { margin: 0.2rem 0 0.75rem; }
.queue-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.queue-tab { border: 0; border-radius: 0; padding: 0.8rem 0.25rem; background: #f8fafb; font-size: 0.82rem; }
.queue-tab.active { background: #fff; color: var(--primary-dark); box-shadow: inset 0 -3px var(--primary); font-weight: 750; }
.queue-list { overflow-y: auto; min-height: 0; flex: 1; }
.queue-item { width: 100%; text-align: left; border: 0; border-bottom: 1px solid #edf1f3; border-radius: 0; padding: 0.8rem 0.9rem; background: #fff; }
.queue-item:hover, .queue-item.selected { background: #eef8f9; }
.queue-item-head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.queue-item-name { font-weight: 700; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.queue-item-ref { color: var(--muted); font-size: 0.75rem; }
.queue-item-meta { display: flex; justify-content: space-between; gap: 0.5rem; margin-top: 0.35rem; color: var(--muted); font-size: 0.78rem; }
.waiting-pulse { width: 9px; height: 9px; background: #d92d20; border-radius: 50%; box-shadow: 0 0 0 0 rgba(217,45,32,.4); animation: pulse 1.7s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(217,45,32,0); } 100% { box-shadow: 0 0 0 0 rgba(217,45,32,0); } }
.empty-state { color: var(--muted); text-align: center; padding: 2rem 1rem; }
.conversation-panel { display: flex; min-width: 0; }
.conversation-empty { margin: auto; text-align: center; color: var(--muted); }
.conversation-view { display: flex; flex-direction: column; min-width: 0; width: 100%; }
.conversation-header { min-height: 74px; padding: 0.8rem 1rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }
.conversation-header h2 { margin: 0 0 0.2rem; font-size: 1.1rem; }
.conversation-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; justify-content: flex-end; }
.message-list { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.65rem; background: #f8fafb; }
.message { max-width: 78%; padding: 0.68rem 0.78rem; border-radius: 12px; border: 1px solid transparent; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.message.customer { align-self: flex-start; background: var(--incoming); border-color: #cbe8f8; }
.message.agent { align-self: flex-end; background: var(--outgoing); border-color: #cfe9d6; }
.message.internal_note { align-self: stretch; max-width: 100%; background: var(--internal); border-color: #f2d98b; }
.message.system { align-self: center; max-width: 90%; background: var(--system); border-color: #e0e5e8; color: var(--muted); text-align: center; font-size: 0.84rem; }
.message-head { display: flex; justify-content: space-between; gap: 0.8rem; margin-bottom: 0.3rem; font-size: 0.74rem; color: var(--muted); }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.38; }
.composer { border-top: 1px solid var(--line); padding: 0.65rem 0.8rem; background: #fff; }
.composer-row { display: grid; grid-template-columns: 1fr auto; gap: 0.55rem; align-items: end; }
.composer textarea { min-height: 54px; max-height: 160px; }
.internal-note-toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }
.internal-note-toggle input { width: auto; }
.detail-list { margin: 0 0 1.2rem; }
.detail-list div { padding: 0.55rem 0; border-bottom: 1px solid #edf1f3; }
.detail-list dt { color: var(--muted); font-size: 0.75rem; margin-bottom: 0.15rem; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.ticket-card { border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem; background: #f8fafb; }
.ticket-card a { color: var(--primary-dark); font-weight: 700; }

/* Dialog */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 2rem)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(20, 35, 43, 0.5); }
.dialog-form { padding: 1.2rem; display: grid; gap: 0.85rem; }
.dialog-form h3 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.55rem; }

/* Customer widget */
.customer-chat { background: transparent; }
.customer-chat.embed { height: 100vh; }
.customer-chat.direct { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at top left, #d9f2f4, transparent 45%), var(--bg); }
.customer-shell { width: 100%; height: 100%; display: flex; flex-direction: column; background: #fff; overflow: hidden; }
.customer-chat.direct .customer-shell { width: min(620px, 100%); height: min(820px, calc(100vh - 2rem)); border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.customer-header { min-height: 64px; padding: 0.8rem 1rem; display: flex; align-items: center; justify-content: space-between; background: linear-gradient(135deg, var(--primary-dark), var(--primary)); color: #fff; }
.customer-status { opacity: 0.86; font-size: 0.8rem; margin-top: 0.15rem; }
.icon-button { width: 36px; height: 36px; padding: 0; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.35); font-size: 1.4rem; }
.customer-main { min-height: 0; flex: 1; display: flex; }
.prechat-view { width: 100%; padding: 1rem; overflow-y: auto; }
.prechat-view > p { margin-top: 0; line-height: 1.45; }
.customer-conversation { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.customer-messages { padding: 0.8rem; }
.customer-composer { border-top: 1px solid var(--line); padding: 0.65rem; display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; align-items: end; }
.customer-composer textarea { min-height: 48px; max-height: 120px; }
.customer-footer { min-height: 28px; padding: 0.35rem 0.65rem; display: flex; justify-content: space-between; color: var(--muted); background: #f8fafb; border-top: 1px solid var(--line); font-size: 0.7rem; }

/* Admin */
.admin-container { max-width: 1500px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.admin-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 1rem; box-shadow: 0 4px 14px rgba(29,55,66,.06); overflow: hidden; }
.admin-card h2 { margin-top: 0; }
.inline-form { display: grid; grid-template-columns: 1.2fr 1fr 150px auto; gap: 0.55rem; margin-bottom: 1rem; }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.grid-form .span-2 { grid-column: span 2; }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: 0.55rem 1rem; }
.checkbox-grid label { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: 500; }
.checkbox-grid input { width: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { border-bottom: 1px solid var(--line); padding: 0.65rem; text-align: left; vertical-align: top; }
th { background: #f5f8fa; color: #43515b; position: sticky; top: 0; }
.code-box { display: block; white-space: pre-wrap; overflow-wrap: anywhere; background: #18252b; color: #e6f5f6; border-radius: 8px; padding: 0.7rem; font-family: Consolas, monospace; font-size: 0.74rem; }

@media (max-width: 1120px) {
  .agent-grid { grid-template-columns: 280px minmax(360px, 1fr); }
  .customer-panel { display: none; }
}
@media (max-width: 760px) {
  .agent-page { overflow: auto; height: auto; }
  .agent-shell { height: auto; min-height: 100vh; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .agent-grid { display: block; }
  .queue-panel { height: 280px; border-right: 0; border-bottom: 1px solid var(--line); }
  .conversation-panel { min-height: 620px; }
  .message { max-width: 90%; }
  .conversation-header { align-items: flex-start; flex-direction: column; }
  .inline-form, .grid-form { grid-template-columns: 1fr; }
  .grid-form .span-2 { grid-column: auto; }
}

/* Hotfix 4 - agent attention and alert experience */
.agent-alert-status { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.32rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 750; white-space: nowrap; }
.agent-alert-status.active { color: #067647; background: #ecfdf3; border: 1px solid #abefc6; }
.agent-alert-status.needs-action { color: #934f00; background: #fff7ed; border: 1px solid #fed7aa; }
.alert-activate-button { font-weight: 700; }
.alert-setup-banner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.65rem 1rem; background: #fff7ed; color: #7c2d12; border-bottom: 1px solid #fed7aa; z-index: 18; }
.alert-setup-banner > div { display: flex; flex-wrap: wrap; gap: 0.35rem 0.65rem; align-items: baseline; }
.alert-setup-banner span { font-size: 0.86rem; }
.agent-alert-banner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 1rem; border-bottom: 1px solid transparent; box-shadow: 0 5px 16px rgba(29,55,66,.12); z-index: 17; animation: agent-alert-attention 1.1s ease-in-out infinite alternate; }
.agent-alert-banner.waiting-alert { background: #fff1f0; border-color: #fecdca; color: #7a271a; }
.agent-alert-banner.message-alert { background: #eff8ff; border-color: #b2ddff; color: #1849a9; }
.agent-alert-banner-copy { display: flex; min-width: 0; flex-direction: column; gap: 0.18rem; }
.agent-alert-banner-copy strong { font-size: 0.95rem; letter-spacing: 0.02em; }
.agent-alert-banner-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.86rem; }
.message-toast { border-color: #b2ddff; border-left-color: #1570ef; }
.message-alert-dot { width: 10px; height: 10px; border-radius: 50%; background: #1570ef; box-shadow: 0 0 0 0 rgba(21,112,239,.45); animation: pulse-message 1.3s infinite; }
@keyframes pulse-message { 70% { box-shadow: 0 0 0 8px rgba(21,112,239,0); } 100% { box-shadow: 0 0 0 0 rgba(21,112,239,0); } }
@keyframes agent-alert-attention { from { filter: brightness(1); } to { filter: brightness(.96); } }

@media (max-width: 900px) {
  .alert-setup-banner, .agent-alert-banner { align-items: stretch; flex-direction: column; }
  .agent-alert-banner-copy span { white-space: normal; }
}

/* v2.6.1 Build 1 - operations dashboard, knowledge and attachments */
.manager-page { min-height: 100vh; background: var(--bg); }
.manager-container { max-width: 1600px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.manager-period { display: flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 700; }
.manager-period select { width: auto; }
.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); gap: .75rem; }
.kpi-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: .85rem; box-shadow: 0 4px 14px rgba(29,55,66,.06); display: grid; gap: .2rem; }
.kpi-card span { font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.kpi-card strong { font-size: 1.55rem; color: var(--primary-dark); }
.kpi-card small { color: var(--muted); line-height: 1.3; }
.manager-card { background:#fff; border:1px solid var(--line); border-radius:14px; padding:1rem; box-shadow:0 4px 14px rgba(29,55,66,.06); overflow:hidden; }
.manager-card h2 { margin:0 0 .75rem; }
.manager-card h3 { margin:1rem 0 .55rem; }
.section-head { display:flex; align-items:flex-start; justify-content:space-between; gap:1rem; }
.section-head h2,.section-head p { margin-top:0; }
.manager-two-column { display:grid; grid-template-columns:1fr 1fr; gap:1rem; }
.manager-two-column.nested { align-items:start; }
.summary-list { margin:.25rem 0 0; padding-left:1.2rem; display:grid; gap:.45rem; line-height:1.45; }
.table-scroll { overflow:auto; max-height:440px; }
.status-pill { display:inline-flex; border-radius:999px; padding:.18rem .5rem; font-size:.75rem; font-weight:700; }
.status-pill.online { background:#ecfdf3; color:#067647; }
.status-pill.offline { background:#f2f4f7; color:#667085; }
.hour-bars { display:grid; gap:.3rem; }
.hour-row { display:grid; grid-template-columns:52px 1fr 40px; align-items:center; gap:.5rem; font-size:.78rem; }
.hour-track { height:10px; background:#eef2f4; border-radius:999px; overflow:hidden; }
.hour-track i { display:block; height:100%; background:var(--primary); border-radius:inherit; }
.report-actions { display:flex; align-items:end; gap:.65rem; flex-wrap:wrap; }
.report-actions label { min-width:260px; display:grid; gap:.3rem; font-weight:700; font-size:.85rem; }
.insight-row { display:flex; align-items:center; justify-content:space-between; gap:.75rem; padding:.65rem 0; border-bottom:1px solid #edf1f3; }
.insight-row > div { min-width:0; display:grid; gap:.2rem; }
.insight-row span { color:var(--muted); font-size:.78rem; }
.faq-form { border:1px solid var(--line); border-radius:12px; padding:.8rem; background:#f8fafb; }
.faq-grid { display:grid; grid-template-columns:1fr 1fr; gap:.65rem; }
.attachment-list { display:flex; flex-wrap:wrap; gap:.4rem; margin-top:.45rem; }
.attachment-chip { display:inline-flex; align-items:center; gap:.35rem; padding:.38rem .5rem; border:1px solid var(--line); border-radius:8px; background:#fff; font-size:.78rem; cursor:pointer; }
.attachment-chip:hover { border-color:var(--primary); }
.attachment-preview { max-width:280px; max-height:220px; border-radius:8px; border:1px solid var(--line); display:block; margin-top:.45rem; cursor:pointer; }
.attachment-tools { display:flex; align-items:center; gap:.45rem; margin-top:.4rem; }
.attach-button { white-space:nowrap; }
.upload-status { font-size:.75rem; color:var(--muted); min-height:1rem; }
.knowledge-card { border:1px solid var(--line); border-radius:10px; padding:.7rem; background:#f8fafb; margin-bottom:.5rem; }
.knowledge-card strong { display:block; margin-bottom:.25rem; }
.knowledge-card p { margin:.25rem 0; font-size:.82rem; line-height:1.35; }
.knowledge-actions { display:flex; gap:.35rem; flex-wrap:wrap; }
@media (max-width:1250px){ .kpi-grid{grid-template-columns:repeat(3,1fr);} }
@media (max-width:800px){ .kpi-grid{grid-template-columns:repeat(2,1fr);} .manager-two-column{grid-template-columns:1fr;} .faq-grid{grid-template-columns:1fr;} }
