* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --muted: #64748b;
  --line: #dce3ee;
  --primary: #0f766e;
  --primary-dark: #0b5e58;
  --assistant-bg: #f8fafc;
  --user-gradient: linear-gradient(140deg, #0f766e 0%, #14b8a6 100%);
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-sm: 0 8px 20px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 26px 60px rgba(15, 23, 42, 0.08);
  --chat-panel-width: 420px;
  --header-height: 86px;
}

body {
  font-family: 'Space Grotesk', 'Avenir Next', 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at 0% 0%, rgba(15, 118, 110, 0.14), transparent 42%),
    radial-gradient(
      circle at 100% 100%,
      rgba(59, 130, 246, 0.14),
      transparent 45%
    ),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow: hidden;
}

.bg-orb {
  position: fixed;
  pointer-events: none;
  border-radius: 999px;
  filter: blur(50px);
  z-index: 0;
  opacity: 0.5;
}

.bg-orb--one {
  width: 280px;
  height: 280px;
  left: -80px;
  top: 100px;
  background: rgba(20, 184, 166, 0.35);
}

.bg-orb--two {
  width: 320px;
  height: 320px;
  right: -100px;
  bottom: -60px;
  background: rgba(59, 130, 246, 0.3);
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1580px;
  margin: 0 auto;
  padding: 18px;
  gap: 14px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  min-height: var(--header-height);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  animation: slideFadeIn 450ms ease both;
}

.header-brand h1 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.header-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow,
.panel-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.69rem;
  color: var(--muted);
  font-weight: 700;
}

.panel-eyebrow {
  margin-bottom: 4px;
}

.field-label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.header-actions .input {
  width: auto;
  min-width: 220px;
}

.input-sm {
  padding: 10px 12px;
  font-size: 0.875rem;
}

.btn-sm {
  padding: 9px 14px;
  font-size: 0.84rem;
}

.split-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--chat-panel-width) minmax(0, 1fr);
  gap: 14px;
}

.chat-panel,
.form-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 320px;
  animation: slideFadeIn 500ms ease 80ms both;
}

.chat-panel-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(220, 227, 238, 0.9);
}

.chat-panel-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-panel-header h2 {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.chat-scroll-shell {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  scrollbar-width: thin;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: min-content;
}

.chat-typing-row {
  display: none;
  flex-shrink: 0;
  align-self: flex-start;
  padding-bottom: 2px;
}

.chat-typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  min-height: 44px;
  border-radius: 18px;
  background: var(--assistant-bg);
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #94a3b8;
  animation: chatTypingBounce 1.2s ease-in-out infinite;
}

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

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

@keyframes chatTypingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-typing-dot {
    animation: none;
    opacity: 0.7;
  }
}

.chat-bubble {
  max-width: 90%;
  padding: 12px 14px;
  border-radius: 16px;
  align-self: flex-start;
  border: 1px solid transparent;
  animation: messageIn 280ms ease both;
}

.chat-bubble--user {
  align-self: flex-end;
  background: var(--user-gradient);
  color: #fff;
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.25);
}

.chat-bubble--assistant {
  background: var(--assistant-bg);
  border-color: #e2e8f0;
}

.chat-bubble-label {
  display: block;
  font-size: 0.69rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  opacity: 0.88;
}

.chat-bubble-content {
  font-size: 0.95rem;
  line-height: 1.45;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-input-area {
  padding: 14px 16px 16px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid rgba(220, 227, 238, 0.9);
  background: rgba(248, 250, 252, 0.7);
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-input {
  flex: 1;
  min-width: 0;
}

.voice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.recording-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.84rem;
  color: var(--muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #94a3b8;
}

.status.recording .status-dot {
  background: #ef4444;
  box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.2);
}

.transcription {
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.3em;
}

.form-panel {
  min-width: 0;
  overflow-y: auto;
  padding: 18px;
  animation: slideFadeIn 550ms ease 140ms both;
}

.form-shell {
  width: 100%;
  display: grid;
  gap: 14px;
}

.form-panel .card {
  background: var(--surface);
  border-radius: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.ai-message,
.form-header p,
.confidence {
  color: var(--muted);
}

.form-card.is-loading {
  opacity: 0.65;
  pointer-events: none;
}

.ai-response {
  background: linear-gradient(120deg, #f3fbf9 0%, #ffffff 70%);
}

.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.form-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.form-header h2 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.form-header p {
  font-size: 0.93rem;
  margin-top: 4px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.84rem;
  color: #334155;
  font-weight: 700;
}

.span-2 {
  grid-column: span 2;
}

.input,
input,
select,
textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #d5dfeb;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-family: 'DM Sans', 'Avenir Next', 'Segoe UI', sans-serif;
  color: var(--ink);
  background: #ffffff;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

textarea {
  min-height: 94px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
  background: #fcfffe;
}

.btn {
  border: none;
  padding: 11px 18px;
  border-radius: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    opacity 0.2s ease;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.25);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--primary-dark);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.32);
}

.btn-secondary {
  background: #eaf0f8;
  color: #1f2937;
}

.btn-secondary:hover:not(:disabled) {
  background: #dde7f3;
}

/* ── Variants ─────────────────────────────────────────────────────────────── */

.variants-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.variants-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.variants-header label {
  font-size: 0.84rem;
  color: #334155;
  font-weight: 700;
}

