@font-face { font-family: 'Material Symbols Rounded'; font-style: normal; font-weight: 500; font-display: block; src: url('/assets/material-symbols-rounded.ttf') format('truetype'); }
.material-symbols-rounded { font-family: 'Material Symbols Rounded'; font-weight: 500; font-style: normal; letter-spacing: 0; text-transform: none; white-space: nowrap; font-feature-settings: 'liga'; -webkit-font-smoothing: antialiased; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.mobile-only, .mobile-navigation, .mobile-menu-backdrop { display: none; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, [role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.inbox-head-actions { display: flex; align-items: center; gap: 12px; }
.inbox-search-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.inbox-search { flex: 1; position: relative; min-width: 0; }
.inbox-search > .material-symbols-rounded { position: absolute; left: 12px; top: 12px; color: #61736c; }
.inbox-search input { margin: 0; padding-left: 38px; }
.inbox-segments { display: flex; align-items: center; gap: 4px; padding: 12px 0; }
.inbox-segments button { padding: 0 14px; min-height: 36px; font-size: 13px; background: transparent; color: var(--muted); }
.inbox-segments button[aria-pressed="true"] { background: rgba(45,212,191,.14); color: var(--accent-soft); }
#inboxFilterSummary { margin-left: auto; font-size: 12px; }
.conversation-workspace { grid-template-columns: minmax(280px, 350px) minmax(0, 1fr); height: calc(100dvh - 154px); min-height: 480px; }
.conversation-sidebar-panel { overflow: hidden; }
.conversation-sidebar-panel .start-thread-form, #conversationFilters { flex-shrink: 0; max-height: 45%; overflow-y: auto; }
.conversation-list { flex: 1; align-content: start; overscroll-behavior: contain; }
.conversation-top strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-top time { flex: 0 0 auto; font-size: 11px; color: var(--muted); font-weight: normal; }
.conversation-preview { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.conversation-preview.has-draft { color: var(--warm); }
.conversation-meta .unread-badge { margin-left: auto; }
.thread-head { flex-wrap: wrap; align-items: center; gap: 10px; }
.thread-identity { flex: 1; min-width: 0; }
.thread-head h2 { overflow-wrap: anywhere; }
.thread-meta { gap: 6px 10px; }
.last-message-pill { width: 100%; white-space: normal; border: 0; background: rgba(244,184,96,.08); border-radius: 4px; }
.messages { min-height: 0; overscroll-behavior: contain; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.message small { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; font-size: 11px; }
.message-status { text-transform: capitalize; }
.reply-composer { flex: 0 0 auto; gap: 6px; }
.reply-template-row { display: flex; justify-content: space-between; align-items: center; }
.template-control { display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 70%; }
.template-control select { min-width: 0; width: auto; max-width: 100%; min-height: 36px; margin: 0; padding: 4px 8px; font-size: 13px; }
#replyDraftStatus { font-size: 11px; }
.composer-input-row { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 8px; align-items: end; }
.composer-input-row textarea { margin: 0; min-height: 44px; max-height: 120px; resize: none; line-height: 1.45; }
.composer-input-row .icon-btn { width: 44px; height: 44px; }
.composer-footer { display: flex; justify-content: flex-end; color: var(--muted); font-size: 11px; }
.contact-suggestions { display: grid; max-height: 200px; overflow: auto; }
.contact-suggestion { display: grid; justify-content: stretch; text-align: left; padding: 10px; background: transparent; border-bottom: 1px solid var(--line); color: var(--text); white-space: normal; }
.contact-suggestion span { font-size: 12px; color: var(--muted); }
.empty-inbox { display: grid; justify-items: center; align-content: center; min-height: 180px; gap: 12px; color: var(--muted); }
.empty-inbox .material-symbols-rounded { font-size: 32px; }
.mobile-contact-search { display: block; margin-bottom: 16px; }
.contact-name { min-height: 44px; background: transparent; color: inherit; padding: 0; text-align: left; white-space: normal; justify-content: flex-start; }
.modal-card { max-height: calc(100dvh - 44px); overflow-y: auto; }

@media (min-width: 761px) and (max-width: 1100px) {
  .app-shell { grid-template-columns: 84px minmax(0, 1fr); }
  .sidebar { position: sticky; height: 100dvh; padding: 16px 10px; }
  .sidebar .brand-word, .sidebar .nav-btn > span:last-child, .sidebar .ghost-btn > span:last-child { display: none; }
  .sidebar .brand-row, .sidebar .nav-btn, .sidebar .ghost-btn { justify-content: center; }
  .content { padding: 18px; }
  .topbar { flex-direction: row; }
  .topbar h1 { font-size: 26px; }
  .topbar p, .user-pill { display: none; }
  .conversation-workspace { grid-template-columns: minmax(240px, .75fr) minmax(0, 1fr); }
  .thread-controls { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px), (max-width: 1000px) and (max-height: 500px) and (pointer: coarse) {
  :root { --bg: #f7f9f8; --panel: #fff; --panel-2: #fff; --text: #192d26; --muted: #607168; --ink: #192d26; --line: #e0e7e3; --soft: #fff; --accent: #087f60; --accent-soft: #087454; --warm: #9b640e; --danger: #b33142; }
  html { background: var(--bg); -webkit-text-size-adjust: 100%; }
  body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
  body.workspace-authenticated { overflow: hidden; }
  .mobile-only { display: inline-flex; }
  button { min-height: 44px; font-weight: 600; color: white; touch-action: manipulation; }
  button, input, select, textarea { letter-spacing: 0; }
  input, select, textarea { font-size: 16px; font-weight: 400; min-height: 44px; background: #fff; border-color: #cfdad4; }
  select { padding-right: 28px; text-overflow: ellipsis; }
  label { font-size: 12px; font-weight: 600; min-width: 0; }
  .secondary-btn { background: #edf5f0; border-color: #c8dfd1; color: #146d50; }
  .danger-btn { background: #fff0f1; border-color: #edc4ca; color: #a82f41; }
  .small-btn, .icon-btn { min-height: 44px; }
  .icon-btn { min-width: 44px; width: 44px; }
  .login-shell { min-height: 100dvh; padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom)); background: var(--bg); }
  .login-card { padding: 28px 0; background: transparent; border: 0; box-shadow: none; }
  .login-card .brand-row { margin-bottom: 36px; }
  .login-card h1 { font-size: 26px; }
  .login-card button { width: 100%; }
  .brand-word { color: #193e30; }
  .app-shell { position: fixed; top: var(--app-top, 0px); left: 0; right: 0; height: var(--app-height, 100dvh); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .content { display: flex; flex-direction: column; min-height: 0; flex: 1; max-width: none; padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); overflow: hidden; }
  .topbar { flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 10px 0; margin: 0; }
  .topbar h1 { font-size: 25px; line-height: 1.2; margin: 0; overflow-wrap: anywhere; }
  .topbar p, .user-pill { display: none; }
  .top-actions { display: contents; }
  #refreshBtn { width: 44px; height: 44px; background: transparent; color: var(--text); }
  #refreshBtn > span:last-child { display: none; }
  .scope-control { width: 100%; grid-column: 1 / -1; grid-row: 2; }
  .scope-control select { margin-top: 5px; }
  .view { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding-bottom: 16px; }
  #conversationsView { padding: 0; overflow: hidden; }
  .panel { background: transparent; box-shadow: none; border: 0; border-radius: 0; padding: 16px 0; margin: 0; min-width: 0; }
  .panel h2 { font-size: 18px; }
  .two-col, .agent-layout { display: flex; flex-direction: column; gap: 12px; margin: 0; }
  .two-col > *, .agent-layout > * { min-width: 0; }
  .mobile-form-toggle { width: 100%; justify-content: flex-start; padding: 0 14px; margin: 8px 0 0; }
  .mobile-form-collapsed:not(.mobile-form-expanded) { display: none; }
  .stack { gap: 16px; }
  .stats-grid, .analytics-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
  .stat { box-shadow: none; padding: 14px; background: #fff; }
  .stat span { font-size: 12px; font-weight: 600; }
  .stat strong { font-size: 28px; font-weight: 650; }
  .analytics-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .notice { flex: 0 0 auto; padding: 10px 12px; margin: 4px 0 8px; background: #eaf6ed; color: #285c3c; font-size: 13px; overflow-wrap: anywhere; }
  .notice.error { background: #fff0f1; color: #a82f41; }
  .mobile-navigation { display: grid; flex: 0 0 auto; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--line); padding: 4px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); background: #fff; }
  .mobile-navigation button { display: flex; flex-direction: column; gap: 3px; padding: 6px 2px; min-height: 52px; background: transparent; color: #68786e; font-size: 11px; border-radius: 6px; }
  .mobile-navigation button.active { color: #087454; background: #edf6f0; }
  .mobile-navigation .material-symbols-rounded { font-size: 23px; }
  .nav-icon-wrap { position: relative; height: 23px; }
  .nav-unread { position: absolute; left: 16px; top: -5px; min-width: 17px; padding: 2px 4px; border: 2px solid white; border-radius: 20px; background: #a34722; color: #fff; font-size: 9px; }
  .sidebar { display: none; }
  .sidebar.mobile-menu-open { display: flex; position: absolute; inset: 0 0 0 auto; width: min(340px, 92%); height: 100%; padding: max(24px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom)); z-index: 41; background: #fff; border: 0; box-shadow: -12px 0 40px #0e261d26; gap: 24px; overflow: auto; }
  .sidebar .brand-row { padding-right: 40px; justify-content: flex-start; }
  .sidebar .brand-word, .sidebar .nav-btn > span:last-child, .sidebar .ghost-btn > span:last-child { display: inline; }
  .sidebar .nav-btn, .sidebar .ghost-btn { justify-content: flex-start; }
  .sidebar .brand-icon { width: 36px; height: 36px; }
  .sidebar .brand-word { font-size: 22px; }
  .mobile-account { font-size: 13px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
  #mobileMenuClose { position: absolute; top: max(18px, env(safe-area-inset-top)); right: 12px; color: var(--text); background: transparent; }
  .sidebar nav { gap: 4px; }
  .sidebar .nav-btn { min-height: 46px; color: #51675a; }
  .sidebar .nav-btn.active { background: #edf6f0; color: #087454; }
  .sidebar .ghost-btn { min-height: 44px; }
  .mobile-menu-backdrop { display: block; position: absolute; inset: 0; width: 100%; height: 100%; z-index: 40; background: #0d231d66; border-radius: 0; }
  .conversation-workspace { display: flex; height: 100%; min-height: 0; gap: 0; }
  .conversation-sidebar-panel { flex: 1; padding: 0; min-width: 0; }
  .conversation-thread-panel { display: none; }
  .panel-head { align-items: center; padding: 4px 0 10px; border: 0; }
  .panel-head h2 { font-size: 16px; color: var(--muted); font-weight: 500; }
  .counter-pill { min-height: 24px; border: 0; padding: 0; color: var(--muted); font-weight: 500; }
  .inbox-head-actions { gap: 14px; }
  .inbox-search-row { margin: 0; }
  .inbox-search input { border: 0; background: #eaf0ec; }
  #conversationFiltersToggle { border: 0; background: #eaf0ec; color: #3d5d4b; }
  .inbox-segments { padding: 10px 0; }
  .inbox-segments button { min-height: 40px; color: #6a776f; }
  .inbox-segments button[aria-pressed="true"] { background: #e2f0e7; color: #106b4b; }
  #inboxUnreadCount { font-size: 11px; }
  #conversationFilters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; padding: 12px; background: #edf2ef; border-radius: 8px; }
  .start-thread-form { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px 0; margin-bottom: 10px; }
  .start-thread-form label:first-child { grid-column: 1 / -1; }
  .start-thread-form label:nth-child(2) { grid-column: 1 / -1; }
  .conversation-sidebar-panel .start-thread-form { max-height: 60%; }
  .conversation-list { margin: 0 -16px; padding: 0; gap: 0; }
  .conversation-item { border: 0; border-bottom: 1px solid #e8edea; border-radius: 0; padding: 15px 16px; background: #fff; gap: 5px; }
  .conversation-item.active { border-color: #d6e8de; background: #eef7f1; box-shadow: inset 3px 0 #087f60; }
  .conversation-top strong { font-size: 15px; font-weight: 650; margin: 0; }
  .conversation-top time { font-size: 10px; }
  .conversation-meta { gap: 5px 10px; font-size: 11px; }
  .conversation-meta .status-badge { min-height: 20px; padding: 1px 5px; font-size: 10px; border-radius: 4px; }
  .conversation-preview { font-size: 14px; color: #65746b; line-height: 1.45; }
  .unread-badge { min-height: 20px; min-width: 20px; padding: 2px 5px; font-size: 10px; background: #087f60; color: white; }
  .list-pagination { padding: 12px 16px; }
  .mobile-thread-open .topbar, .mobile-thread-open .mobile-navigation { display: none; }
  .mobile-thread-open .content { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .mobile-thread-open .conversation-sidebar-panel { display: none; }
  .mobile-thread-open .conversation-thread-panel { display: flex; flex: 1; min-width: 0; padding: 0; }
  .thread-head { flex: 0 0 auto; gap: 4px 6px; padding: 6px 0 10px; border-bottom: 1px solid var(--line); }
  .thread-head h2 { font-size: 17px; font-weight: 650; line-height: 1.3; }
  #threadBackBtn { background: transparent; color: #0c7152; margin-left: -6px; }
  #threadDetailsBtn { background: transparent; border: 0; color: #546b5e; }
  .thread-meta { margin-top: 2px; font-size: 11px; gap: 2px 8px; }
  .thread-meta span:first-child, .thread-meta span:nth-child(2), .thread-meta .status-badge { display: none; }
  .last-message-pill { padding: 6px 10px; min-height: 26px; font-size: 11px; font-weight: 500; background: #fbf4e6; color: #896019; border-radius: 4px; }
  .thread-controls { flex: 0 1 auto; max-height: 42%; overflow: auto; grid-template-columns: minmax(0, 1fr); padding: 10px 0; }
  .thread-controls .inline-form { grid-template-columns: minmax(0, 1fr) 100px; }
  .messages { padding: 16px 0; gap: 10px; }
  .message { max-width: 88%; border: 1px solid #e1e8e3; background: #fff; color: #213b2d; font-size: 15px; padding: 10px 12px; }
  .message.outgoing { background: #e0f1e6; border-color: #d2e8d9; color: #183e2a; }
  .message small { color: #647a6c; opacity: 1; font-size: 10px; line-height: 1.4; }
  .delivery-mark { color: #087454; min-width: 0; margin-left: 3px; }
  .empty-thread { border: 0; min-height: 120px; font-size: 14px; padding: 20px; }
  .reply-composer { padding: 8px 0 max(8px, env(safe-area-inset-bottom)); gap: 5px; background: var(--bg); }
  .template-control { max-width: 70%; }
  .template-control select { font-size: 16px; min-height: 44px; height: 44px; max-width: 190px; background: transparent; border: 0; color: #486452; }
  .template-control > .material-symbols-rounded { color: #6d8173; font-size: 20px; }
  .composer-input-row textarea { font-size: 16px; padding: 10px 12px; background: white; }
  .composer-footer { font-size: 10px; padding-right: 52px; }
  .keyboard-open .mobile-navigation { display: none; }
  .keyboard-open .reply-composer { padding-bottom: 5px; }
  .keyboard-open .reply-template-row { display: none; }
  .table-wrap { overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tr { background: white; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }
  td { display: grid; grid-template-columns: minmax(85px, .7fr) minmax(0, 1.3fr); align-items: start; gap: 8px; padding: 9px 0; font-size: 13px; overflow-wrap: anywhere; color: var(--text); }
  td::before { content: attr(data-label); color: var(--muted); font-size: 11px; padding-top: 2px; font-weight: 500; }
  td:last-child { border: 0; }
  td input, td select { max-width: 100%; }
  td .cell-actions { grid-column: 1 / -1; }
  td[data-label="Actions"] { display: flex; justify-content: flex-end; flex-wrap: wrap; }
  td[data-label="Actions"]::before { display: none; }
  #contactsList tbody { gap: 0; }
  #contactsList tr { display: grid; grid-template-columns: minmax(0, 1fr) 44px; column-gap: 12px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 10px 12px; }
  #contactsList td { display: block; border: 0; padding: 0; }
  #contactsList td::before { display: none; }
  #contactsList td[data-label="Name"] { grid-column: 1; grid-row: 1; }
  #contactsList td[data-label="Phone"] { grid-column: 1; grid-row: 2; color: var(--muted); font-size: 13px; }
  #contactsList td[data-label="Email"], #contactsList td[data-label="Organization"] { display: none; }
  #contactsList td[data-label="Actions"] { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  #contactsList [data-message-contact] { width: 44px; padding: 0; }
  #contactsList [data-message-contact] > span:last-child { display: none; }
  #contactsList .contact-name { font-size: 15px; min-height: 44px; width: 100%; font-weight: 600; }
  .status-badge { font-weight: 600; }
  .status-badge.active, .status-badge.online, .status-badge.open { background: #edf8ef; color: #23743d; border-color: #cee7d2; }
  .status-badge.pending, .status-badge.snoozed { background: #fcf5e8; color: #926715; border-color: #e9d7ae; }
  .list-item { background: #fff; box-shadow: none; }
  .modal-overlay { top: var(--app-top, 0px); bottom: auto; height: var(--app-height, 100dvh); padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); align-items: end; }
  .modal-card { max-height: 100%; box-shadow: 0 10px 40px #142c2626; background: #fff; padding: 18px; }
  .modal-head { margin-bottom: 20px; }
  .modal-head h2 { font-size: 19px; }
  .modal-head .icon-btn { color: #355443; background: #edf2ef; }
  .modal-actions { flex-direction: row; }
  .modal-actions button { flex: 1; }
  .readonly-grid { padding: 10px; }
  .readonly-row { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .token-box { grid-template-columns: 1fr 1fr; }
  .token-box label { grid-column: 1 / -1; }
  .inline-actions button { flex: 1; white-space: normal; padding: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
