:root {
  color-scheme: light;
  --ink: #16293a;
  --muted: #647482;
  --line: #dce5e9;
  --paper: #ffffff;
  --canvas: #f6f3ed;
  --accent: #167a65;
  --accent-dark: #0d5e4d;
  --accent-soft: #e4f4ee;
  --warning: #81530b;
  --warning-bg: #fff3d9;
  --danger: #a63d35;
  --thread: #f7fbfa;
  font-family: Arial, "Noto Sans Hebrew", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { outline-offset: 3px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #1a76b8; }
.inbox-body { min-height: 100vh; }
.inbox-shell, .agent-shell { max-width: 1440px; min-height: 100vh; margin: 0 auto; padding: 20px clamp(14px, 3vw, 40px); }
.inbox-topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); padding: 0 0 18px; }
.inbox-topbar h1 { margin: 2px 0 0; font-size: clamp(22px, 3vw, 30px); }
.inbox-kicker { margin: 0; color: var(--accent-dark); font-size: 13px; font-weight: 700; letter-spacing: .02em; }
.inbox-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inbox-nav a { color: var(--ink); text-decoration: none; font-weight: 700; padding: 9px 12px; border-radius: 8px; }
.inbox-nav a:hover { background: #edf4f2; }
.button { border: 1px solid transparent; border-radius: 8px; cursor: pointer; padding: 9px 14px; font-weight: 700; line-height: 1.2; }
.button:disabled { cursor: not-allowed; opacity: .54; }
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--accent-dark); }
.button-quiet { background: transparent; color: var(--ink); border-color: #c9d4d8; }
.button-quiet:hover:not(:disabled) { background: #f0f5f5; }
.button-stop { border-color: #e5b6b1; color: var(--danger); background: #fff; }
.button-stop:hover:not(:disabled) { background: #fff1f0; }
.notice { margin: 14px 0; padding: 11px 14px; background: #e9f2f6; color: #123f5d; border-right: 4px solid #287eae; border-radius: 5px; }
.notice.is-error { color: #7d2823; background: #fff0ef; border-color: #bd4a42; }
.field-hint { margin: 5px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; clip-path: inset(50%); }

.inbox-workspace { display: grid; grid-template-columns: minmax(275px, 360px) minmax(0, 1fr); min-height: calc(100vh - 118px); margin-top: 18px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--paper); }
.thread-sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--thread); border-left: 1px solid var(--line); }
.sidebar-heading, .thread-filters { padding: 15px; border-bottom: 1px solid var(--line); }
.sidebar-heading label, .search-label, .agent-form label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 14px; }
select, input[type="search"], input[type="text"], textarea { width: 100%; border: 1px solid #bfcdd3; border-radius: 7px; background: #fff; color: var(--ink); padding: 9px 10px; }
textarea { resize: vertical; min-height: 54px; line-height: 1.5; }
.search-label { margin: 13px 15px 6px; }
#threadSearch { width: calc(100% - 30px); margin: 0 15px 13px; }
.thread-filters { margin: 0; border: 0; }
.thread-filters legend { font-size: 13px; font-weight: 700; padding: 0; }
.filter-list { display: flex; flex-wrap: wrap; gap: 7px; padding-top: 8px; }
.filter-chip { border: 1px solid #c5d2d5; border-radius: 999px; background: #fff; color: var(--ink); padding: 5px 9px; cursor: pointer; font-size: 12px; }
.filter-chip.is-active { color: #fff; border-color: var(--accent); background: var(--accent); }
.threads-list { min-height: 0; overflow-y: auto; }
.thread-row { width: 100%; border: 0; border-bottom: 1px solid #e2e9eb; background: transparent; text-align: right; cursor: pointer; padding: 13px 15px; color: inherit; }
.thread-row:hover, .thread-row.is-selected { background: #e5f4ee; }
.thread-row-heading { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.thread-row strong { font-size: 14px; overflow-wrap: anywhere; }
.thread-row time { color: var(--muted); font-size: 11px; white-space: nowrap; direction: ltr; }
.thread-preview { display: block; overflow: hidden; color: #52636d; font-size: 13px; line-height: 1.4; margin-top: 5px; text-overflow: ellipsis; white-space: nowrap; }
.thread-row-meta { display: flex; gap: 6px; margin-top: 7px; align-items: center; }
.thread-pill, .mode-badge { border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 700; }
.thread-pill.agent, .mode-badge.agent { background: #e0efff; color: #195a90; }
.thread-pill.manual, .mode-badge.manual { background: #eceff2; color: #425563; }
.thread-pill.unanswered { background: #fff0d4; color: #865711; }
.threads-empty, .messages-empty { padding: 24px 15px; color: var(--muted); text-align: center; line-height: 1.5; }
.load-older { display: block; width: calc(100% - 30px); margin: 12px 15px; }

.chat-panel { display: flex; min-height: 0; background: #f1eee7; }
.chat-empty { align-self: center; width: 100%; padding: 36px; text-align: center; color: var(--muted); }
.chat-empty h2 { color: var(--ink); }
.chat-content { display: flex; flex-direction: column; min-width: 0; width: 100%; min-height: 0; }
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px clamp(15px, 2.5vw, 28px); background: #fff; border-bottom: 1px solid var(--line); }
.thread-person h2 { margin: 3px 0 0; font-size: 16px; }
.thread-phone { margin: 0; color: #4a5e69; direction: ltr; text-align: right; font-size: 14px; overflow-wrap: anywhere; }
.account-link { display: inline-block; color: #176c9c; margin-top: 5px; font-size: 12px; font-weight: 700; }
.thread-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: end; }
.stopped-banner { margin: 0; padding: 9px clamp(15px, 2.5vw, 28px); background: var(--warning-bg); color: var(--warning); border-bottom: 1px solid #efd9ac; font-size: 13px; font-weight: 700; }
.messages-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 12px clamp(15px, 3vw, 34px); }
.messages-list { display: flex; flex-direction: column; gap: 9px; }
.message-row { display: flex; flex-direction: column; align-items: flex-start; max-width: 78%; }
.message-row.out { align-self: flex-end; align-items: flex-end; }
.message-bubble { position: relative; max-width: 100%; padding: 10px 12px 7px; overflow-wrap: anywhere; background: #fff; border: 1px solid #e0e0dc; border-radius: 10px; border-top-right-radius: 2px; white-space: pre-wrap; line-height: 1.45; }
.message-row.out .message-bubble { background: #dff2e7; border-color: #c5e4d2; border-top-right-radius: 10px; border-top-left-radius: 2px; }
.message-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: #687781; font-size: 11px; }
.message-source { font-weight: 700; }
.message-stop { margin-top: 5px; padding: 4px 8px; font-size: 11px; }
.composer { background: #fff; border-top: 1px solid var(--line); padding: 12px clamp(15px, 2.5vw, 28px); }
.composer textarea:disabled { background: #f1f3f4; color: #65737c; }
.composer-footer { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-top: 7px; }
.composer-footer .field-hint { margin: 0; }

.agent-shell { max-width: 1480px; }
.agents-workspace { display: grid; grid-template-columns: minmax(250px, 330px) minmax(0, 1fr); min-height: calc(100vh - 118px); margin-top: 18px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--paper); }
.agents-sidebar { background: var(--thread); border-left: 1px solid var(--line); }
.agents-sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px; border-bottom: 1px solid var(--line); }
.agents-sidebar h2 { margin: 0; font-size: 17px; }
.ai-status { margin: 12px 16px; padding: 9px; border-radius: 6px; background: var(--warning-bg); color: var(--warning); font-size: 13px; line-height: 1.5; }
.ai-status.is-ready { background: var(--accent-soft); color: var(--accent-dark); }
.agent-list-item { width: 100%; padding: 13px 16px; background: transparent; border: 0; border-bottom: 1px solid var(--line); text-align: right; cursor: pointer; color: var(--ink); }
.agent-list-item:hover, .agent-list-item.is-selected { background: #e5f4ee; }
.agent-list-item strong, .agent-list-item span { display: block; }
.agent-list-item span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.agent-editor-panel { min-width: 0; overflow-y: auto; padding: clamp(18px, 3vw, 34px); }
.agent-form { max-width: 980px; margin: 0 auto; }
.editor-heading, .templates-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.editor-heading { border-bottom: 1px solid var(--line); padding-bottom: 15px; margin-bottom: 17px; }
.editor-heading h2 { margin: 3px 0 0; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.mode-choice, .numbers-choice { min-width: 0; margin: 0; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.mode-choice legend, .numbers-choice legend { padding: 0 4px; font-weight: 700; font-size: 14px; }
.mode-choice label, .checkbox-label { display: block; font-weight: 400; margin: 7px 0; }
.checkbox-list { display: grid; gap: 8px; }
.checkbox-list label { display: flex; gap: 7px; align-items: start; }
.checkbox-list small { color: var(--muted); }
.templates-section { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
.templates-heading h3 { margin: 0; }
.templates-list { display: grid; gap: 10px; margin-top: 13px; }
.template-row { display: grid; grid-template-columns: minmax(120px, .4fr) minmax(0, 1fr) auto; align-items: start; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfc; }
.template-row textarea { min-height: 42px; }
.template-remove { color: var(--danger); border-color: #e5b6b1; }
.agent-activation { margin-top: 19px; padding: 10px 12px; border-radius: 8px; background: #f5f8f8; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.form-error { margin: 12px 0 0; color: #a22d28; font-weight: 700; }
.access-state { max-width: 560px; margin: 48px auto; padding: 28px; background: #fff; border: 1px solid var(--line); border-radius: 12px; text-align: center; }
.access-state .button { display: inline-block; margin-top: 8px; text-decoration: none; }

@media (max-width: 760px) {
  .inbox-shell, .agent-shell { padding: 12px; }
  .inbox-topbar { align-items: flex-start; flex-direction: column; gap: 10px; }
  .inbox-workspace, .agents-workspace { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .thread-sidebar, .agents-sidebar { border-left: 0; border-bottom: 1px solid var(--line); max-height: 47vh; }
  .chat-panel { min-height: 58vh; }
  .field-grid { grid-template-columns: minmax(0, 1fr); }
  .template-row { grid-template-columns: minmax(0, 1fr); }
  .template-remove { justify-self: start; }
  .chat-header { align-items: flex-start; flex-direction: column; }
  .thread-actions { justify-content: start; }
  .message-row { max-width: 90%; }
}