.variants-hint-inline {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
}

.variants-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.variant-row {
  display: grid;
  grid-template-columns: 1fr 140px 36px;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  animation: messageIn 220ms ease both;
}

.variant-days-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.variant-days-wrap .input {
  width: 70px;
  flex-shrink: 0;
  text-align: right;
  padding: 8px 10px;
}

.variant-days-unit {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
  font-size: 1rem;
}

.btn-ghost:hover:not(:disabled) {
  background: #fee2e2;
  color: #dc2626;
}

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

@keyframes messageIn {
  from {
    transform: translateY(6px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (max-width: 1240px) {
  .header-actions .input {
    min-width: 170px;
  }

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

/* ── Phase indicator ──────────────────────────────────────────────────────── */

.phase-indicator {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
}

.phase-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  transition: color 0.25s ease;
}

.phase-step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background 0.25s ease,
    color 0.25s ease;
}

.phase-step-label {
  white-space: nowrap;
}

.phase-step--active {
  color: var(--primary);
}

.phase-step--active .phase-step-num {
  background: var(--primary);
  color: #fff;
}

.phase-step--done {
  color: #16a34a;
}

.phase-step--done .phase-step-num {
  background: #bbf7d0;
  color: #15803d;
}

.phase-connector {
  flex: 1;
  min-width: 20px;
  height: 2px;
  background: var(--line);
  border-radius: 999px;
  margin: 0 4px;
}

/* ── Availability start card ──────────────────────────────────────────────── */

.availability-start-card {
  animation: slideFadeIn 350ms ease both;
}

.availability-start-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.avail-start-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.avail-start-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.avail-start-row .input {
  flex: 1;
  font-size: 0.82rem;
  font-family: ui-monospace, 'Cascadia Code', 'Fira Mono', monospace;
}

.availability-start-card--active {
  opacity: 0.6;
  pointer-events: none;
}

/* ── Availability card ────────────────────────────────────────────────────── */

.availability-card {
  animation: slideFadeIn 350ms ease both;
}

.availability-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.availability-card-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 2px;
}

.avail-draft {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.avail-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.5;
}

.avail-icon {
  flex-shrink: 0;
  width: 22px;
  font-size: 1rem;
  text-align: center;
  margin-top: 1px;
}

.avail-muted {
  color: var(--muted);
}

.avail-slots-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.avail-slot-pill {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
}

.avail-tz-row {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.ticket-created-json {
  margin-top: 12px;
  padding: 12px;
  font-size: 0.75rem;
  line-height: 1.45;
  background: var(--surface-2, #f8fafc);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  max-height: 220px;
}

.drafts-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 4px;
}

.draft-card .draft-card-header {
  flex-wrap: wrap;
  align-items: center;
}

.draft-card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.draft-lock-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.draft-lock-label input {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.draft-form.field-grid {
  margin-top: 4px;
}

.draft-form--locked {
  opacity: 0.92;
}

.draft-slots-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.draft-slots-header label {
  margin: 0;
}

.draft-slots-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.draft-slot-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.draft-slot-row .draft-remove-slot {
  align-self: center;
  min-width: 36px;
}

.draft-exceptions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.draft-exception-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 2fr auto;
  gap: 10px;
  align-items: end;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.draft-ex-reason-wrap {
  min-width: 0;
}

.draft-exception-row .draft-remove-exception {
  align-self: center;
  min-width: 36px;
}

.draft-price-rules-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.draft-price-rule-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr minmax(100px, 1.2fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.draft-price-rule-row .tpr-label-wrap {
  min-width: 0;
}

.draft-price-rule-row .draft-remove-price-rule {
  align-self: center;
  min-width: 36px;
}

.draft-subsection {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.draft-subsection-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.draft-metadata-grid {
  margin-top: 0;
}

.draft-json-textarea {
  font-family: ui-monospace, 'Cascadia Code', 'Fira Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  resize: vertical;
  min-height: 88px;
}

.draft-field-hint {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.draft-field-hint code {
  font-size: 0.76rem;
}

/* ── Button success state ─────────────────────────────────────────────────── */

.btn-success {
  background: #22c55e !important;
  color: #fff !important;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.3) !important;
  cursor: default;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    padding: 12px;
  }

  .app-header {
    border-radius: 18px;
    padding: 14px;
  }

  .header-brand h1 {
    font-size: 1.28rem;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
    gap: 10px;
  }

  .header-field {
    flex: 1;
    min-width: 220px;
  }

  .header-actions .input {
    min-width: 0;
    width: 100%;
  }

  .split-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .chat-panel {
    min-width: 0;
    max-height: 52vh;
  }

  .form-panel {
    padding: 12px;
  }

  .form-panel .card {
    padding: 16px;
  }

  .form-header {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .span-2 {
    grid-column: span 1;
  }

  .variant-row {
    grid-template-columns: 1fr 36px;
    grid-template-rows: auto auto;
  }

  .variant-days-wrap {
    grid-column: 1 / -1;
  }

  .draft-slot-row {
    grid-template-columns: 1fr;
  }

  .draft-slot-row .draft-remove-slot {
    justify-self: start;
  }

  .draft-exception-row {
    grid-template-columns: 1fr;
  }

  .draft-price-rule-row {
    grid-template-columns: 1fr;
  }

  .draft-price-rule-row .draft-remove-price-rule {
    justify-self: start;
  }
}
