:root {
  --navy: #071a33;
  --blue: #1459c7;
  --blue-dark: #0d46a3;
  --blue-soft: #edf4ff;
  --gold: #f4b942;
  --ink: #142033;
  --muted: #68758a;
  --line: #dce3ec;
  --surface: #ffffff;
  --page: #f3f6fa;
  --success: #197347;
  --success-soft: #eaf8f1;
  --warning: #895700;
  --warning-soft: #fff6dc;
  --danger: #a02727;
  --danger-soft: #fff0f0;
  --shadow: 0 18px 50px rgba(9, 26, 51, 0.11);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--page); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(20, 89, 199, .2), transparent 35%),
    radial-gradient(circle at 80% 10%, rgba(244, 185, 66, .18), transparent 30%),
    var(--navy);
}
.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border-radius: 24px;
  padding: 38px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .28);
}
.login-card h1 { margin: 18px 0 8px; font-size: 29px; }
.login-card p { margin: 0 0 26px; color: var(--muted); line-height: 1.5; }
.login-card label, .field-label { display: block; font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.login-card input, select, .reference-row input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-card input { padding: 13px 14px; margin-bottom: 14px; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20, 89, 199, .12); }
.mark {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 27px;
  color: var(--navy);
  background: var(--gold);
}
.mark.small { width: 40px; height: 40px; border-radius: 11px; font-size: 19px; }
.error-text { color: var(--danger); min-height: 22px; margin-top: 10px; font-size: 14px; }

