:root {
  --ink: #17201d;
  --muted: #68736f;
  --line: #dfe7e2;
  --surface: #ffffff;
  --surface-soft: #f5f8f6;
  --brand: #0d6b5f;
  --brand-strong: #084c45;
  --accent: #e0a526;
  --danger: #bb3f35;
  --note: #eef3ff;
  --shadow: 0 18px 45px rgba(23, 32, 29, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(13, 107, 95, 0.1), transparent 32%),
    linear-gradient(315deg, rgba(224, 165, 38, 0.12), transparent 30%),
    #eef4f1;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 32, 29, 0.86);
}

.auth-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 24px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand span {
  color: var(--muted);
}

.auth-card h1 {
  font-size: 28px;
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.auth-card input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.auth-card small {
  color: var(--muted);
  line-height: 1.45;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: #10201d;
  color: #f5fbf8;
}

.brand,
.agent-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #316ee2;
  color: #18201c;
  font-weight: 900;
}

.brand span,
.agent-card span {
  display: block;
  color: #b9c8c2;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 0 12px;
  color: #dbe8e4;
  background: transparent;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.agent-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.agent-card i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 50%;
  background: #65d18f;
}

.agent-photo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 32%, #f5d6b7 0 18%, transparent 19%),
    linear-gradient(145deg, #49a08b, #e0a526);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar,
.panel-heading,
.chat-header,
.reply-actions,
.reply-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.realtime-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0 10px;
  background: #dff3ed;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  width: min(360px, 42vw);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search-box span {
  color: var(--muted);
  font-size: 13px;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.primary-action,
.secondary-action,
.ghost-action,
.tool-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary-action {
  background: var(--brand);
  color: white;
}

.primary-action:hover {
  background: var(--brand-strong);
}

.secondary-action {
  width: 100%;
  background: #132420;
  color: white;
}

.ghost-action,
.tool-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 22px 0;
}

.metric {
  min-height: 116px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.metric span,
.metric small,
.muted {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 30px;
}

.support-layout {
  display: grid;
  grid-template-columns: 330px minmax(380px, 1fr) 310px;
  gap: 14px;
  min-height: calc(100vh - 210px);
}

.conversation-list,
.chat-panel,
.details-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.conversation-list,
.details-panel {
  padding: 16px;
}

.compact {
  align-items: flex-start;
}

.panel-heading select,
.ticket-card select,
.ticket-card input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface);
}

.thread-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.thread-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
}

.thread-item.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13, 107, 95, 0.12);
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #dfeee8;
  color: var(--brand-strong);
  font-weight: 900;
}

.thread-summary {
  min-width: 0;
}

.thread-title,
.thread-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.thread-title strong,
.thread-summary p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-summary p {
  margin: 6px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.thread-meta {
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--surface-soft);
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
}

.pill.priority {
  background: #fff1d2;
  color: #8c5c00;
}

.pill.resolved {
  background: #e7f4ec;
  color: #2f6f48;
}

.chat-panel {
  display: grid;
  min-height: 640px;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  padding: 30px;
  text-align: center;
}

.empty-state div {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 14px;
  border-radius: 50%;
  background: #dfeee8;
  color: var(--brand);
  font-size: 34px;
  font-weight: 900;
}

.empty-state p {
  max-width: 310px;
  color: var(--muted);
}

.chat-active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 640px;
}

.hidden {
  display: none !important;
}

.chat-header {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.status-actions {
  display: flex;
  gap: 8px;
}

.message-stream {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.72)),
    repeating-linear-gradient(135deg, #edf4f1 0 1px, transparent 1px 16px);
}

.message {
  max-width: min(78%, 560px);
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(23, 32, 29, 0.08);
}

.message.agent {
  align-self: flex-end;
  background: #dff3ed;
}

.message.note {
  align-self: center;
  max-width: 90%;
  background: var(--note);
  color: #334064;
  font-size: 13px;
}

.message small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
}

.reply-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.reply-box textarea {
  width: 100%;
  resize: vertical;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  outline-color: var(--brand);
}

.reply-tools select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

#typing-hint {
  color: var(--muted);
  font-size: 13px;
}

.customer-details {
  display: grid;
  gap: 12px;
  margin: 16px 0 18px;
}

.detail-row {
  display: grid;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-row span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.detail-row strong {
  word-break: break-word;
}

.ticket-card {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.ticket-card form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.ticket-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.visitor-widget {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  display: grid;
  justify-items: end;
  gap: 10px;
}

.widget-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border: 0;
  border-radius: 999px;
  padding: 0 16px;
  background: #132420;
  color: white;
  box-shadow: var(--shadow);
}

.widget-toggle strong {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #151811;
  font-size: 12px;
}

.widget-window {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(360px, calc(100vw - 28px));
  height: 470px;
  overflow: hidden;
  border: 1px solid #cbd9d3;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.widget-window.collapsed {
  display: none;
}

.widget-window header {
  padding: 14px;
  background: var(--brand);
  color: white;
}

.widget-window header span {
  display: block;
  margin-top: 3px;
  color: #d7eee8;
  font-size: 12px;
}

.visitor-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 14px;
  background: var(--surface-soft);
}

.visitor-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.visitor-form input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

.visitor-form button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: var(--brand);
  color: white;
  font-weight: 800;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.visitor-page {
  display: grid;
  place-items: center;
  padding: 18px;
}

.visitor-chat-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(720px, 100%);
  height: min(760px, calc(100vh - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.visitor-chat-header {
  padding: 16px;
  background: #10201d;
  color: #f5fbf8;
}

.visitor-chat-header .brand span {
  color: #b9c8c2;
}

.visitor-start {
  display: grid;
  align-content: center;
  gap: 16px;
  padding: 24px;
}

.visitor-start h1 {
  font-size: 30px;
}

.visitor-start-form {
  display: grid;
  gap: 14px;
}

.visitor-start-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.visitor-start-form input,
.visitor-start-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  outline-color: var(--brand);
}

.visitor-chat {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}

.visitor-page-feed {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 18px;
  background: var(--surface-soft);
}

.visitor-page-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.visitor-page-form input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline-color: var(--brand);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .brand div:not(.brand-mark),
  .agent-card div:not(.agent-photo),
  .nav-item span {
    display: none;
  }

  .sidebar {
    padding: 18px;
  }

  .support-layout {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .details-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
  }

  .nav-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(44px, auto);
    margin-left: auto;
  }

  .agent-card {
    display: none;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    width: 100%;
  }

  .metrics-grid,
  .support-layout {
    grid-template-columns: 1fr;
  }

  .chat-panel,
  .chat-active {
    min-height: 560px;
  }

  .visitor-widget {
    right: 12px;
    bottom: 12px;
  }
}
