:root {
  --background: oklch(0.98 0.005 250);
  --foreground: oklch(0.17 0.02 260);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.17 0.02 260);
  --primary: oklch(0.5 0.16 250);
  --primary-foreground: oklch(0.99 0 0);
  --secondary: oklch(0.95 0.015 250);
  --secondary-foreground: oklch(0.25 0.04 250);
  --muted: oklch(0.95 0.01 250);
  --muted-foreground: oklch(0.5 0.02 260);
  --border: oklch(0.91 0.015 250);
  --input: oklch(0.91 0.015 250);
  --destructive: oklch(0.577 0.245 27.325);
  --success: oklch(0.55 0.16 155);
  --success-foreground: oklch(0.99 0 0);
  --warning: oklch(0.7 0.15 60);
  --warning-foreground: oklch(0.25 0.05 60);
  --sidebar: oklch(0.18 0.03 255);
  --sidebar-foreground: oklch(0.92 0.01 250);
  --sidebar-primary: oklch(0.6 0.18 250);
  --sidebar-primary-foreground: oklch(0.99 0 0);
  --sidebar-accent: oklch(0.24 0.04 255);
  --sidebar-border: oklch(0.28 0.04 255);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--background);
  color: var(--foreground);
  font-family: "Geist", "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}

a {
  color: inherit;
}

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

.page-auth {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-wrap {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.brand-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.brand-head h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-head p {
  margin: 4px 0 0;
  color: var(--muted-foreground);
  font-size: 14px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(12, 18, 28, 0.04);
}

.panel-header {
  padding: 18px 18px 8px;
}

.panel-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.panel-desc {
  margin: 6px 0 0;
  color: var(--muted-foreground);
  font-size: 14px;
}

.panel-body {
  padding: 12px 18px 18px;
}

.stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 14px;
  font-weight: 600;
}

.input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--input);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--card);
  color: var(--foreground);
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--primary);
  outline: 2px solid color-mix(in oklch, var(--primary), transparent 80%);
  outline-offset: 1px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  background: transparent;
  color: var(--foreground);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.btn-outline {
  border-color: var(--border);
  background: var(--card);
}

.btn-ghost {
  background: transparent;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
}

.w-full {
  width: 100%;
}

.error-box {
  border: 1px solid color-mix(in oklch, var(--destructive), transparent 70%);
  background: color-mix(in oklch, var(--destructive), transparent 92%);
  color: var(--destructive);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

.demo-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: color-mix(in oklch, var(--muted), white 35%);
  font-size: 12px;
  color: var(--muted-foreground);
}

.demo-box strong {
  color: var(--foreground);
}

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

.sidebar {
  width: 300px;
  background: var(--sidebar);
  color: var(--sidebar-foreground);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--sidebar-primary);
  color: var(--sidebar-primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.sidebar-brand-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-brand-title .line-1 {
  font-size: 14px;
  font-weight: 600;
}

.sidebar-brand-title .line-2 {
  font-size: 12px;
  opacity: 0.65;
}

.sidebar .btn-primary {
  width: 100%;
  margin-top: 12px;
}

.sidebar-content {
  flex: 1;
  padding: 0 8px 8px;
  overflow: auto;
}

.sidebar-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 6px;
  font-size: 12px;
  opacity: 0.75;
}

.session-empty {
  margin: 0;
  padding: 16px 12px;
  text-align: center;
  font-size: 12px;
  opacity: 0.6;
}

.session-btn {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  text-align: left;
  border-radius: 10px;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
  margin-bottom: 6px;
  cursor: pointer;
}

.session-btn:hover {
  background: color-mix(in oklch, var(--sidebar-accent), transparent 30%);
}

.session-btn.active {
  background: color-mix(in oklch, var(--sidebar-accent), transparent 20%);
  border-color: color-mix(in oklch, var(--sidebar-border), transparent 30%);
}

.session-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.session-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  opacity: 0.6;
}

