:root {
  --bg: #f5f3f0;
  --bg-strong: #fff1e9;
  --panel: rgba(255, 255, 255, 0.9);
  --surface: #fffaf7;
  --primary: #ff6b1a;
  --primary-strong: #e3560e;
  --primary-soft: #fff0e6;
  --accent: #116dff;
  --accent-soft: #edf4ff;
  --text: #191f2a;
  --muted: #5c697a;
  --bot: #fff9f5;
  --user: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  --danger: #e85151;
  --success: #18a957;
  --border: rgba(19, 35, 52, 0.08);
  --shadow: 0 22px 48px rgba(17, 24, 39, 0.08), 0 8px 20px rgba(255, 107, 26, 0.08);
  --shadow-soft: 0 10px 28px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at top, #fffaf7 0%, #fff2ea 25%, #f5f3f0 100%);
  color: var(--text);
}

body {
  display: flex;
  justify-content: center;
  padding: 28px 18px 40px;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(100%, 960px);
}

.topbar {
  margin-bottom: 18px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  width: fit-content;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--primary);
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(255, 107, 26, 0.12);
  flex: none;
}

.brand-badge img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

h1 {
  margin: 0;
  font-size: clamp(1.2rem, 1.8vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  color: #1f2430;
}

.chat-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 107, 26, 0.1);
  border-radius: 30px;
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(12px);
}

.identity-form {
  display: grid;
  gap: 10px;
  max-width: 520px;
  margin: 16px auto;
}

.identity-form h2,
.identity-form p {
  margin: 0 0 4px;
}

.identity-form p {
  color: var(--muted);
  line-height: 1.5;
}

.identity-form label {
  font-weight: 700;
}

.identity-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
}

.identity-form button {
  margin-top: 8px;
  background: var(--primary);
  color: white;
}

.identity-form button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 350px;
  max-height: 62vh;
  overflow-y: auto;
  padding: 14px 10px 14px 12px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.9) 0%, rgba(255,244,237,0.9) 100%);
  border: 1px solid var(--border);
}

.bubble {
  max-width: 80%;
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: var(--shadow-soft);
  animation: bubbleIn 180ms ease-out;
}

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bubble.bot {
  align-self: flex-start;
  background: var(--bot);
  color: var(--text);
  border: 1px solid rgba(255, 107, 26, 0.08);
}

.bubble.user {
  align-self: flex-end;
  background: var(--user);
  color: #fff;
  border: none;
}

.match-hint {
  align-self: flex-start;
  max-width: 82%;
  margin: 2px 0 4px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 107, 26, 0.05);
  border: 1px solid rgba(255, 107, 26, 0.1);
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.feedback-inline {
  align-self: flex-start;
  max-width: 82%;
  margin-top: -4px;
  padding: 10px 12px 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(17, 24, 39, 0.05);
  box-shadow: var(--shadow-soft);
}

.feedback-inline .feedback-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.feedback-inline .feedback-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.feedback-inline .btn {
  padding: 8px 12px;
  font-size: 0.9rem;
  border-radius: 10px;
}

.chat-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.composer {
  display: flex;
  gap: 12px;
  margin-top: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.8) 0%, rgba(255,247,242,0.9) 100%);
  border: 1px solid rgba(255, 107, 26, 0.1);
  border-radius: 18px;
  padding: 10px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
}

.composer input {
  flex: 1;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.65);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer input:focus {
  border-color: rgba(255, 107, 26, 0.2);
  box-shadow: 0 0 0 4px rgba(255, 107, 26, 0.08);
}

.composer button,
.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.composer button {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: white;
  min-width: 122px;
  box-shadow: 0 10px 20px rgba(255, 107, 26, 0.22);
}

.composer button:hover,
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(255, 107, 26, 0.18);
}

.composer input:hover {
  background: rgba(255, 255, 255, 0.8);
}

