:root {
  color-scheme: dark;
  --bg: #11130f;
  --surface: #191c17;
  --surface-2: #20241e;
  --surface-3: #292e26;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f4f4ec;
  --muted: #a8ad9f;
  --accent: #f0c52f;
  --accent-strong: #ffd84f;
  --accent-ink: #1b1a11;
  --danger: #ff8278;
  --success: #8bd29a;
  --radius: 18px;
  font-family: Inter, Onest, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(240, 197, 47, 0.4);
  outline-offset: 2px;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 10%, rgba(240, 197, 47, 0.12), transparent 38%),
    linear-gradient(145deg, #0f110d, #191c16);
}

.auth-card {
  width: min(100%, 440px);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(25, 28, 23, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
  font-size: 25px;
  box-shadow: 0 12px 32px rgba(240, 197, 47, 0.18);
}
.brand-mark-small { width: 40px; height: 40px; border-radius: 12px; font-size: 20px; }
.eyebrow { margin: 20px 0 6px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
.auth-card h1 { margin-bottom: 10px; font-size: clamp(27px, 6vw, 38px); letter-spacing: -0.04em; }
.auth-copy { color: var(--muted); line-height: 1.55; }
.auth-form { display: grid; gap: 17px; margin-top: 24px; }
.auth-form label { display: grid; gap: 8px; color: #d9dccf; font-size: 14px; }
.auth-form input, .composer textarea, .chat-actions select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--text);
  padding: 13px 14px;
}
.auth-form input:focus, .composer textarea:focus, .chat-actions select:focus { border-color: rgba(240, 197, 47, 0.58); }
.alert { margin: 18px 0; padding: 13px 15px; border-radius: 12px; font-size: 14px; line-height: 1.45; }
.alert-error { background: rgba(255, 130, 120, 0.12); border: 1px solid rgba(255, 130, 120, 0.3); color: #ffc2bd; }

.button {
  min-height: 43px;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 750;
  transition: transform 140ms ease, background-color 140ms ease, opacity 140ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.button-primary { background: var(--accent); color: var(--accent-ink); }
.button-primary:hover { background: var(--accent-strong); }
.button-secondary { background: var(--surface-3); color: var(--text); border: 1px solid var(--line); }
.button-full { display: flex; width: 100%; justify-content: center; align-items: center; text-decoration: none; margin-top: 20px; }

.desk-page { height: 100vh; overflow: hidden; }
.desk-header {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 19, 15, 0.96);
}
.desk-brand, .desk-user { display: flex; align-items: center; gap: 12px; }
.desk-brand strong, .desk-brand span { display: block; }
.desk-brand span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.desk-user { color: var(--muted); font-size: 14px; }
.desk-user a { color: var(--text); text-decoration: none; }

.desk-layout {
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: minmax(280px, 350px) minmax(420px, 1fr) minmax(230px, 290px);
}
.conversation-panel, .contact-panel { background: var(--surface); }
.conversation-panel { min-width: 0; border-right: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; }
.contact-panel { border-left: 1px solid var(--line); padding: 24px; overflow: auto; }
.panel-toolbar, .chat-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-toolbar { padding: 20px 18px 13px; }
.panel-toolbar .eyebrow, .contact-panel .eyebrow { margin-top: 0; }
.panel-toolbar h1 { margin-bottom: 0; font-size: 25px; letter-spacing: -0.03em; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 20px; }
.icon-button.is-spinning { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-tabs { display: flex; gap: 7px; padding: 0 16px 14px; overflow-x: auto; }
.status-tab { border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); padding: 7px 10px; cursor: pointer; white-space: nowrap; font-size: 12px; }
.status-tab.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 800; }
.conversation-list { min-height: 0; overflow-y: auto; padding: 0 8px 12px; }
.conversation-item {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 12px 10px;
  cursor: pointer;
}
.conversation-item:hover { background: rgba(255, 255, 255, 0.035); }
.conversation-item.is-active { background: var(--surface-3); }
.conversation-avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: rgba(240, 197, 47, 0.12); color: var(--accent); font-weight: 850; }
.conversation-main { min-width: 0; display: grid; gap: 5px; }
.conversation-heading { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.conversation-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conversation-heading time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.conversation-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.conversation-meta { display: flex; gap: 7px; color: #7f8577; font-size: 10px; }
.status-dot { color: #b8bdaf; }
.status-new { color: var(--accent); }
.status-open { color: var(--success); }
.unread-badge { min-width: 22px; height: 22px; display: grid; place-items: center; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 900; }
.empty-state, .loading-row { padding: 28px 18px; color: var(--muted); text-align: center; font-size: 14px; }

.chat-panel { min-width: 0; background: #141712; display: flex; }
.chat-empty { margin: auto; max-width: 430px; padding: 36px; text-align: center; color: var(--muted); }
.chat-empty h2 { color: var(--text); margin-bottom: 8px; }
.empty-symbol { width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto 18px; border-radius: 20px; background: var(--surface-2); color: var(--accent); font-size: 28px; }
.chat-view { min-width: 0; width: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.is-hidden { display: none !important; }
.chat-header { min-height: 76px; padding: 13px 20px; border-bottom: 1px solid var(--line); background: rgba(20, 23, 18, 0.95); }
.chat-header .eyebrow { margin: 0 0 4px; }
.chat-header h2 { margin: 0; font-size: 20px; }
.chat-actions { display: flex; align-items: center; gap: 9px; }
.chat-actions select { width: auto; min-width: 142px; padding: 10px 12px; }
.message-list { overflow-y: auto; padding: 24px clamp(16px, 4vw, 46px); display: flex; flex-direction: column; gap: 10px; }
.message { display: flex; }
.message-inbound { justify-content: flex-start; }
.message-outbound { justify-content: flex-end; }
.message-bubble { max-width: min(76%, 680px); padding: 11px 13px 8px; border-radius: 16px; background: var(--surface-2); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1); }
.message-outbound .message-bubble { background: #3d371a; border: 1px solid rgba(240, 197, 47, 0.16); }
.message-bubble p { margin: 0; line-height: 1.5; white-space: normal; overflow-wrap: anywhere; }
.message-bubble footer { display: flex; justify-content: flex-end; gap: 7px; margin-top: 5px; color: #909687; font-size: 10px; }
.message-type { display: inline-block; margin-bottom: 6px; color: var(--accent); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; padding: 14px 18px 18px; border-top: 1px solid var(--line); background: rgba(20, 23, 18, 0.96); }
.composer textarea { resize: none; min-height: 46px; max-height: 160px; line-height: 1.45; }

.contact-panel h2 { margin-bottom: 24px; font-size: 23px; letter-spacing: -0.025em; }
.contact-details { display: grid; gap: 0; margin: 0; }
.contact-details div { padding: 15px 0; border-top: 1px solid var(--line); }
.contact-details dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.contact-details dd { margin: 5px 0 0; overflow-wrap: anywhere; }
.toast { position: fixed; z-index: 50; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 13px 16px; border-radius: 13px; background: #30362c; color: var(--text); box-shadow: 0 18px 60px rgba(0,0,0,.36); opacity: 0; transform: translateY(12px); pointer-events: none; transition: 180ms ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: #5d2925; }

@media (max-width: 1050px) {
  .desk-layout { grid-template-columns: minmax(270px, 330px) minmax(0, 1fr); }
  .contact-panel { display: none; }
}

@media (max-width: 720px) {
  .desk-page { overflow: auto; }
  .desk-header { height: 60px; padding: 0 14px; }
  .desk-user span { display: none; }
  .desk-layout { height: calc(100dvh - 60px); grid-template-columns: 1fr; }
  .conversation-panel { border-right: 0; }
  .chat-panel { position: fixed; inset: 60px 0 0; z-index: 10; transform: translateX(100%); transition: transform 180ms ease; }
  body:has(.chat-view:not(.is-hidden)) .chat-panel { transform: translateX(0); }
  .chat-header { padding: 10px 12px; align-items: flex-start; }
  .chat-actions { flex-direction: column; align-items: stretch; }
  .chat-actions .button, .chat-actions select { min-height: 36px; padding: 7px 9px; font-size: 12px; }
  .message-bubble { max-width: 88%; }
  .message-list { padding: 16px 12px; }
  .composer { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

.alert-success { background: rgba(139, 210, 154, 0.12); border: 1px solid rgba(139, 210, 154, 0.3); color: #c8f1d0; }
.mobile-back { display: none; flex: 0 0 auto; }
.management-page { min-height: 100vh; background: var(--bg); }
.management-layout { width: min(1180px, calc(100% - 32px)); margin: 34px auto; display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 22px; }
.management-card { padding: 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.management-card h1, .management-card h2 { margin-bottom: 20px; }
.management-card select { width: 100%; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-2); color: var(--text); padding: 13px 14px; }
.user-table { display: grid; gap: 10px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.user-row strong, .user-row span { display: block; }
.user-row span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.user-state { display: flex; align-items: center; gap: 14px; }
@media (max-width: 800px) { .management-layout { grid-template-columns: 1fr; } .user-row { align-items: flex-start; flex-direction: column; } .user-state { width: 100%; justify-content: space-between; } }
@media (max-width: 720px) { .mobile-back { display: grid; } }