.session-title {
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.sidebar-footer {
  border-top: 1px solid color-mix(in oklch, var(--sidebar-border), transparent 20%);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.sidebar .btn-ghost {
  color: color-mix(in oklch, var(--sidebar-foreground), transparent 25%);
  justify-content: flex-start;
}

.sidebar .btn-ghost:hover {
  color: var(--sidebar-foreground);
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: color-mix(in oklch, var(--sidebar-accent), transparent 45%);
  border-radius: 8px;
  padding: 8px 10px;
}

.user-meta {
  display: grid;
  gap: 2px;
}

.user-name {
  font-size: 12px;
  font-weight: 600;
}

.user-email {
  font-size: 12px;
  opacity: 0.6;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.welcome-inner {
  max-width: 620px;
  text-align: center;
}

.bot-mark {
  width: 80px;
  height: 80px;
  margin: 0 auto;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  color: var(--primary);
  background: color-mix(in oklch, var(--primary), transparent 88%);
}

.welcome-title {
  margin: 24px 0 0;
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.welcome-desc {
  margin: 10px auto 0;
  max-width: 560px;
  color: var(--muted-foreground);
}

.feature-grid {
  margin-top: 28px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.feature-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--card);
}

.feature-icon {
  font-size: 18px;
  color: var(--primary);
}

.feature-label {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
}

.feature-desc {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted-foreground);
}

.welcome .btn-primary {
  margin-top: 28px;
}

.chat-root {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-header {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.chat-ticket-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  color: var(--muted-foreground);
}

.chat-ticket-title {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 600;
}

.status-badge {
  border: 1px solid transparent;
  border-radius: 999px;
  height: 22px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-new {
  background: var(--primary);
  color: var(--primary-foreground);
}

.status-waiting_for_support {
  background: var(--warning);
  color: var(--warning-foreground);
}

.status-waiting_for_agent {
  background: var(--secondary);
  color: var(--secondary-foreground);
}

.status-resolved {
  background: var(--success);
  color: var(--success-foreground);
}

.chat-main {
  flex: 1;
  overflow-y: auto;
}

.message-list {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 20px 24px;
  display: grid;
  gap: 16px;
}

.empty-chat {
  margin: 100px auto 0;
  text-align: center;
  max-width: 380px;
}

.empty-chat h3 {
  margin: 16px 0 0;
}

.empty-chat p {
  margin: 8px 0 0;
  color: var(--muted-foreground);
  font-size: 14px;
}

.msg-row {
  display: flex;
  gap: 10px;
}

.msg-row.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.avatar.user {
  background: var(--primary);
  color: var(--primary-foreground);
}

.avatar.assistant {
  background: var(--muted);
  color: var(--muted-foreground);
}

.avatar.engineer {
  background: color-mix(in oklch, var(--warning), white 15%);
  color: var(--warning-foreground);
}

.bubble {
  max-width: 75%;
  border-radius: 16px;
  padding: 10px 14px;
  line-height: 1.5;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  background: var(--primary);
  color: var(--primary-foreground);
}

.bubble.assistant {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
}

.bubble.engineer {
  background: color-mix(in oklch, var(--warning), white 84%);
  color: var(--warning-foreground);
  border: 1px solid color-mix(in oklch, var(--warning), var(--border) 45%);
}

.citations {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed color-mix(in oklch, var(--border), transparent 25%);
}

.citation-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
  color: color-mix(in oklch, var(--muted-foreground), var(--foreground) 35%);
}

.citation-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.citation-list li {
  font-size: 12px;
}

.citation-link {
  color: color-mix(in oklch, var(--primary), black 8%);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.typing {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.typing-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  white-space: normal;
}

.typing-label {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted-foreground);
}

.typing span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: color-mix(in oklch, var(--muted-foreground), transparent 35%);
  animation: bounce 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.6;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.chat-input-wrap {
  border-top: 1px solid var(--border);
  background: var(--background);
  padding: 12px 16px;
}

.composer-note {
  max-width: 980px;
  margin: 0 auto 8px;
  font-size: 12px;
  color: var(--muted-foreground);
}

.chat-input-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.textarea {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  border: 1px solid var(--input);
  border-radius: 10px;
  resize: none;
  padding: 11px 12px;
  background: var(--card);
  color: var(--foreground);
}

.send-btn {
  min-width: 56px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 13px;
  font-weight: 600;
}

.send-btn-stop {
  min-width: 40px;
  width: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stop-glyph {
  width: 12px;
  height: 12px;
  background: currentColor;
  display: inline-block;
}

.tickets-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.tickets-header {
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  gap: 12px;
}

.tickets-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tickets-title {
  font-size: 18px;
  font-weight: 600;
}

.select {
  height: 38px;
  border: 1px solid var(--input);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--card);
}

.tickets-body {
  padding: 20px;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
  background: var(--card);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}

th {
  font-size: 13px;
  color: var(--muted-foreground);
  font-weight: 600;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: var(--muted-foreground);
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.empty-state {
  text-align: center;
  color: var(--muted-foreground);
  padding: 80px 20px;
}

#toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 9999;
}

.toast {
  min-width: 220px;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(12, 18, 28, 0.12);
}

.toast.error {
  border-color: color-mix(in oklch, var(--destructive), transparent 65%);
}

@media (max-width: 980px) {
  .sidebar {
    width: 260px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 280px;
  }

  .feature-grid {
    grid-template-columns: 1fr;
  }

  .bubble {
    max-width: 85%;
  }
}
