:root {
  --paper: #EBF0EC;
  --surface: #FFFFFF;
  --ink: #15302A;
  --muted: #55685F;
  --line: #C6D2CB;
  --done: #2D7A57;
  --done-ink: #FFFFFF;
  --mark: #F5C518;
  --mark-soft: #FFF3B8;
  --danger: #B3261E;
  --radius-lg: 18px;
  --radius-sm: 8px;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F1D19;
    --surface: #182A24;
    --ink: #E3EEE8;
    --muted: #9DB2A8;
    --line: #2C443B;
    --done: #3FA274;
    --done-ink: #08140F;
    --mark: #F5C518;
    --mark-soft: #4A3F0E;
    --danger: #FF8A80;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.55 var(--font-body);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--mark); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- header ---- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.5rem; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .8rem; }
.brand-mark { font-size: 1.9rem; line-height: 1; }
.brand h1 { font: 700 1.45rem/1.1 var(--font-display); margin: 0; letter-spacing: -.01em; }
.brand p { margin: .1rem 0 0; color: var(--muted); font-size: .9rem; }
.toggle-panel { display: none; }

/* ---- layout ---- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 430px; }

/* ---- chat ---- */
.chat { display: flex; flex-direction: column; min-height: 0; max-width: 820px; width: 100%; margin: 0 auto; }
.log { flex: 1; overflow-y: auto; padding: 1.5rem 1.5rem .5rem; display: flex; flex-direction: column; gap: 1rem; }
.msg { display: flex; flex-direction: column; max-width: 78ch; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.bubble { padding: .75rem 1rem; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line); }
.msg.user .bubble { background: var(--ink); color: var(--paper); border-color: var(--ink); border-bottom-right-radius: 4px; }
.msg.bot .bubble { border-bottom-left-radius: 4px; }
.bubble p { margin: 0 0 .5rem; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: .25rem 0 .5rem; padding-left: 1.25rem; }
.msg.error .bubble { border-color: var(--danger); color: var(--danger); }

.tools { margin-top: .35rem; font-size: .82rem; color: var(--muted); }
.tools summary { cursor: pointer; }
.tools summary::marker { color: var(--done); }
.tools pre { white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem; font-size: .75rem; }
.tool-name { background: var(--mark-soft); padding: 0 .35rem; border-radius: 4px; color: var(--ink); }

.typing .bubble { display: flex; gap: .3rem; align-items: center; color: var(--muted); }
.typing .dot { width: .45rem; height: .45rem; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing .dot:nth-child(2) { animation-delay: .2s; } .typing .dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

.suggestions { display: flex; flex-wrap: wrap; gap: .5rem; padding: .5rem 1.5rem; }
.suggestions button {
  border: 1px dashed var(--done); background: transparent; color: var(--ink);
  border-radius: 999px; padding: .4rem .85rem; font-size: .88rem; cursor: pointer;
}
.suggestions button:hover { background: var(--surface); }

.composer { display: flex; gap: .6rem; padding: .75rem 1.5rem 1.25rem; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 9rem; padding: .75rem 1rem; border-radius: var(--radius-lg);
  border: 1.5px solid var(--line); background: var(--surface);
}
.composer textarea:focus { border-color: var(--done); outline: none; }
#send, .primary {
  background: var(--done); color: var(--done-ink); border: 0; border-radius: 999px;
  padding: .75rem 1.3rem; font-weight: 700; cursor: pointer;
}
#send:disabled, .primary:disabled { opacity: .5; cursor: progress; }

/* ---- panel (papel milimétrico) ---- */
.panel {
  border-left: 1px solid var(--line); overflow-y: auto; padding: 1.25rem 1.25rem 2rem;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 22px 22px; background-position: -1px -1px;
  background-blend-mode: normal;
}
.panel > * { background: var(--paper); }
.panel-head h2 { font: 700 1.2rem/1.2 var(--font-display); margin: 0; }
.panel-head p { margin: .2rem 0 0; color: var(--muted); font-size: .9rem; }
.panel-head { padding: .25rem 0 .75rem; }

.gauge { padding: .5rem 0 1rem; }
.gauge-bar { height: 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.gauge-bar span { display: block; height: 100%; width: 0; background: var(--done); transition: width .6s ease; }
.gauge-text { margin: .4rem 0 0; font-size: .9rem; color: var(--muted); }
.gauge-text strong { font: 700 1.1rem var(--font-display); color: var(--ink); }

.semester { display: grid; grid-template-columns: 2.2rem 1fr; gap: .5rem; padding: .45rem 0; border-top: 1px solid var(--line); transition: background .3s; }
.semester.flash { background: var(--mark-soft); }
.sem-num { font: 700 1.25rem/1.6 var(--font-display); color: var(--muted); text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: .2rem .5rem; font-size: .78rem; line-height: 1.3; cursor: pointer; text-align: left;
}
.chip small { color: var(--muted); margin-left: .25rem; }
.chip[aria-pressed="true"] { background: var(--done); border-color: var(--done); color: var(--done-ink); }
.chip[aria-pressed="true"] small { color: inherit; opacity: .8; }
.chip.related { box-shadow: inset 0 -3px 0 var(--mark); }
.chip.fixed { cursor: default; border-style: dashed; color: var(--muted); }
.chip.esp { border: 1.5px solid var(--mark); }
.chip.esp[aria-pressed="true"] { border-color: var(--mark); }
.bubble a { color: var(--done); font-weight: 700; }
.msg.user .bubble a { color: inherit; }

.extras { border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 1rem 0; padding: .6rem .9rem .8rem; display: grid; gap: .35rem; }
.extras legend { font-weight: 700; padding: 0 .3rem; }
.extras label { display: flex; align-items: center; gap: .5rem; font-size: .92rem; }
.extras input[type="checkbox"] { accent-color: var(--done); width: 1.05rem; height: 1.05rem; }

.panel-actions { display: flex; gap: .6rem; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: .75rem 1.1rem; cursor: pointer; }

/* ---- móvil ---- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .toggle-panel {
    display: inline-block; border: 1.5px solid var(--done); background: transparent;
    border-radius: 999px; padding: .45rem .9rem; font-weight: 700; cursor: pointer;
  }
  .panel {
    position: fixed; inset: auto 0 0 0; height: 82vh; z-index: 10; border-left: 0;
    border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
    transform: translateY(100%); transition: transform .3s ease; box-shadow: 0 -8px 30px rgb(0 0 0 / .18);
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
  }
  .panel.open { transform: none; }
  .top { padding: .75rem 1rem; }
  .brand p { display: none; }
  .log, .suggestions, .composer { padding-left: 1rem; padding-right: 1rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