.primary, .secondary, .ghost, .icon-button {
  border: 0;
  border-radius: 10px;
  padding: 10px 15px;
  font-weight: 750;
}
.primary { background: var(--blue); color: #fff; }
.primary:hover { background: var(--blue-dark); }
.primary:disabled, .secondary:disabled { opacity: .55; cursor: not-allowed; }
.secondary { background: #eef1f5; color: var(--ink); }
.secondary:hover { background: #e1e6ed; }
.ghost { background: transparent; color: #dce8fb; }
.ghost:hover { background: rgba(255,255,255,.09); }
.full { width: 100%; }
.icon-button { padding: 7px 10px; background: #eef2f7; color: var(--ink); font-size: 18px; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 68px;
  flex: 0 0 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 2px 12px rgba(5, 19, 37, .2);
  z-index: 4;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; margin-top: 2px; font-size: 11px; color: #9fb2cc; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.badge { font-size: 11px; font-weight: 800; padding: 6px 9px; border-radius: 999px; color: #21304a; background: var(--gold); margin-right: 8px; }
.badge.readonly { color: var(--danger); background: #ffd7d7; }

.workspace { min-height: calc(100vh - 68px); display: grid; grid-template-columns: 315px 1fr; }
.course-panel {
  border-right: 1px solid var(--line);
  background: #fbfcfe;
  padding: 24px 20px;
  overflow-y: auto;
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.panel-heading h2, .drawer-header h2 { margin: 3px 0 0; font-size: 22px; }
.eyebrow { text-transform: uppercase; letter-spacing: .09em; font-size: 10px; font-weight: 850; color: var(--blue); }
select { padding: 12px 36px 12px 12px; margin-bottom: 16px; }
.course-card {
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  padding: 15px;
  box-shadow: 0 6px 18px rgba(9, 26, 51, .04);
}
.course-card.empty { color: var(--muted); font-size: 13px; }
.course-card h3 { margin: 0 0 4px; font-size: 16px; }
.course-card .course-code { color: var(--muted); font-size: 12px; }
.course-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 14px; }
.stat { border-radius: 9px; background: #f3f6fa; padding: 9px; }
.stat strong { display: block; font-size: 17px; }
.stat span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.course-meta { margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); line-height: 1.6; }
.guardrails { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 18px; }
.guardrails h3 { margin: 0 0 12px; font-size: 13px; }
.guardrails div { display: flex; gap: 8px; align-items: center; margin: 9px 0; color: var(--muted); font-size: 12px; }
.guardrails span { color: var(--success); font-weight: 900; }

.assistant-panel { min-width: 0; display: flex; flex-direction: column; height: calc(100vh - 68px); }
.chat { flex: 1; overflow-y: auto; padding: 30px max(30px, calc((100% - 1050px) / 2)); }
.message { display: flex; gap: 12px; margin-bottom: 22px; }
.message.user-message { justify-content: flex-end; }
.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 900;
  background: var(--navy);
  color: #fff;
}
.user-message .avatar { order: 2; background: var(--blue); }
.bubble {
  max-width: min(880px, calc(100% - 46px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px 16px 16px 16px;
  padding: 16px 18px;
  box-shadow: 0 5px 18px rgba(9, 26, 51, .04);
}
.user-message .bubble { background: var(--blue); color: #fff; border: 0; border-radius: 16px 6px 16px 16px; }
.bubble p { margin: 0; line-height: 1.55; }
.prompt-examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.prompt-examples button { border: 1px solid #c8d8f2; color: var(--blue-dark); background: var(--blue-soft); border-radius: 999px; padding: 7px 11px; font-size: 11px; font-weight: 700; }
.loading-bubble { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); animation: pulse 1s infinite alternate; }
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { from { opacity: .25; transform: translateY(0); } to { opacity: 1; transform: translateY(-3px); } }

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  padding: 15px max(30px, calc((100% - 1050px) / 2)) 18px;
  box-shadow: 0 -8px 28px rgba(9, 26, 51, .04);
}
.reference-row { display: grid; grid-template-columns: 130px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.reference-row label { font-size: 11px; font-weight: 750; color: var(--muted); }
.reference-row label span { font-weight: 500; }
.reference-row input { padding: 8px 10px; font-size: 12px; }
textarea { resize: vertical; min-height: 82px; max-height: 220px; padding: 13px 14px; line-height: 1.45; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-top: 9px; }
.composer-footer span { font-size: 11px; color: var(--muted); }

.plan-bubble { width: min(960px, calc(100% - 46px)); max-width: 960px; padding: 0; overflow: hidden; }
.plan-bubble > .assistant-copy { padding: 17px 18px 0; }
.plan-card { margin-top: 14px; border-top: 1px solid var(--line); }
.plan-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; padding: 16px 18px; background: #f8faff; }
.plan-header h3 { margin: 4px 0 0; font-size: 16px; }
.status-pill { flex: 0 0 auto; border-radius: 999px; padding: 5px 9px; background: var(--warning-soft); color: var(--warning); font-size: 10px; font-weight: 800; }
.status-pill.applied { background: var(--success-soft); color: var(--success); }
.status-pill.failed { background: var(--danger-soft); color: var(--danger); }
.notice-list { margin: 12px 18px 0; border-radius: 10px; padding: 10px 12px; font-size: 12px; line-height: 1.5; }
.notice-list.assumptions { background: var(--blue-soft); color: #284e82; }
.notice-list.warnings { background: var(--warning-soft); color: var(--warning); }
.notice-list strong { display: block; margin-bottom: 4px; }
.notice-list ul { margin: 0; padding-left: 18px; }
.changes-wrap { overflow-x: auto; padding: 12px 18px 0; }
.changes-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.changes-table th { text-align: left; padding: 9px 8px; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.changes-table td { padding: 10px 8px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.item-name { font-weight: 750; min-width: 160px; }
.item-reason { display: block; color: var(--muted); font-weight: 400; font-size: 10px; margin-top: 3px; }
.value-old { color: var(--muted); }
.value-new { color: var(--success); font-weight: 750; }
.plan-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 15px 18px 17px; }
.plan-empty { padding: 18px; color: var(--muted); }
.plan-result { margin: 0 18px 18px; border-radius: 10px; padding: 11px 12px; font-size: 12px; }
.plan-result.success { background: var(--success-soft); color: var(--success); }
.plan-result.error { background: var(--danger-soft); color: var(--danger); }

.drawer {
  position: fixed;
  z-index: 20;
  right: 0;
  top: 0;
  width: min(480px, 92vw);
  height: 100vh;
  background: #fff;
  box-shadow: -20px 0 60px rgba(9, 26, 51, .2);
  transform: translateX(105%);
  transition: transform .2s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid var(--line); }
.history-list { padding: 14px; overflow-y: auto; }
.history-item { border: 1px solid var(--line); border-radius: 12px; padding: 13px; margin-bottom: 10px; }
.history-item h3 { margin: 0 0 4px; font-size: 14px; }
.history-item p { margin: 4px 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.history-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.history-status { font-size: 10px; text-transform: uppercase; font-weight: 850; color: var(--blue); }
.undo-button { border: 1px solid #bad0ef; background: var(--blue-soft); color: var(--blue-dark); border-radius: 8px; padding: 6px 9px; font-size: 11px; font-weight: 750; }
.backdrop { position: fixed; inset: 0; z-index: 19; background: rgba(5, 19, 37, .4); }

@media (max-width: 850px) {
  .workspace { grid-template-columns: 1fr; }
  .course-panel { border-right: 0; border-bottom: 1px solid var(--line); padding: 15px; }
  .guardrails { display: none; }
  .panel-heading { margin-bottom: 12px; }
  .course-card { display: none; }
  .assistant-panel { height: calc(100vh - 225px); min-height: 520px; }
  .chat, .composer { padding-left: 14px; padding-right: 14px; }
  .badge { display: none; }
  .reference-row { grid-template-columns: 1fr; }
  .reference-row label { display: none; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 12px; }
  .brand strong { font-size: 13px; }
  .brand span { display: none; }
  .ghost { padding: 8px 7px; font-size: 12px; }
  .bubble, .plan-bubble { max-width: calc(100% - 42px); width: calc(100% - 42px); }
  .plan-header { flex-direction: column; }
  .composer-footer { align-items: flex-end; }
  .composer-footer span { display: none; }
}
