:root {
  --color-primary: #7c3aed;
  --color-on-primary: #ffffff;
  --color-secondary: #6366f1;
  --color-accent: #ec4899;
  --color-background: #edf0ff;
  --color-foreground: #0f172a;
  --color-muted: rgba(255, 255, 255, .38);
  --color-border: rgba(255, 255, 255, .55);
  --color-destructive: #dc2626;
  --color-ring: #7c3aed;
  --color-ok: #059669;
  --glass-bg: rgba(255, 255, 255, .48);
  --glass-blur: 22px;
  --easing: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 0 18px 50px -24px rgba(99, 102, 241, .42);
  --radius: 24px;
  --font-display: Inter, Sarabun, sans-serif;
  --font-body: Inter, Sarabun, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(165deg, #f4f0ff 0%, #edf4ff 42%, #fde8f3 100%);
  color: var(--color-foreground);
  font-family: var(--font-body);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(48px);
  opacity: .55;
}

.orb-a {
  width: 420px;
  height: 420px;
  left: -80px;
  top: -90px;
  background: radial-gradient(circle, #c4b5fd 0%, transparent 70%);
  animation: drift 22s var(--easing) infinite alternate;
}

.orb-b {
  width: 380px;
  height: 380px;
  right: -60px;
  top: 12%;
  background: radial-gradient(circle, #fbcfe8 0%, transparent 70%);
  animation: drift 26s var(--easing) infinite alternate-reverse;
}

.orb-c {
  width: 340px;
  height: 340px;
  left: 28%;
  bottom: -120px;
  background: radial-gradient(circle, #a5b4fc 0%, transparent 70%);
  animation: drift 28s var(--easing) infinite alternate;
}

.grid-veil {
  position: absolute;
  inset: 0;
  opacity: .22;
  background-image:
    linear-gradient(rgba(255,255,255,.55) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.55) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 50% 20%, #000 20%, transparent 75%);
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(28px, 18px, 0) scale(1.06); }
}

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--color-border);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.7);
}

.topbar, .workspace, .dialog {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: .85rem 1.1rem 0;
  padding: .75rem 1rem;
  border-radius: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: .8rem;
}

.brand-mark {
  width: 44px;
  height: 44px;
  color: var(--color-primary);
  background: rgba(255,255,255,.55);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 14px;
  display: grid;
  place-items: center;
}

.brand-mark svg { width: 26px; height: 26px; }

.brand-kicker {
  margin: 0;
  font-size: .7rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #64748b;
  font-weight: 600;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -.03em;
}

.brand-sub {
  margin: 0;
  color: #475569;
  font-size: .88rem;
  flex: 1;
}

.topbar-actions { display: flex; gap: .5rem; }

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, .92fr);
  gap: 1rem;
  padding: 1rem 1.1rem 1.2rem;
  min-height: 0;
}

.pane {
  border-radius: var(--radius);
  min-height: 0;
}

.reveal {
  animation: rise .55s var(--easing) both;
}

.reveal.delay { animation-delay: .08s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.pane-data {
  padding: 1.15rem;
  overflow: auto;
}

.pane-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-bottom: .85rem;
}

.pane-head h2,
.chat-head h2,
.calc-card h3,
.plan-out h3,
.dialog h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
}

.chip-live {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .22rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  background: rgba(124, 58, 237, .12);
  color: #6d28d9;
  border: 1px solid rgba(124, 58, 237, .18);
}

.chip-live.chat {
  background: rgba(236, 72, 153, .12);
  color: #be185d;
  border-color: rgba(236, 72, 153, .2);
}

.dropzone {
  position: relative;
  overflow: hidden;
  border: 1.5px dashed rgba(124, 58, 237, .35);
  border-radius: 20px;
  background: rgba(255,255,255,.28);
  text-align: center;
  padding: 2rem 1.2rem;
  cursor: pointer;
  transition: border-color .22s var(--easing), background .22s var(--easing), transform .22s var(--easing);
}

.dropzone::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255,255,255,.45) 50%, transparent 65%);
  transform: translateX(-120%);
  pointer-events: none;
}

.dropzone:hover::after,
.dropzone:focus-visible::after {
  animation: sheen .9s var(--easing);
}

@keyframes sheen {
  to { transform: translateX(120%); }
}

.dropzone:hover, .dropzone:focus-visible, .dropzone.is-drag {
  border-color: var(--color-primary);
  background: rgba(255,255,255,.5);
  outline: none;
  transform: scale(1.01);
}

.dropzone:focus-visible {
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .28);
}

.dropzone-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto .7rem;
  color: var(--color-primary);
  background: rgba(255,255,255,.5);
  border-radius: 16px;
  display: grid;
  place-items: center;
}

.dropzone-icon svg { width: 28px; height: 28px; }

.dropzone h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
}

