:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #697386;
  --line: #dfe3eb;
  --line-strong: #c6ccd8;
  --brand: #ef7d22;
  --brand-strong: #c65f12;
  --teal: #0f766e;
  --blue: #2563eb;
  --danger: #b42318;
  --soft: #eef2f7;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(239, 125, 34, 0.12), rgba(15, 118, 110, 0.1)),
    var(--bg);
}

.login-panel {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 18px;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
}

.login-panel h1 {
  margin: 0 0 24px;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form label,
.select-label {
  color: var(--muted);
  font-size: 13px;
}

.login-form input,
.thread-panel select,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.login-form input {
  min-height: 48px;
  padding: 0 14px;
}

.login-form input:focus,
.thread-panel select:focus,
.composer textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(239, 125, 34, 0.18);
}

.login-form button,
.composer button[type="submit"] {
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.login-form button {
  min-height: 48px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.workspace-view {
  height: 100vh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}

.thread-panel {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  z-index: 4;
}

.thread-top,
.chat-header,
.composer-row,
.composer-options {
  display: flex;
  align-items: center;
}

.thread-top {
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.thread-top h2,
.chat-title-block h1 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: 0;
}

.thread-top h2 {
  font-size: 22px;
}

.chat-title-block h1 {
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover,
.thread-item:hover,
.ghost-button:hover {
  background: var(--soft);
}

.thread-panel select {
  min-height: 40px;
  padding: 0 10px;
}

.thread-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

.thread-item {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  min-height: 66px;
  color: var(--ink);
}

.thread-item.is-active {
  border-color: rgba(239, 125, 34, 0.65);
  background: #fff7ed;
}

.thread-item strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
  max-height: 36px;
  overflow: hidden;
}

.thread-item span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghost-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.chat-panel {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
}

.chat-header {
  gap: 12px;
  justify-content: space-between;
  min-height: 68px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.chat-title-block {
  min-width: 0;
  flex: 1;
}

.agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--line-strong);
}

.agent-badge.is-online .status-dot {
  background: var(--teal);
}

.agent-badge.is-busy .status-dot {
  background: var(--brand);
}

.agent-badge.is-offline .status-dot {
  background: var(--danger);
}

.message-list {
  min-height: 0;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: min(760px, 88%);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid transparent;
}

.message.user {
  align-self: flex-end;
  background: #1f2937;
  color: #fff;
}

.message.assistant {
  align-self: flex-start;
  background: #fff;
  border-color: var(--line);
}

.message.system {
  align-self: center;
  max-width: min(720px, 94%);
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
  font-size: 13px;
}

.job-card {
  align-self: flex-start;
  max-width: min(760px, 92%);
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

.job-card strong {
  color: var(--ink);
}

.job-events {
  margin-top: 8px;
  display: grid;
  gap: 5px;
}

.job-events span {
  display: block;
}

.assistant-draft {
  color: var(--ink);
  white-space: pre-wrap;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  min-height: 0;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  letter-spacing: 0;
}

.empty-mark {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(239, 125, 34, 0.8), rgba(15, 118, 110, 0.85)),
    #fff;
}

.composer {
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--line);
}

.composer-row {
  gap: 10px;
}

.composer textarea {
  resize: none;
  min-height: 46px;
  max-height: 150px;
  padding: 11px 12px;
  line-height: 1.45;
}

.composer button[type="submit"] {
  width: 74px;
  min-height: 46px;
}

.composer button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer-options {
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
  color: var(--muted);
  font-size: 12px;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.toggle-line input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

.composer-status {
  text-align: right;
}

.mobile-only {
  display: none;
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .login-view {
    justify-items: start;
    padding: 16px 24px;
  }

  .workspace-view {
    grid-template-columns: 1fr;
  }

  .thread-panel {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(310px, 88vw);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .thread-panel.is-open {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-grid;
  }

  .chat-header {
    min-height: 62px;
    padding: 10px 12px;
  }

  .chat-title-block h1 {
    font-size: 17px;
  }

  .agent-badge {
    min-height: 30px;
    padding: 0 8px;
    font-size: 12px;
  }

  .message-list {
    padding: 12px;
    gap: 10px;
  }

  .message {
    max-width: 94%;
    padding: 10px 12px;
    font-size: 14px;
  }

  .composer {
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  }

  .composer-row {
    gap: 8px;
  }

  .composer button[type="submit"] {
    width: 64px;
  }

  .login-panel {
    width: 300px;
    max-width: calc(100vw - 48px);
    padding: 22px;
  }
}

@media (max-width: 340px) {
  .login-view {
    padding: 12px;
  }

  .login-panel {
    width: 272px;
    max-width: calc(100vw - 24px);
    padding: 18px;
  }

  .login-panel h1 {
    font-size: 25px;
  }

  .agent-badge span:last-child {
    max-width: 54px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .composer button[type="submit"] {
    width: 58px;
  }
}