.feedback {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.feedback p {
  margin: 0 0 12px;
  color: var(--muted);
  font-weight: 700;
}

.feedback-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn.positive {
  background: linear-gradient(135deg, #147849 0%, #0b6f3f 100%);
  color: white;
}

.btn.negative {
  background: linear-gradient(135deg, #b5292d 0%, #9d1b20 100%);
  color: white;
}

.support-box {
  align-self: flex-end;
  width: fit-content;
  max-width: 100%;
  border: 1px solid rgba(255, 89, 21, 0.18);
  background: linear-gradient(135deg, var(--accent-soft) 0%, #fffaf8 100%);
  color: var(--text);
  border-radius: 16px;
  box-shadow: 0 12px 24px rgba(17, 24, 39, 0.12);
}

.support-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: #9a3a00;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.support-toggle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.support-toggle svg {
  flex: none;
}

.support-chevron {
  margin-left: auto;
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

.support-toggle[aria-expanded="true"] .support-chevron {
  transform: rotate(180deg);
}

.support-details {
  width: min(480px, calc(100vw - 64px));
  max-height: min(48dvh, 440px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 14px 14px;
  border-top: 1px solid var(--border);
}

.support-box p {
  margin: 0;
  line-height: 1.5;
}

.support-box form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.support-contact {
  display: grid;
  gap: 8px;
  width: 100%;
}

.support-contact input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.support-files {
  display: grid;
  gap: 8px;
  width: 100%;
}

#supportFiles {
  width: 100%;
  max-width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
}

.support-box small {
  width: 100%;
  color: var(--muted);
}

.support-confirm {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  line-height: 1.4;
}

.support-confirm input {
  flex: none;
  margin-top: 4px;
}

.support-box label {
  font-weight: 700;
}

.support-box select {
  min-width: 220px;
  max-width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
}

.support-box button:disabled {
  opacity: 0.6;
  cursor: wait;
}

#identityStatus,
#supportStatus {
  display: block;
  margin-top: 10px;
}

.btn {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.hidden {
  display: none !important;
}

@media (max-width: 640px) {
  body {
    display: block;
    padding: 0;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .topbar {
    flex: none;
    margin: 0;
    padding: 12px 16px;
  }

  h1 {
    font-size: 1.2rem;
    line-height: 1.2;
  }

  .chat-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 16px 14px max(16px, env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 20px 20px 0 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .identity-form {
    width: 100%;
    margin: 0 auto;
    gap: 8px;
  }

  .identity-form input,
  .support-contact input,
  .support-box select {
    min-height: 44px;
    font-size: 16px;
  }

  .brand-wrap {
    align-items: center;
  }

  .brand-badge {
    width: 46px;
    height: 46px;
  }

  .chat-messages {
    flex: 1;
    min-height: 0;
    max-height: none;
    gap: 12px;
    padding: 10px 8px 10px 10px;
    border-radius: 16px;
  }

  .bubble {
    max-width: 92%;
    padding: 12px 14px;
    border-radius: 16px;
    overflow-wrap: anywhere;
  }

  .match-hint,
  .feedback-inline {
    max-width: 92%;
    padding: 8px 10px;
  }

  .chat-controls {
    position: sticky;
    bottom: 0;
    z-index: 1;
    flex: none;
    margin-top: 8px;
    background: var(--surface);
  }

  .composer {
    flex-direction: row;
    padding: 8px;
    gap: 8px;
  }

  .support-box {
    width: 100%;
  }

  .support-details {
    width: 100%;
    max-height: min(42dvh, 420px);
  }

  .composer input {
    min-width: 0;
    padding: 11px 12px;
    font-size: 16px;
  }

  .btn {
    width: 100%;
    padding: 11px 14px;
  }

  .composer button {
    width: auto;
    min-width: 76px;
    padding: 11px 12px;
  }

  .feedback-inline .feedback-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .feedback-inline .btn {
    min-width: 0;
    padding: 8px 10px;
    font-size: 0.84rem;
  }

  .support-box form {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }

  .support-box select {
    width: 100%;
    min-width: 0;
  }
}