.dropzone p { margin: .45rem 0 0; color: #64748b; }

.paste-box {
  display: grid;
  gap: .45rem;
  margin-top: .95rem;
}

.paste-box > span {
  font-size: .82rem;
  font-weight: 600;
  color: #475569;
}

.paste-box textarea {
  min-height: 110px;
  font-family: ui-monospace, "JetBrains Mono", monospace;
  font-size: .82rem;
  background: rgba(255,255,255,.42);
}

.control-fields {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem .7rem;
  margin: 0 0 .85rem;
}

.control-fields .check {
  background: rgba(255,255,255,.42);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 999px;
  padding: .32rem .75rem;
}

.analyze-out {
  margin-top: .9rem;
  overflow: auto;
}

.analyze-out table { font-size: .84rem; }
.analyze-out .num { text-align: right; font-variant-numeric: tabular-nums; }

.linkish {
  background: none;
  border: 0;
  padding: 0;
  color: var(--color-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.linkish:hover { filter: brightness(.9); }

.data-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: 1rem 0 .7rem;
}

.pill {
  background: rgba(255,255,255,.55);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 999px;
  padding: .28rem .7rem;
  font-size: .82rem;
  font-weight: 600;
}

.table-wrap {
  overflow: auto;
  max-height: 280px;
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 16px;
  background: rgba(255,255,255,.42);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
}

th, td {
  padding: .45rem .55rem;
  border-bottom: 1px solid rgba(255,255,255,.45);
  text-align: left;
  white-space: nowrap;
}

th {
  background: rgba(247, 243, 253, .85);
  position: sticky;
  top: 0;
}

.calc-card, .plan-out {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255,255,255,.38);
  border: 1px solid rgba(255,255,255,.58);
  backdrop-filter: blur(12px);
}

.hint { color: #64748b; font-size: .86rem; margin: .35rem 0 .8rem; }

.goal-grid { display: grid; gap: .65rem; }

.goal-row {
  display: grid;
  grid-template-columns: 1.3fr .8fr .7fr;
  gap: .5rem;
}

.field { display: grid; gap: .28rem; }
.field span { font-size: .78rem; font-weight: 600; color: #475569; }

input, select, textarea {
  font: inherit;
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 12px;
  padding: .55rem .65rem;
  background: rgba(255,255,255,.55);
  color: inherit;
  transition: box-shadow .2s var(--easing), border-color .2s var(--easing);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(124, 58, 237, .55);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .2);
}

.ratio-row {
  display: flex;
  gap: .9rem;
  margin: .8rem 0;
}

.check {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .9rem;
  cursor: pointer;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: .68rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  transition: transform .18s var(--easing), filter .18s var(--easing), box-shadow .18s var(--easing);
}

.btn svg { width: 18px; height: 18px; }

.btn:hover { transform: translateY(-1px) scale(1.01); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .28);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: var(--color-on-primary);
  box-shadow: 0 10px 24px -10px rgba(236, 72, 153, .7);
}

.btn-secondary {
  background: linear-gradient(135deg, var(--color-secondary), #8b5cf6);
  color: #fff;
}

.btn-ghost {
  background: rgba(255,255,255,.42);
  border: 1px solid rgba(255,255,255,.65);
  color: var(--color-foreground);
}

.btn-sm { padding: .42rem .75rem; font-size: .82rem; }
.btn-block { width: 100%; }

.plan-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .7rem;
  flex-wrap: wrap;
}

.export-actions {
  display: flex;
  gap: .4rem;
}

.plan-step {
  padding: .7rem 0;
  border-top: 1px solid rgba(255,255,255,.5);
  font-size: .9rem;
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .6rem;
  padding: 1rem 1rem .4rem;
}

.chat-head p { margin: .25rem 0 0; color: #64748b; font-size: .86rem; }

.chat-log {
  flex: 1;
  overflow: auto;
  padding: .6rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
}

.bubble {
  max-width: 92%;
  padding: .8rem .95rem;
  border-radius: 18px;
  line-height: 1.55;
  white-space: pre-wrap;
  animation: rise .35s var(--easing);
}

.bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--color-primary), #8b5cf6);
  color: #fff;
  box-shadow: 0 10px 22px -14px rgba(124, 58, 237, .8);
}

.bubble.ai {
  align-self: flex-start;
  background: rgba(255,255,255,.5);
  border: 1px solid rgba(255,255,255,.65);
}

.bubble.sys {
  align-self: center;
  background: rgba(255,255,255,.4);
  color: #475569;
  font-size: .84rem;
}

.bubble.error {
  background: rgba(254, 242, 242, .85);
  color: var(--color-destructive);
  border: 1px solid #fecaca;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .6rem;
  padding: .85rem 1rem 1rem;
  border-top: 1px solid rgba(255,255,255,.45);
  background: rgba(255,255,255,.18);
}

.chat-form textarea { resize: none; min-height: 56px; }

.dialog {
  border: 0;
  border-radius: 22px;
  padding: 0;
  background: transparent;
  max-width: 420px;
  width: calc(100% - 2rem);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(8px);
}

.dialog-card {
  padding: 1.25rem;
  border-radius: 22px;
}

.dialog-actions {
  display: flex;
  gap: .5rem;
  margin-top: 1rem;
}

a { color: var(--color-primary); }

.hidden { display: none !important; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
  .pane-chat { min-height: 62vh; }
  .goal-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
