@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --bg: #09090d;
  --surface: #111117;
  --surface-2: #17171f;
  --surface-3: #20202a;
  --line: rgba(255, 255, 255, .09);
  --line-strong: rgba(255, 255, 255, .15);
  --text: #f4f4f5;
  --muted: #92929f;
  --red: #ed4a4d;
  --red-dark: #b52f39;
  --amber: #f3b64d;
  --green: #4bd28c;
  --shadow: 0 18px 42px rgba(0, 0, 0, .36);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 78% -10%, rgba(237, 74, 77, .13), transparent 34rem), var(--bg);
  font: 14px/1.5 Inter, system-ui, sans-serif;
  text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

.app-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(420px, 100%); padding: 36px; background: rgba(17,17,23,.9); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.login h1 { margin: 22px 0 8px; font-size: 30px; letter-spacing: -.04em; }
.login p { margin: 0 0 28px; color: var(--muted); }
.brand { display: flex; gap: 12px; align-items: center; font-weight: 800; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: white; background: linear-gradient(140deg, var(--red), var(--red-dark)); font-size: 12px; font-weight: 800; box-shadow: 0 10px 20px rgba(237,74,77,.22); }
.brand span { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.field { display: grid; gap: 7px; margin: 16px 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.field input, .composer textarea, .ticket-form input, .ticket-form textarea { width: 100%; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; resize: vertical; }
.field input:focus, .ticket-form input:focus, .ticket-form textarea:focus, .composer textarea:focus { border-color: rgba(237,74,77,.7); outline: none; }
.button { border: 0; border-radius: 999px; padding: 11px 16px; color: var(--text); background: var(--surface-3); cursor: pointer; font-weight: 700; transition: transform .18s ease, filter .18s ease, background .18s ease; }
.button:hover { filter: brightness(1.1); }
.button:active { transform: scale(.97); }
.button-primary { color: #fff; background: linear-gradient(135deg, var(--red), var(--red-dark)); box-shadow: 0 12px 28px rgba(237,74,77,.24); }
.button-quiet { color: var(--muted); background: transparent; }
.error { min-height: 20px; color: #ff9294; font-size: 12px; }

.workspace { width: min(1540px, 100%); min-height: calc(100vh - 48px); display: grid; grid-template-columns: 290px minmax(420px, 1fr) 290px; overflow: hidden; background: rgba(17,17,23,.84); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.queue, .customer-panel { background: rgba(13,13,18,.72); }
.queue { border-right: 1px solid var(--line); padding: 22px 14px; }
.queue-header, .thread-header, .customer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.queue-header { padding: 0 8px 20px; }
.queue-title { font-size: 17px; font-weight: 800; letter-spacing: -.03em; }
.queue-subtitle { color: var(--muted); font-size: 11px; }
.filter-row { display: flex; gap: 6px; padding: 0 8px 14px; }
.filter-row button { border: 1px solid transparent; border-radius: 999px; padding: 6px 9px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; }
.filter-row button.active { color: white; background: rgba(237,74,77,.13); border-color: rgba(237,74,77,.28); }
.ticket-list { display: grid; gap: 6px; max-height: calc(100vh - 170px); overflow: auto; padding-right: 2px; }
.ticket-item { width: 100%; display: grid; gap: 5px; border: 1px solid transparent; border-radius: 12px; padding: 12px; color: var(--text); background: transparent; text-align: left; cursor: pointer; }
.ticket-item:hover { background: rgba(255,255,255,.04); }
.ticket-item.active { background: rgba(237,74,77,.11); border-color: rgba(237,74,77,.28); }
.ticket-item-top, .ticket-item-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ticket-item-top strong { font-size: 12px; }
.ticket-item-title { overflow: hidden; color: #e7e7ea; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.ticket-item-bottom { color: var(--muted); font-size: 10px; }
.source-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--red); }
.source-dot.email { background: var(--amber); }
.source-dot.widget, .source-dot.cabinet { background: var(--green); }

.thread { min-width: 0; display: grid; grid-template-rows: auto 1fr auto; background: linear-gradient(180deg, rgba(27,27,35,.32), transparent 30%); }
.thread-header { min-height: 82px; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.thread-header h1 { margin: 0; font-size: 17px; letter-spacing: -.03em; }
.thread-meta { margin-top: 4px; color: var(--muted); font-size: 11px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; color: var(--amber); background: rgba(243,182,77,.1); border-radius: 999px; font-size: 11px; font-weight: 700; }
.status.open { color: var(--green); background: rgba(75,210,140,.1); }
.messages { display: flex; flex-direction: column; gap: 14px; overflow: auto; padding: 24px; }
.message { max-width: min(720px, 86%); padding: 13px 15px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-2); }
.message.outbound { align-self: flex-end; border-color: rgba(237,74,77,.28); background: rgba(237,74,77,.1); }
.message-author { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: grid; gap: 10px; padding: 16px 24px 20px; border-top: 1px solid var(--line); }
.composer textarea { min-height: 82px; }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.composer-hint { color: var(--muted); font-size: 11px; }

.customer-panel { border-left: 1px solid var(--line); padding: 22px 18px; }
.customer-header { padding-bottom: 22px; }
.customer-header h2 { margin: 0; font-size: 14px; }
.customer-empty { margin-top: 30px; color: var(--muted); font-size: 12px; }
.customer-block { display: grid; gap: 5px; padding: 14px 0; border-top: 1px solid var(--line); }
.customer-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.customer-value { overflow-wrap: anywhere; }
.customer-json { max-height: 260px; overflow: auto; color: #c9c9d2; background: var(--surface-2); border-radius: 10px; padding: 10px; font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.toolbar { display: flex; gap: 6px; }
.select { color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 7px; font-size: 11px; }
.empty-state { display: grid; place-items: center; min-height: 100%; color: var(--muted); text-align: center; padding: 40px; }
.empty-state strong { display: block; margin-bottom: 8px; color: var(--text); font-size: 17px; }

.embed-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.embed-shell { width: min(480px, 100%); padding: 22px; background: rgba(17,17,23,.96); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.embed-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.embed-heading strong, .embed-heading span { display: block; }
.embed-heading span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.ticket-form { display: grid; gap: 15px; }
.ticket-form label { display: grid; gap: 7px; color: #dedee4; font-size: 12px; font-weight: 600; }
.ticket-form textarea { min-height: 150px; }
.hint { color: var(--muted); font-weight: 400; }
.form-status { min-height: 20px; margin: 0; color: var(--muted); font-size: 12px; }
.ticket-result { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 18px; }
.ticket-result strong { display: block; margin-bottom: 6px; }
.ticket-result p { margin: 0; color: var(--muted); font-size: 12px; }
.public-messages { display: grid; gap: 9px; margin: 16px 0; max-height: 240px; overflow: auto; }
.public-messages .message { max-width: 100%; padding: 10px 12px; font-size: 12px; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 260px minmax(0, 1fr); }
  .customer-panel { display: none; }
}
@media (max-width: 700px) {
  .app-shell { padding: 0; }
  .workspace { min-height: 100vh; border: 0; border-radius: 0; grid-template-columns: 1fr; }
  .queue { display: none; }
  .thread-header { padding-inline: 16px; }
  .messages { padding: 18px 14px; }
  .composer { padding-inline: 14px; }
  .login { padding: 28px 22px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
