:root {
  color-scheme: light;
  --ink: #173333;
  --muted: #6b7f7c;
  --line: #dce7e4;
  --surface: #ffffff;
  --canvas: #f3f7f6;
  --deep: #102a2a;
  --deep-2: #173a39;
  --brand: #0d9f78;
  --brand-dark: #08775b;
  --brand-soft: #e6f7f1;
  --warm: #f5b95f;
  --danger: #d55454;
  --shadow: 0 18px 60px rgba(16, 42, 42, .13);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.eyebrow { margin: 0; color: var(--brand); font-size: .72rem; font-weight: 800; letter-spacing: .14em; }
.brand-mark { display: grid; width: 52px; height: 52px; place-items: center; border-radius: 17px; color: #fff; background: linear-gradient(145deg, #10ad82, #08775b); box-shadow: 0 12px 30px rgba(13, 159, 120, .25); font-weight: 900; font-size: 1.45rem; }
.brand-mark-small { width: 40px; height: 40px; border-radius: 13px; font-size: 1.05rem; }

/* Login */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at 12% 15%, #1b4b47 0, transparent 34%), radial-gradient(circle at 90% 90%, #0d9f7855 0, transparent 30%), var(--deep); }
.login-shell { width: min(1030px, 100%); min-height: 620px; display: grid; grid-template-columns: 1.05fr .95fr; overflow: hidden; border: 1px solid #ffffff1c; border-radius: 30px; background: #fff; box-shadow: 0 35px 90px #071c1c80; }
.login-brand { position: relative; padding: 68px 62px; color: #fff; background: linear-gradient(150deg, #153c3a 0%, #102a2a 60%, #0a2423 100%); overflow: hidden; }
.login-brand::after { content: ""; position: absolute; width: 320px; height: 320px; right: -170px; bottom: -140px; border: 1px solid #ffffff1c; border-radius: 50%; box-shadow: 0 0 0 48px #ffffff08, 0 0 0 96px #ffffff08; }
.login-brand .eyebrow { margin: 30px 0 12px; color: #6de2bd; }
.login-brand h1 { max-width: 460px; margin: 0 0 22px; font-size: clamp(2.2rem, 4vw, 4rem); line-height: .98; letter-spacing: -.055em; }
.login-brand > p:not(.eyebrow) { max-width: 430px; margin: 0 0 42px; color: #c8d8d5; line-height: 1.65; }
.login-feature { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; margin: 15px 0; color: #eef8f5; font-size: .93rem; }
.login-feature span { display: grid; width: 25px; height: 25px; place-items: center; border-radius: 50%; color: var(--deep); background: #6de2bd; font-weight: 900; }
.login-card { align-self: center; padding: 56px 62px; }
.login-card-heading { display: flex; gap: 14px; align-items: center; }
.login-card h2 { margin: 3px 0 0; font-size: 1.65rem; letter-spacing: -.035em; }
.login-intro { margin: 27px 0; color: var(--muted); }
.login-form { display: grid; gap: 10px; }
.login-form label { margin-top: 8px; font-size: .83rem; font-weight: 750; }
.login-form input { width: 100%; height: 52px; padding: 0 15px; border: 1px solid var(--line); border-radius: 12px; outline: none; background: #fbfdfc; transition: border-color .2s, box-shadow .2s; }
.login-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px #0d9f7819; }
.primary-button { min-height: 52px; margin-top: 16px; border: 0; border-radius: 12px; color: #fff; background: var(--brand); font-weight: 800; cursor: pointer; box-shadow: 0 12px 24px #0d9f7828; }
.primary-button:hover { background: var(--brand-dark); }
.primary-button:disabled { cursor: not-allowed; opacity: .5; }
.form-alert { margin: 0 0 16px; padding: 12px 14px; border: 1px solid #eab8b8; border-radius: 11px; color: #8f2929; background: #fff3f3; font-size: .87rem; }
.login-security { margin: 24px 0 0; color: #8da09d; text-align: center; font-size: .75rem; }

/* Application shell */
.app-page { height: 100vh; height: 100dvh; overflow: hidden; }
.app-shell { height: 100%; display: grid; grid-template-columns: 340px minmax(0, 1fr); background: var(--canvas); }
.conversation-sidebar { position: relative; z-index: 3; min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); }
.sidebar-header, .chat-header { flex: 0 0 auto; display: flex; align-items: center; min-height: 74px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: #fff; }
.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-lockup div:last-child { display: grid; line-height: 1.15; }
.brand-lockup strong { font-size: 1.02rem; }
.brand-lockup span { color: var(--muted); font-size: .76rem; }
.header-actions { display: flex; gap: 8px; margin-left: auto; }
.icon-button, .avatar-button { display: grid; width: 39px; height: 39px; place-items: center; border: 1px solid transparent; border-radius: 11px; background: transparent; cursor: pointer; }
.icon-button:hover { border-color: var(--line); background: var(--canvas); }
.avatar-button { color: #fff; background: var(--deep); font-weight: 800; }
.account-menu { position: absolute; z-index: 15; top: 65px; right: 16px; width: 215px; display: grid; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.account-menu strong { font-size: .9rem; }
.account-menu span { margin-top: 3px; color: var(--muted); font-size: .76rem; }
.account-menu button { margin-top: 13px; padding: 10px; border: 0; border-radius: 9px; color: #8f2929; background: #fff1f1; cursor: pointer; text-align: left; }
.sidebar-tools { padding: 15px 16px 12px; }
.search-field { height: 45px; display: flex; align-items: center; gap: 9px; padding: 0 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--canvas); }
.search-field span { color: var(--muted); font-size: 1.25rem; }
.search-field input { width: 100%; min-width: 0; border: 0; outline: none; background: transparent; color: var(--ink); font-size: .86rem; }
.filter-tabs { display: flex; gap: 4px; margin-top: 12px; padding: 4px; border-radius: 11px; background: var(--canvas); }
.filter-tab { flex: 1; padding: 8px 4px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; font-size: .76rem; font-weight: 750; }
.filter-tab.active { color: var(--brand-dark); background: #fff; box-shadow: 0 3px 12px #1733330d; }
.conversation-count { display: flex; justify-content: space-between; padding: 4px 18px 10px; color: var(--muted); font-size: .7rem; }
.conversation-count span:first-child { color: var(--ink); font-weight: 750; }
.conversation-list { min-height: 0; flex: 1; overflow-y: auto; padding: 0 9px 18px; }
.conversation-item { width: 100%; display: grid; grid-template-columns: 45px minmax(0, 1fr) auto; gap: 11px; align-items: center; padding: 13px 10px; border: 0; border-radius: 13px; background: transparent; cursor: pointer; text-align: left; }
.conversation-item:hover { background: var(--canvas); }
.conversation-item.active { background: var(--brand-soft); }
.contact-avatar { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 14px; color: #fff; background: linear-gradient(145deg, #315b57, #173a39); font-size: .9rem; font-weight: 850; }
.contact-avatar.large { width: 62px; height: 62px; border-radius: 20px; font-size: 1.25rem; }
.conversation-copy { min-width: 0; display: grid; gap: 4px; }
.conversation-name-line { display: flex; align-items: center; min-width: 0; gap: 7px; }
.conversation-name-line strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }
.human-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--warm); }
.conversation-preview { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: .77rem; }
.conversation-meta { align-self: stretch; display: grid; justify-items: end; align-content: center; gap: 7px; color: var(--muted); font-size: .66rem; }
.unread-count { min-width: 20px; height: 20px; display: grid; place-items: center; padding: 0 6px; border-radius: 999px; color: #fff; background: var(--brand); font-weight: 800; }
.list-skeleton { height: 70px; margin: 5px; border-radius: 13px; background: linear-gradient(90deg, #f1f5f4 20%, #f8faf9 50%, #f1f5f4 80%); background-size: 240% 100%; animation: shimmer 1.4s infinite linear; }
@keyframes shimmer { to { background-position: -240% 0; } }
.list-empty, .panel-error { margin: 24px 12px; padding: 22px 16px; border: 1px dashed #cbdad6; border-radius: 14px; color: var(--muted); text-align: center; font-size: .82rem; line-height: 1.5; }

.chat-panel { min-width: 0; min-height: 0; position: relative; display: flex; background: #edf3f1; }
.empty-chat { width: min(540px, 90%); margin: auto; text-align: center; }
.empty-illustration { width: 132px; height: 94px; display: flex; justify-content: center; align-items: center; gap: 7px; margin: 0 auto 28px; border: 1px solid #cfe0dc; border-radius: 30px 30px 30px 7px; color: var(--brand); background: #fff; box-shadow: 0 18px 50px #17333312; }
.empty-illustration span { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.empty-chat h1 { margin: 8px 0 12px; font-size: clamp(1.7rem, 3vw, 2.7rem); letter-spacing: -.05em; }
.empty-chat > p:not(.eyebrow) { margin: 0 auto; color: var(--muted); line-height: 1.65; }
.retention-note { display: inline-flex; margin-top: 28px; padding: 9px 13px; border: 1px solid #d8e4e1; border-radius: 999px; color: #67807b; background: #ffffffa8; font-size: .75rem; }
.active-chat { min-width: 0; min-height: 0; flex: 1; display: flex; flex-direction: column; }
.chat-header { gap: 11px; }
.contact-heading { min-width: 0; display: grid; gap: 3px; }
.contact-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-heading button { width: fit-content; max-width: 100%; padding: 0; overflow: hidden; border: 0; color: var(--muted); background: none; cursor: pointer; text-overflow: ellipsis; white-space: nowrap; font-size: .75rem; }
.chat-header-actions { display: flex; align-items: center; gap: 9px; margin-left: auto; }
.mode-pill { padding: 7px 10px; border-radius: 999px; font-size: .7rem; font-weight: 800; }
.mode-pill.bot { color: #08775b; background: var(--brand-soft); }
.mode-pill.human { color: #8b5a12; background: #fff0d4; }
.secondary-button { min-height: 39px; padding: 0 13px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-size: .78rem; font-weight: 750; }
.secondary-button:hover { border-color: #abc5bf; background: var(--canvas); }
.mobile-back { display: none; }
.message-area { min-height: 0; flex: 1; overflow-y: auto; padding: 18px clamp(18px, 4vw, 70px) 24px; background-color: #edf3f1; background-image: radial-gradient(#1733330c 1px, transparent 1px); background-size: 18px 18px; }
.privacy-divider { display: flex; align-items: center; gap: 12px; margin: 0 auto 20px; color: #80938f; font-size: .68rem; }
.privacy-divider::before, .privacy-divider::after { content: ""; height: 1px; flex: 1; background: #d5e1df; }
.privacy-divider span { padding: 6px 10px; border-radius: 999px; background: #ffffffc7; }
.message-list { display: flex; flex-direction: column; gap: 9px; }
.message-row { display: flex; align-items: flex-end; gap: 8px; }
.message-row.out { justify-content: flex-end; }
.message-bubble { max-width: min(620px, 78%); padding: 10px 12px 7px; border: 1px solid #dbe6e3; border-radius: 6px 16px 16px 16px; background: #fff; box-shadow: 0 3px 12px #1733330b; }
.message-row.out .message-bubble { border-color: #bfe4d8; border-radius: 16px 6px 16px 16px; background: #dff5ed; }
.message-row.admin .message-bubble { border-color: #f1d5a8; background: #fff2da; }
.message-sender { display: block; margin-bottom: 4px; color: var(--brand-dark); font-size: .66rem; font-weight: 800; }
.message-row.admin .message-sender { color: #926118; }
.message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .86rem; line-height: 1.45; }
.media-placeholder { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 10px; border-radius: 10px; background: #1733330a; }
.media-placeholder span:first-child { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 9px; background: #fff; }
.media-placeholder div { display: grid; font-size: .78rem; }
.media-placeholder small { color: var(--muted); }
.message-time { display: block; margin-top: 4px; color: #7a8f8a; text-align: right; font-size: .62rem; }
.day-divider { align-self: center; margin: 9px 0; padding: 6px 10px; border-radius: 999px; color: var(--muted); background: #ffffffd9; font-size: .67rem; box-shadow: 0 2px 9px #1733330a; }
.messages-empty { align-self: center; margin-top: 18vh; padding: 16px 20px; border-radius: 14px; color: var(--muted); background: #ffffffd9; text-align: center; font-size: .8rem; }
.composer { flex: 0 0 auto; padding: 10px clamp(15px, 3vw, 46px) calc(11px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
.composer-notice { display: none; margin: 0 0 7px; color: #8b5a12; text-align: center; font-size: .71rem; }
.composer.locked .composer-notice { display: block; }
.composer form { display: flex; align-items: flex-end; gap: 10px; }
.composer textarea { min-height: 44px; max-height: 130px; flex: 1; resize: none; padding: 11px 13px; border: 1px solid var(--line); border-radius: 13px; outline: none; background: var(--canvas); line-height: 1.4; }
.composer textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px #0d9f7814; }
.composer textarea:disabled { cursor: not-allowed; opacity: .62; }
.send-button { width: 44px; height: 44px; flex: 0 0 auto; border: 0; border-radius: 13px; color: #fff; background: var(--brand); cursor: pointer; font-weight: 900; }
.send-button:disabled { cursor: not-allowed; background: #b8c9c5; }
.composer-hint { display: block; margin-top: 5px; color: #98a8a5; text-align: right; font-size: .61rem; }

.details-panel { position: relative; z-index: 12; width: 350px; min-width: 0; display: none; border-left: 1px solid var(--line); background: #fff; }
.app-shell.details-open { grid-template-columns: 310px minmax(0, 1fr) 350px; }
.app-shell.details-open .details-panel { display: flex; flex-direction: column; }
.details-panel > header { display: flex; align-items: center; justify-content: space-between; min-height: 74px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.details-panel h2 { margin: 3px 0 0; font-size: 1.15rem; }
.details-content { overflow-y: auto; padding: 18px; }
.detail-card { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.profile-card { display: grid; justify-items: center; padding: 22px; text-align: center; }
.profile-card strong { margin-top: 11px; }
.profile-card > span:not(.customer-badge) { margin-top: 3px; color: var(--muted); font-size: .77rem; }
.customer-badge { margin-top: 12px; padding: 6px 9px; border-radius: 999px; color: var(--brand-dark); background: var(--brand-soft); font-size: .67rem; font-weight: 850; }
.detail-section { padding: 20px 2px; border-bottom: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 12px; font-size: .8rem; }
.section-heading { display: flex; justify-content: space-between; }
.section-heading span { color: var(--muted); font-size: .72rem; }
.account-list { display: grid; gap: 9px; }
.account-card { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--canvas); }
.account-card header { display: flex; align-items: center; justify-content: space-between; }
.account-card strong { font-size: .83rem; }
.account-card .status { padding: 4px 7px; border-radius: 999px; color: var(--brand-dark); background: var(--brand-soft); font-size: .6rem; font-weight: 800; }
.account-card p { margin: 6px 0 0; color: var(--muted); font-size: .7rem; line-height: 1.4; }
.summary-text { margin: 0; color: var(--muted); white-space: pre-wrap; font-size: .77rem; line-height: 1.55; }
.retention-card { display: flex; gap: 10px; border: 0; }
.retention-card > span { font-size: 1.2rem; }
.retention-card strong { font-size: .76rem; }
.retention-card p { margin: 4px 0 0; color: var(--muted); font-size: .7rem; line-height: 1.5; }
.details-overlay { position: fixed; z-index: 10; inset: 0; border: 0; background: #081e1d70; }
.toast-region { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: grid; gap: 9px; }
.toast { max-width: 360px; padding: 12px 15px; border: 1px solid #cce0db; border-radius: 12px; background: #fff; box-shadow: var(--shadow); font-size: .8rem; animation: toast-in .2s ease-out; }
.toast.error { border-color: #edc3c3; color: #8f2929; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1180px) {
  .app-shell.details-open { grid-template-columns: 320px minmax(0, 1fr); }
  .app-shell.details-open .details-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(390px, 92vw); box-shadow: -18px 0 60px #102a2a28; }
  .app-shell.details-open .details-overlay { display: block !important; }
  .mode-pill { display: none; }
}

@media (max-width: 760px) {
  .login-page { padding: 0; background: var(--deep); }
  .login-shell { min-height: 100vh; min-height: 100dvh; grid-template-columns: 1fr; border: 0; border-radius: 0; }
  .login-brand { display: none; }
  .login-card { width: min(100%, 480px); align-self: center; justify-self: center; padding: 38px 25px; }
  .app-shell { display: block; position: relative; }
  .conversation-sidebar, .chat-panel { position: absolute; inset: 0; width: 100%; }
  .conversation-sidebar { transform: translateX(0); transition: transform .22s ease; }
  .chat-panel { z-index: 5; transform: translateX(100%); transition: transform .22s ease; }
  .app-shell.chat-open .conversation-sidebar { transform: translateX(-22%); }
  .app-shell.chat-open .chat-panel { transform: translateX(0); }
  .sidebar-header, .chat-header { min-height: 68px; padding: 11px 13px; }
  .mobile-back { display: grid; }
  .chat-header .contact-avatar { width: 38px; height: 38px; border-radius: 12px; }
  .chat-header-actions { gap: 5px; }
  .secondary-button { max-width: 112px; min-height: 36px; padding: 0 9px; font-size: .68rem; }
  .details-button { width: 36px; height: 36px; }
  .message-area { padding: 14px 12px 20px; }
  .message-bubble { max-width: 86%; }
  .composer { padding: 8px 9px calc(8px + env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .details-panel { display: none; }
  .app-shell.details-open .details-panel { display: flex; width: min(360px, 92vw); }
  .toast-region { right: 10px; bottom: 10px; left: 10px; }
  .toast { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
