:root {
  color-scheme: light;
  --surface: #fffdfa;
  --surface-soft: #f4eee5;
  --line: #e8dfd3;
  --muted: #685d54;
  --error: #a23232;
  --error-surface: #fff0ee;
  --success: #286746;
  --success-surface: #edf8f0;
  --shadow: 0 8px 32px rgba(33, 21, 17, 0.07);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--pilui-crudo); color: var(--pilui-negro); font-family: var(--pilui-font-body); font-size: 15px; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.56; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--pilui-focus); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.eyebrow { color: var(--pilui-anil); font-family: var(--pilui-font-display); font-size: 11px; font-weight: 700; letter-spacing: .11em; line-height: 1.2; margin: 0; text-transform: uppercase; }

.button { align-items: center; border-radius: 10px; border: 1px solid transparent; display: inline-flex; gap: 8px; justify-content: center; min-height: 40px; padding: 9px 14px; text-align: center; transition: background-color .15s, border-color .15s, transform .15s; font-size: 14px; font-weight: 650; }
.button:active:not(:disabled), .icon-button:active:not(:disabled) { transform: translateY(1px); }
.button-primary { background: var(--pilui-negro); color: #fff; }
.button-primary:hover:not(:disabled) { background: #473127; }
.button-quiet { background: transparent; color: var(--pilui-negro); }
.button-quiet:hover:not(:disabled) { background: var(--surface-soft); }
.button-outline { background: var(--surface); border-color: var(--line); color: var(--pilui-negro); }
.button-outline:hover:not(:disabled) { border-color: var(--pilui-anil); }
.button-danger { border-color: #e6b9b5; color: var(--error); }
.button-danger:hover:not(:disabled) { background: var(--error-surface); }
.button svg, .icon-button svg { width: 18px; height: 18px; flex: none; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--pilui-negro); border-radius: 10px; width: 40px; height: 40px; }
.icon-button:hover { background: var(--surface-soft); }

.auth-screen { align-items: center; display: grid; justify-items: center; min-height: 100vh; padding: 24px; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); max-width: 430px; padding: 32px; width: 100%; }
.auth-logo { display: block; width: 138px; height: auto; margin-bottom: 32px; }
.auth-card h1 { font-family: var(--pilui-font-display); font-size: 30px; line-height: 1.12; margin: 10px 0 12px; }
.auth-card p:not(.eyebrow):not(.form-error) { color: var(--muted); line-height: 1.5; margin: 0 0 24px; }
.auth-card form { display: grid; gap: 10px; }
.auth-card label { font-weight: 650; }
.auth-card input { border: 1px solid #cfc4b8; border-radius: 10px; padding: 12px 14px; width: 100%; }
.auth-card form .button { margin-top: 6px; }
.form-error { color: var(--error); font-size: 13px; margin: 0; }

.app-shell { display: flex; flex-direction: column; height: 100vh; min-height: 540px; overflow: hidden; }
.topbar { align-items: center; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; gap: 24px; justify-content: space-between; min-height: 76px; padding: 12px 26px; }
.brand-lockup, .topbar-actions { align-items: center; display: flex; gap: 16px; }
.brand-logo { display: block; height: 40px; width: 146px; object-fit: contain; object-position: left; }
.brand-divider { background: var(--line); height: 36px; width: 1px; }
.product-title { display: flex; flex-direction: column; gap: 2px; }
.product-title strong { font-family: var(--pilui-font-display); font-size: 18px; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.topbar-actions { gap: 8px; }
.mode-badge { background: var(--surface-soft); border-radius: 99px; color: var(--pilui-ambar); font-size: 12px; font-weight: 700; padding: 7px 11px; white-space: nowrap; }
.mode-badge.mode-live { background: #e7f1f4; color: var(--pilui-anil); }
.mode-badge.mode-error { background: var(--error-surface); color: var(--error); }
.environment-notice { background: #fff3cd; border-bottom: 1px solid #e4d38d; color: #664d03; font-size: 13px; line-height: 1.35; padding: 8px 26px; text-align: center; }
.environment-notice.live-notice { background: #eaf4f6; border-color: #b7d2db; color: var(--pilui-anil); }
.environment-notice.error-notice { background: var(--error-surface); border-color: #edc5c2; color: var(--error); }

.inbox-layout { display: grid; flex: 1; grid-template-columns: minmax(290px, 370px) minmax(0, 1fr); min-height: 0; }
.conversation-pane { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.pane-heading { align-items: end; display: flex; justify-content: space-between; gap: 10px; padding: 23px 20px 16px; }
.pane-heading h2 { font-family: var(--pilui-font-display); font-size: 23px; line-height: 1.15; margin: 6px 0 0; }
.count-muted { color: var(--muted); font-family: var(--pilui-font-body); font-size: 15px; font-weight: 500; }
.updated-at { color: var(--muted); font-size: 11px; margin: 0 0 2px; white-space: nowrap; }
.list-controls { border-bottom: 1px solid var(--line); padding: 0 16px 15px; }
.search-field { align-items: center; border: 1px solid var(--line); border-radius: 10px; display: flex; gap: 8px; padding: 0 10px; }
.search-field:focus-within { border-color: var(--pilui-anil); box-shadow: 0 0 0 2px rgba(36, 90, 112, .14); }
.search-field svg { color: var(--muted); width: 17px; height: 17px; flex: none; }
.search-field input { background: transparent; border: 0; color: var(--pilui-negro); min-width: 0; outline: 0; padding: 11px 0; width: 100%; }
.search-field input::placeholder, .composer textarea::placeholder { color: #8e8278; }
.filter-row { display: flex; gap: 6px; margin-top: 12px; }
.filter-chip { background: transparent; border: 1px solid transparent; border-radius: 99px; color: var(--muted); font-size: 12px; font-weight: 650; padding: 6px 10px; }
.filter-chip:hover { background: var(--surface-soft); }
.filter-chip.active { background: rgba(36, 90, 112, .11); color: var(--pilui-anil); }
.conversation-list { flex: 1; overflow: auto; overscroll-behavior: contain; }
.conversation-item { align-items: center; background: transparent; border: 0; border-bottom: 1px solid #f1ebe4; color: inherit; display: flex; gap: 11px; padding: 14px 16px; text-align: left; width: 100%; }
.conversation-item:hover { background: #faf5ec; }
.conversation-item.selected { background: #eef3f1; border-left: 3px solid var(--pilui-anil); padding-left: 13px; }
.avatar { align-items: center; background: #eadbbd; border-radius: 50%; color: var(--pilui-ambar); display: flex; flex: none; font-family: var(--pilui-font-display); font-size: 17px; font-weight: 700; height: 40px; justify-content: center; width: 40px; }
.conversation-copy { min-width: 0; flex: 1; }
.conversation-top, .conversation-bottom { align-items: center; display: flex; gap: 8px; justify-content: space-between; }
.conversation-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-time { color: var(--muted); flex: none; font-size: 11px; }
.conversation-phone { color: var(--muted); display: block; font-size: 11px; margin-top: 1px; }
.conversation-preview { color: var(--muted); font-size: 13px; margin: 7px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-bottom { margin-top: 1px; }
.unread-count { align-items: center; background: var(--pilui-anil); border-radius: 99px; color: white; display: inline-flex; flex: none; font-size: 11px; font-weight: 700; justify-content: center; min-width: 20px; padding: 2px 5px; }
.mini-tag { color: var(--error); font-size: 11px; font-weight: 700; white-space: nowrap; }
.list-empty { color: var(--muted); line-height: 1.5; padding: 26px 20px; text-align: center; }
.list-empty strong { color: var(--pilui-negro); display: block; font-family: var(--pilui-font-display); margin-bottom: 4px; }

.thread-pane { background: var(--pilui-crudo); display: flex; flex-direction: column; min-height: 0; }
.empty-thread { align-items: center; display: flex; flex: 1; flex-direction: column; justify-content: center; padding: 32px; text-align: center; }
.empty-mark { height: 88px; width: 88px; }
.empty-mark img { height: 100%; width: 100%; }
.empty-thread h2 { font-family: var(--pilui-font-display); font-size: 25px; margin: 24px 0 6px; }
.empty-thread p { color: var(--muted); line-height: 1.5; margin: 0; max-width: 340px; }
.thread-content { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.thread-header { align-items: center; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; gap: 12px; min-height: 76px; padding: 12px 22px; }
.thread-identity { align-items: center; display: flex; flex: 1; gap: 10px; min-width: 0; }
.thread-heading-text { min-width: 0; }
.thread-heading-text h2 { font-family: var(--pilui-font-display); font-size: 18px; line-height: 1.2; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-heading-text p { color: var(--muted); font-size: 12px; margin: 2px 0 0; }
.back-button { display: none; }
.window-banner { align-items: center; background: var(--success-surface); border-bottom: 1px solid #d2e6d9; color: var(--success); display: flex; font-size: 13px; font-weight: 600; gap: 9px; line-height: 1.35; min-height: 42px; padding: 9px 22px; }
.window-banner::before { background: currentColor; border-radius: 50%; content: ""; height: 7px; width: 7px; flex: none; }
.window-banner.closed { background: #fff3dd; border-color: #eed9aa; color: #785318; }
.window-banner.opted-out { background: var(--error-surface); border-color: #edc5c2; color: var(--error); }
.thread-error { background: var(--error-surface); border-bottom: 1px solid #edc5c2; color: var(--error); font-size: 13px; padding: 9px 22px; }
.message-scroll { flex: 1; overflow: auto; overscroll-behavior: contain; }
.message-list { display: flex; flex-direction: column; gap: 11px; list-style: none; margin: 0 auto; max-width: 980px; padding: 28px 28px 32px; }
.message-row { display: flex; }
.message-row.outgoing { justify-content: flex-end; }
.message-bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; box-shadow: 0 2px 9px rgba(33, 21, 17, .035); max-width: min(78%, 600px); min-width: 120px; padding: 10px 12px 8px; }
.message-row.outgoing .message-bubble { background: #e5efef; border-color: #d2e4e3; border-radius: 14px 14px 4px 14px; }
.message-text { line-height: 1.42; margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-meta { align-items: center; color: var(--muted); display: flex; font-size: 11px; gap: 8px; justify-content: flex-end; margin-top: 5px; }
.message-meta .status-failed { color: var(--error); font-weight: 700; }
.message-media { color: var(--muted); font-size: 12px; font-style: italic; }
.thread-empty { align-self: center; color: var(--muted); line-height: 1.45; margin: auto; max-width: 340px; padding: 28px; text-align: center; }
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 14px 20px 16px; }
.composer textarea { border: 1px solid #d9cec2; border-radius: 11px; color: var(--pilui-negro); display: block; max-height: 180px; min-height: 72px; padding: 11px 13px; resize: vertical; width: 100%; }
.composer textarea:disabled { background: #f7f2ec; }
.composer textarea:focus-visible { outline-offset: 1px; }
.composer-footer { align-items: center; display: flex; gap: 18px; justify-content: space-between; margin-top: 9px; }
.composer-hint { color: var(--muted); font-size: 12px; line-height: 1.35; margin: 0; }
.composer-footer .button { flex: none; }
.template-panel { background: var(--surface); border-top: 1px solid var(--line); display: grid; gap: 9px; padding: 15px 20px 17px; }
.template-heading { align-items: center; display: flex; justify-content: space-between; gap: 12px; }
.template-heading h3 { font-family: var(--pilui-font-display); font-size: 17px; margin: 4px 0 0; }
.template-label { background: #e7f1f4; border-radius: 99px; color: var(--pilui-anil); font-size: 11px; font-weight: 700; padding: 5px 9px; }
.template-panel > label:not(.template-review) { font-size: 12px; font-weight: 700; }
.template-panel select { background: white; border: 1px solid #d9cec2; border-radius: 9px; color: var(--pilui-negro); min-height: 39px; padding: 8px 10px; width: 100%; }
.template-recipient { color: var(--muted); font-size: 12px; margin: 1px 0 0; }
.template-recipient strong { color: var(--pilui-negro); }
.template-preview { background: var(--pilui-crudo); border: 1px solid var(--line); border-radius: 9px; font-size: 13px; line-height: 1.4; max-height: 130px; min-height: 48px; overflow: auto; overflow-wrap: anywhere; padding: 10px 12px; white-space: pre-wrap; }
.template-review { align-items: flex-start; display: flex; font-size: 12px; gap: 8px; line-height: 1.35; }
.template-review input { accent-color: var(--pilui-anil); margin: 2px 0 0; }
.template-panel .button { justify-self: end; }
.toast { background: var(--pilui-negro); border-radius: 10px; bottom: 22px; box-shadow: var(--shadow); color: white; font-size: 13px; left: 50%; max-width: min(440px, calc(100vw - 32px)); padding: 11px 16px; position: fixed; text-align: center; transform: translateX(-50%); z-index: 20; }

@media (max-width: 850px) {
  .topbar { padding-inline: 16px; }
  .brand-logo { width: 115px; height: 34px; }
  .brand-lockup { gap: 10px; }
  .product-title strong { font-size: 16px; }
  .inbox-layout { grid-template-columns: minmax(250px, 320px) minmax(0, 1fr); }
  .thread-header { padding-inline: 14px; }
  .message-list { padding-inline: 16px; }
}

@media (max-width: 650px) {
  .app-shell { min-height: 0; height: 100dvh; }
  .topbar { min-height: 64px; }
  .brand-logo { width: 91px; height: 31px; }
  .brand-divider { height: 28px; }
  .product-title .eyebrow { display: none; }
  .product-title strong { font-size: 15px; }
  .topbar-actions { gap: 2px; }
  .topbar-actions .button { padding: 7px; }
  .topbar-actions .button span { display: none; }
  .mode-badge { font-size: 10px; padding: 6px 8px; }
  .environment-notice { padding-inline: 16px; }
  .inbox-layout { display: block; position: relative; }
  .conversation-pane, .thread-pane { height: 100%; width: 100%; }
  .thread-pane { display: none; }
  .inbox-layout.has-selection .conversation-pane { display: none; }
  .inbox-layout.has-selection .thread-pane { display: flex; }
  .pane-heading { padding: 20px 16px 14px; }
  .back-button { display: inline-flex; margin-left: -7px; }
  .thread-header { gap: 4px; padding-right: 10px; }
  .thread-header .avatar { height: 36px; width: 36px; }
  .thread-header .button { font-size: 11px; min-height: 35px; padding: 6px 8px; }
  .message-list { padding: 20px 12px 24px; }
  .message-bubble { max-width: 88%; }
  .composer { padding: 10px 12px 12px; }
  .template-panel { padding: 10px 12px 12px; }
  .composer-footer { align-items: flex-end; gap: 10px; }
  .composer-hint { font-size: 11px; }
  .composer-footer .button { font-size: 12px; padding: 8px 9px; }
}

@media (prefers-reduced-motion: reduce) { .button { transition: none; } }
