:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #6b7280;
  --line: #e5e8ee;
  --nav: #111827;
  --nav-soft: #1f2937;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #059669;
  --shadow: 0 12px 35px rgba(15, 23, 42, .07);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 16px; background: var(--nav); color: white; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 25px; font-weight: 750; letter-spacing: -.02em; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; background: linear-gradient(135deg, #60a5fa, #7c3aed); color: white; font-weight: 850; box-shadow: 0 10px 24px rgba(37,99,235,.3); }
.brand-mark.small { width: 33px; height: 33px; border-radius: 10px; }
nav { display: grid; gap: 5px; }
.nav-link { width: 100%; padding: 11px 12px; border: 0; border-radius: 9px; background: transparent; color: #cbd5e1; text-align: left; }
.nav-link:hover, .nav-link.active { color: white; background: var(--nav-soft); }
.nav-link span { display: inline-block; width: 24px; color: #93c5fd; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 8px; }

main { min-width: 0; padding: 0 28px 34px; }
.topbar { min-height: 104px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar h1 { margin: 2px 0 0; font-size: 26px; letter-spacing: -.035em; }
.eyebrow { margin: 0; color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.live-pill { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid #d1fae5; border-radius: 999px; background: #ecfdf5; color: #047857; font-size: 13px; font-weight: 650; }
.live-pill span { width: 8px; height: 8px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 4px rgba(16,185,129,.12); }

.view { display: none; }
.view.active { display: block; }
.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { padding: 17px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
.stat-card p { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 650; }
.stat-card strong { font-size: 27px; letter-spacing: -.04em; }
.stat-card.alert strong { color: var(--danger); }
.panel { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 16px; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.panel-header select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--ink); }
.inbox-layout { display: grid; grid-template-columns: minmax(280px, .85fr) minmax(480px, 1.65fr); gap: 16px; min-height: calc(100vh - 202px); }
.conversation-list-panel { min-height: 600px; }
.conversation-list { max-height: calc(100vh - 283px); overflow-x: hidden; overflow-y: auto; }
.conversation-item { width: 100%; max-width: 100%; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 11px; padding: 15px 18px; border: 0; border-bottom: 1px solid var(--line); background: white; color: inherit; text-align: left; }
.conversation-item:hover, .conversation-item.selected { background: #f8fafc; }
.channel-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 11px; background: var(--primary-soft); color: var(--primary); font-weight: 800; }
.conversation-copy { min-width: 0; }
.conversation-top { display: flex; justify-content: space-between; gap: 8px; }
.conversation-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conversation-top time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.conversation-preview { margin: 5px 0 8px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; }
.badge { display: inline-flex; align-items: center; padding: 3px 7px; border-radius: 999px; background: #eef2f7; color: #475569; font-size: 10px; font-weight: 700; }
.badge.high, .badge.urgent { background: #fef2f2; color: #b91c1c; }
.badge.waiting_operator { background: #fff7ed; color: #c2410c; }
.unread { min-width: 21px; height: 21px; display: grid; place-items: center; border-radius: 999px; background: var(--primary); color: white; font-size: 11px; font-weight: 750; }

.conversation-panel { display: grid; grid-template-rows: auto minmax(330px, 1fr) auto; min-height: 600px; }
.empty-state { display: grid; place-items: center; }
.empty-copy { max-width: 330px; padding: 40px; text-align: center; }
.empty-copy h2 { margin: 14px 0 8px; }
.empty-copy p { color: var(--muted); }
.empty-icon { width: 58px; height: 58px; margin: auto; display: grid; place-items: center; border-radius: 18px; background: var(--primary-soft); color: var(--primary); font-size: 25px; }
.conversation-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.conversation-heading h2 { margin: 0 0 6px; font-size: 16px; }
.conversation-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.inline-select { width: auto; max-width: 280px; margin-top: 9px; padding: 6px 9px; font-size: 11px; }
.conversation-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.message-stream { padding: 20px; overflow-y: auto; background: #f8fafc; }
.message { max-width: 78%; margin-bottom: 12px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 13px 13px 13px 4px; background: white; }
.message.user { margin-left: auto; border-color: #bfdbfe; border-radius: 13px 13px 4px 13px; background: #eff6ff; }
.message.operator { border-color: #bbf7d0; background: #f0fdf4; }
.message.system { border-style: dashed; background: #fff7ed; }
.message.internal { border-color: #fde68a; background: #fffbeb; }
.message-meta { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 5px; color: var(--muted); font-size: 10px; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 14px; border-top: 1px solid var(--line); }
.composer textarea { min-height: 67px; resize: vertical; }
.composer-side { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 8px 13px; border: 1px solid transparent; border-radius: 9px; text-decoration: none; font-weight: 650; font-size: 12px; }
.button.primary { background: var(--primary); color: white; }
.button.primary:hover { background: #1d4ed8; }
.button.secondary { border-color: var(--line); background: white; color: var(--ink); }
.button.danger { background: #fef2f2; color: var(--danger); }
.button.ghost { border-color: #334155; background: transparent; color: #cbd5e1; }
.danger-text { color: #fca5a5 !important; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, .7fr); gap: 16px; }
.section-gap, #faqView > .settings-grid + .settings-grid { margin-top: 16px; }
.settings-card, .policy-card, .faq-list-card { padding-bottom: 20px; }
.settings-card > label { display: grid; gap: 7px; margin: 18px 20px 0; color: #334155; font-size: 12px; font-weight: 700; }
input, textarea, select { width: 100%; padding: 10px 11px; border: 1px solid #d9dee7; border-radius: 9px; background: white; color: var(--ink); outline: none; }
input:focus, textarea:focus, select:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(96,165,250,.15); }
textarea { resize: vertical; }
.two-columns { display: grid; grid-template-columns: 1fr 170px; gap: 12px; margin: 18px 20px 0; }
.profile-fields { grid-template-columns: minmax(260px, 1fr) minmax(180px, .45fr); }
.two-columns label { display: grid; gap: 7px; color: #334155; font-size: 12px; font-weight: 700; }
.switch-row { display: flex !important; grid-template-columns: auto 1fr !important; align-items: center; }
.switch-row input { width: 18px; height: 18px; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin: 20px; }
.policy-card { padding: 24px; }
.policy-card h2 { margin: 8px 0 18px; font-size: 20px; }
.policy-card li, .policy-card > p:last-child { color: #475569; font-size: 13px; line-height: 1.65; }
.faq-grid { grid-template-columns: minmax(320px, .8fr) minmax(420px, 1.2fr); }
.faq-list { max-height: calc(100vh - 210px); overflow-y: auto; }
.faq-item { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.faq-item h3 { margin: 0 0 7px; font-size: 14px; }
.faq-item p { margin: 0 0 11px; color: #475569; white-space: pre-wrap; font-size: 12px; line-height: 1.5; }
.faq-footer { display: flex; align-items: center; justify-content: space-between; }
.link-button { border: 0; background: transparent; color: var(--danger); font-size: 12px; }

.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.78); backdrop-filter: blur(8px); }
.overlay.hidden { display: none; }
.login-card { width: min(420px, 100%); display: grid; gap: 14px; padding: 34px; border-radius: 18px; background: white; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.login-card .brand-mark { margin-bottom: 5px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0; color: var(--muted); font-size: 13px; }
.error { min-height: 18px; color: var(--danger) !important; }
.muted { color: var(--muted); font-size: 12px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 90; max-width: 360px; padding: 13px 16px; border-radius: 10px; background: #111827; color: white; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; box-shadow: var(--shadow); font-size: 13px; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .inbox-layout { grid-template-columns: 330px minmax(430px, 1fr); }
}
@media (max-width: 800px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 12px; flex-direction: row; align-items: center; overflow-x: auto; }
  .brand { padding: 0 10px 0 0; }
  .brand span:last-child { display: none; }
  nav, .sidebar-bottom { display: flex; margin: 0; }
  .sidebar-bottom { margin-left: auto; }
  .sidebar-bottom .button:not(#pushButton) { display: none; }
  main { padding: 0 14px 24px; }
  .topbar { min-height: 82px; }
  .inbox-layout, .settings-grid, .faq-grid { grid-template-columns: 1fr; }
  .conversation-list { max-height: 360px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
