/* Tokens follow the Angelo Automates portfolio (torrevillas.tech): warm dark
   surfaces, coral accent, Inter. Light theme follows the visitor's OS setting. */
@font-face {
  font-family: "Inter";
  src: url("fonts/inter-latin-var.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #131211;
  --surface: #1C1A18;
  --surface-2: #24211F;
  --text: #F2EEE9;
  --muted: #A9A199;
  --line: #34302C;
  --line-strong: #4A4540;
  --accent: #FF6240;
  --accent-text: #FF8566;
  --accent-soft: #2E1B15;
  --btn-bg: #FF6240;
  --btn-text: #131211;
  --ok: #8CCBA9;   --ok-soft: #17271E;
  --warn: #E9BC6B; --warn-soft: #2B2213;
  --err: #F19C8E;  --err-soft: #2E1A17;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --gutter: clamp(1rem, 0.5rem + 2.5vw, 2rem);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #FAF8F6;
    --surface: #FFFFFF;
    --surface-2: #F3F0EC;
    --text: #1F1D1B;
    --muted: #5E5A56;
    --line: #E6E0DA;
    --line-strong: #D0C8C0;
    --accent: #C8421A;
    --accent-text: #B53A12;
    --accent-soft: #FFF1EC;
    --btn-bg: #C8421A;
    --btn-text: #FFFFFF;
    --ok: #2F6B4F;   --ok-soft: #E8F2EC;
    --warn: #8A5A0B; --warn-soft: #FBF1DE;
    --err: #A3301B;  --err-soft: #FCEBE7;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.55 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
code, pre { font-family: var(--mono); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 1rem; top: -3rem; z-index: 10;
  background: var(--btn-bg); color: var(--btn-text); padding: .5rem .75rem; border-radius: var(--r-sm);
}
.skip:focus { top: 1rem; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Header ---------- */
.top { border-bottom: 1px solid var(--line); }
.top-inner {
  max-width: 76rem; margin: 0 auto; padding: 1rem var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.logo {
  flex: none; width: 36px; height: 36px; border-radius: 9px; background-color: var(--accent);
  background-image:
    linear-gradient(var(--bg), var(--bg)),
    linear-gradient(var(--bg), var(--bg)),
    linear-gradient(var(--bg), var(--bg));
  background-size: 5px 18px, 5px 12px, 5px 8px;
  background-position: 9px 9px, 16px 15px, 23px 19px;
  background-repeat: no-repeat;
}
h1 { margin: 0; font-size: 1.0625rem; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
.sub { margin: 0; color: var(--muted); font-size: .8125rem; }
.badge {
  flex: none; font-size: .75rem; font-weight: 600; color: var(--warn);
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  padding: .25rem .6rem; border-radius: 999px; white-space: nowrap;
}

/* ---------- Layout ---------- */
.layout {
  max-width: 76rem; margin: 0 auto; padding: 1.5rem var(--gutter) 2.5rem;
  display: grid; grid-template-columns: minmax(0, 1fr) 22rem; gap: 1.5rem; align-items: start;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Chat ---------- */
.chat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  display: flex; flex-direction: column; min-height: min(78vh, 52rem);
}
.notice {
  display: flex; align-items: center; gap: .5rem; padding: .7rem 1rem;
  border-bottom: 1px solid var(--line); font-size: .8125rem; color: var(--muted);
}
.notice .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; }
.notice.on .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.notice.off .dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

.log {
  list-style: none; margin: 0; padding: 1rem; flex: 1;
  display: flex; flex-direction: column; gap: .875rem; overflow-y: auto;
}
.msg { max-width: 100%; animation: rise .28s var(--ease) both; }
.msg p { margin: 0; }
.msg.user {
  align-self: flex-end; max-width: min(85%, 34rem);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  padding: .6rem .85rem; border-radius: var(--r-md) var(--r-md) 4px var(--r-md);
  overflow-wrap: anywhere;
}
.msg.bot {
  align-self: stretch; background: var(--surface-2); border: 1px solid var(--line);
  padding: .85rem 1rem; border-radius: var(--r-md) var(--r-md) var(--r-md) 4px;
  display: flex; flex-direction: column; gap: .65rem;
}
.intro .hint { color: var(--muted); font-size: .875rem; }
.examples { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.examples button {
  font: inherit; font-size: .875rem; color: var(--text); cursor: pointer; text-align: left;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px;
  padding: .4rem .8rem; min-height: 36px;
  transition: border-color .15s var(--ease), background-color .15s var(--ease), transform .1s var(--ease);
}
.examples button:hover { border-color: var(--accent); background: var(--accent-soft); }
.examples button:active { transform: scale(.98); }
.examples button:disabled { opacity: .5; cursor: not-allowed; }

.mode {
  align-self: flex-start; font-size: .75rem; font-weight: 600; letter-spacing: .01em;
  padding: .15rem .5rem; border-radius: 999px;
}
.mode.ai { color: var(--ok); background: var(--ok-soft); }
.mode.preset { color: var(--warn); background: var(--warn-soft); }
.answer .text { white-space: pre-line; }

.table-wrap {
  overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm);
  max-height: 22rem; overflow-y: auto; background: var(--surface);
}
table { border-collapse: collapse; width: 100%; font-size: .8125rem; font-variant-numeric: tabular-nums; }
th, td { padding: .45rem .7rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }

.sql summary {
  cursor: pointer; font-size: .8125rem; color: var(--accent-text); font-weight: 550;
  width: fit-content; list-style-position: inside;
}
.sql pre {
  margin: .5rem 0 0; padding: .75rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); overflow-x: auto; font-size: .8125rem; line-height: 1.5;
}
.meta { color: var(--muted); font-size: .75rem; }

.msg.bot.loading { flex-direction: row; align-items: center; color: var(--muted); font-size: .875rem; }
.pulse { display: inline-flex; gap: 4px; }
.pulse i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite ease-in-out; }
.pulse i:nth-child(2) { animation-delay: .15s; }
.pulse i:nth-child(3) { animation-delay: .3s; }

.msg.error { border-color: color-mix(in srgb, var(--err) 45%, transparent); background: var(--err-soft); }
.retry {
  align-self: flex-start; font: inherit; font-size: .8125rem; font-weight: 600; cursor: pointer;
  color: var(--text); background: transparent; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); padding: .35rem .7rem; min-height: 32px;
}
.retry:hover { border-color: var(--err); }

/* ---------- Composer ---------- */
.composer {
  border-top: 1px solid var(--line); padding: .85rem 1rem 1rem;
  display: grid; grid-template-columns: 1fr auto; gap: .4rem .6rem;
}
textarea {
  font: inherit; color: var(--text); background: var(--bg); resize: none;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  padding: .65rem .8rem; min-height: 46px; max-height: 9rem; line-height: 1.45;
  transition: border-color .15s var(--ease);
}
textarea::placeholder { color: var(--muted); }
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.send {
  font: inherit; font-weight: 650; cursor: pointer; align-self: end;
  color: var(--btn-text); background: var(--btn-bg); border: 0; border-radius: var(--r-md);
  padding: 0 1.15rem; min-height: 46px; min-width: 72px;
  transition: filter .15s var(--ease), transform .1s var(--ease);
}
.send:hover { filter: brightness(1.06); }
.send:active { transform: scale(.97); }
.send:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.composer-meta {
  grid-column: 1 / -1; margin: 0; display: flex; justify-content: space-between; gap: 1rem;
  color: var(--muted); font-size: .75rem;
}
#counter.near { color: var(--warn); }
.field-error { grid-column: 1 / -1; margin: 0; color: var(--err); font-size: .8125rem; }
@media (hover: none) { #composer-help { visibility: hidden; } }

/* ---------- About ---------- */
.about {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 1.15rem 1.25rem; font-size: .9rem;
}
.about h2 { margin: 0 0 .75rem; font-size: 1rem; font-weight: 650; }
.about h3 { margin: 1.25rem 0 .5rem; font-size: .9rem; font-weight: 650; }
.about p { margin: 0 0 .65rem; color: var(--muted); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: .7rem; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 1.6rem 1fr; column-gap: .55rem; }
.steps li::before {
  content: counter(s); grid-row: span 2; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  display: grid; place-items: center; font-size: .75rem; font-weight: 700;
  color: var(--accent-text); background: var(--accent-soft);
}
.steps strong { font-weight: 600; font-size: .875rem; }
.steps span { color: var(--muted); font-size: .8125rem; }
.steps code { font-size: .75rem; color: var(--text); }
.stack { display: flex; flex-wrap: wrap; gap: .35rem; }
.stack span {
  font-size: .75rem; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); padding: .15rem .5rem; border-radius: 999px;
}
.limits { font-size: .8125rem; border-left: 2px solid var(--warn); padding-left: .6rem; }

@media (max-width: 560px) {
  .badge { display: none; }
  .log { padding: .75rem; }
  .composer { padding: .75rem; }
  .chat { min-height: 70vh; }
}

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
