:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --ink: #19201d;
  --muted: #66706b;
  --line: #d9ddd9;
  --accent: #274b3c;
  --accent-soft: #e3ece7;
  --danger: #8b2e2e;
  --shadow: 0 16px 40px rgba(20, 30, 25, .07);
  --radius: 18px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  padding: 34px clamp(20px, 5vw, 72px) 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.76);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}
h1 { margin: 4px 0 3px; font-size: clamp(29px, 4vw, 48px); letter-spacing: -.04em; line-height: 1; }
.topbar p { margin: 8px 0 0; color: var(--muted); }
.eyebrow { letter-spacing: .15em; font-size: 11px; font-weight: 800; color: var(--accent); }
.status-pill { background: var(--accent-soft); color: var(--accent); padding: 9px 12px; border-radius: 999px; white-space: nowrap; font-size: 13px; }
.app-shell { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 24px; padding: 28px clamp(20px, 5vw, 72px) 70px; max-width: 1600px; margin: auto; }
.sidebar { position: sticky; top: 145px; align-self: start; max-height: calc(100vh - 175px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.workspace { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel-heading { display:flex; align-items:center; justify-content:space-between; margin-bottom: 16px; }
.panel-heading.compact { margin-bottom: 3px; }
.step { display:inline-grid; place-items:center; width:26px; height:26px; border-radius:50%; margin-right:9px; background:var(--ink); color:#fff; font-size:12px; font-weight:800; }
.search-box { display:block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.search-box input { margin-top: 5px; }
input[type="text"], input[type="search"], input:not([type]), select, textarea, .title-editor {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--ink);
  border-radius: 11px;
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #769487; box-shadow: 0 0 0 3px rgba(39,75,60,.08); }
label { display:block; font-weight:650; }
label textarea, label input, label select { margin-top: 7px; font-weight: 400; }
.form-grid { display:grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; }
.model-address-box { margin-bottom: 17px; padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; }
.model-address-box input { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.field-help { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.field-help code { color: var(--ink); }
fieldset { margin: 18px 0; border: 1px solid var(--line); border-radius: 13px; padding: 15px; }
legend { padding: 0 7px; font-weight: 750; }
.checks { display:grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px 16px; }
.checks label { font-weight: 500; }
.selected-course { min-height: 54px; padding: 12px 14px; background: var(--accent-soft); border-radius: 12px; margin-bottom: 17px; display:flex; align-items:center; }
.selected-course strong { color: var(--accent); }
.muted { color: var(--muted); }
.faculty { border: 1px solid var(--line); border-radius: 11px; overflow:hidden; margin: 8px 0; }
.faculty > button { width:100%; border:0; background:#fbfcfb; padding:11px 12px; display:flex; justify-content:space-between; align-items:center; text-align:left; font-weight:750; color:var(--ink); }
.faculty > button:hover { background: var(--accent-soft); }
.course-list { display:none; padding: 5px 7px 9px; border-top:1px solid var(--line); }
.faculty.open .course-list { display:block; }
.course-btn { width:100%; text-align:left; border:0; background:transparent; padding:8px 9px; border-radius:8px; color:#35403a; }
.course-btn:hover, .course-btn.selected { background:var(--accent-soft); color:var(--accent); }
.ghost, .primary { border-radius: 10px; padding: 10px 14px; border: 1px solid var(--line); }
.ghost { background: #fff; color: var(--ink); }
.primary { background: var(--accent); color:#fff; border-color:var(--accent); font-weight:750; }
.primary:hover { filter: brightness(.95); }
.generate-card { display:flex; align-items:center; justify-content:space-between; gap:20px; }
.generate-card p { margin:0; }
.drop-zone { margin-bottom:17px; padding:24px; border:1.5px dashed #99a79f; border-radius:13px; background:#fafbf9; text-align:center; cursor:pointer; }
.drop-zone input { display:none; }
.drop-zone strong, .drop-zone span { display:block; }
.drop-zone span { color:var(--muted); margin-top:5px; font-weight:400; }
.output-toolbar { display:flex; align-items:center; justify-content:space-between; gap:20px; padding-bottom:15px; border-bottom:1px solid var(--line); }
.output-title-block { flex: 1; min-width: 260px; }
.title-editor { margin-top:4px; border:0; background:transparent; padding:4px 0; font-size:28px; font-weight:850; letter-spacing:-.03em; }
.toolbar-actions { display:flex; gap:8px; flex-wrap:wrap; }
.render-status { color: var(--muted); font-size: 13px; margin-top: 2px; }
.latex-note { margin: 18px 0; padding: 12px 14px; border-radius: 11px; background: var(--accent-soft); color: #294437; }
.pdf-frame-wrap { width: 100%; min-height: 760px; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: #ddd; }
.pdf-preview { display:block; width:100%; min-height: 820px; border:0; background:#fff; }
.hidden { display:none !important; }
.loading-overlay { position:fixed; inset:0; background:rgba(20,25,22,.55); z-index:50; display:grid; place-items:center; padding:20px; }
.loader-card { width:min(440px,100%); padding:28px; border-radius:18px; background:#fff; text-align:center; box-shadow:0 30px 80px rgba(0,0,0,.25); }
.loader-card strong, .loader-card span { display:block; }
.loader-card span { color:var(--muted); margin-top:7px; }
.spinner { width:38px; height:38px; border:4px solid #dce4df; border-top-color:var(--accent); border-radius:50%; margin:0 auto 16px; animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
.error { color:var(--danger); background:#fff1f1; border:1px solid #efc5c5; border-radius:10px; padding:12px; }
@media (max-width: 980px) {
  .app-shell { grid-template-columns:1fr; }
  .sidebar { position:static; max-height:none; }
  .topbar { position:static; }
  .pdf-frame-wrap { min-height: 650px; }
  .pdf-preview { min-height: 700px; }
}
@media (max-width: 650px) {
  .topbar, .generate-card, .output-toolbar { align-items:stretch; flex-direction:column; }
  .form-grid, .checks { grid-template-columns:1fr; }
  .toolbar-actions { display:grid; grid-template-columns:1fr; }
  .pdf-frame-wrap { min-height: 520px; }
  .pdf-preview { min-height: 560px; }
}

.error-card { border-color: #e3b6b6; background: #fffafa; }
.error-toolbar { display:flex; align-items:flex-start; justify-content:space-between; gap:20px; margin-bottom:14px; }
.error-toolbar h2 { margin:4px 0 4px; color:var(--danger); }
.error-toolbar p { margin:0; }
.error-details {
  width:100%;
  min-height:260px;
  resize:vertical;
  border:1px solid #e3b6b6;
  border-radius:11px;
  padding:14px;
  background:#fff;
  color:#4b1717;
  font:13px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  white-space:pre;
  overflow:auto;
}
.error-details:focus { border-color:#b96868; box-shadow:0 0 0 3px rgba(139,46,46,.08); outline:none; }
.copy-status { min-height:22px; margin-top:8px; color:var(--accent); font-weight:700; font-size:13px; }
@media (max-width:650px) { .error-toolbar { flex-direction:column; } .error-toolbar .toolbar-actions { width:100%; } }

.vision-box { margin: 0 0 17px; padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: #f8faf8; }
.vision-toggle { display:flex; align-items:flex-start; gap:11px; font-weight:500; cursor:pointer; }
.vision-toggle input { width:auto; margin:4px 0 0; }
.vision-toggle span { display:block; }
.vision-toggle strong { display:block; color:var(--accent); }
.vision-toggle small { display:block; margin-top:3px; color:var(--muted); font-weight:400; line-height:1.45; }
.vision-options { margin-top:14px; padding-top:14px; border-top:1px solid var(--line); }
