:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d1d5db;
  --accent: #1d4ed8;
  --warn: #92400e;
  --warn-bg: #fffbeb;
  --error: #991b1b;
  --error-bg: #fef2f2;
  --ok: #166534;
  --ok-bg: #f0fdf4;

  --major-core-bg: #eff6ff;
  --major-elective-bg: #dbeafe;
  --ge-core-bg: #f0fdf4;
  --ge-elective-bg: #dcfce7;
  --pe-bg: #fffbeb;
  --nstp-bg: #f5f3ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: "Roboto", Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

/* ---------- Layout ---------- */

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0f172a;
  color: #e5e7eb;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-text {
  min-width: 0;
}

.site-logo {
  width: clamp(48px, 10vw, 84px);
  height: clamp(48px, 10vw, 84px);
  max-width: 84px;
  max-height: 84px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand {
  font-size: 18px;
  font-weight: 700;
}

.sub {
  font-size: 12px;
  color: #94a3b8;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav button {
  text-align: left;
  padding: 10px 12px;
  background: transparent;
  color: inherit;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.nav button.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.nav a {
  text-align: left;
  padding: 10px 12px;
  background: transparent;
  color: inherit;
  border: 1px solid transparent;
  border-radius: 8px;
  text-decoration: none;
}

.nav a:hover,
.nav a:focus {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.sidebar-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.sidebar-actions button {
  padding: 10px 12px;
  background: #1e293b;
  color: #fff;
  border: 1px solid #334155;
  border-radius: 8px;
  cursor: pointer;
  min-height: 40px;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toolbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.toolbar .left,
.toolbar .right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font: inherit;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.secondary {
  background: #fff;
}

.danger {
  color: var(--error);
  border-color: #fecaca;
}

.content {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(15,23,42,0.05);
}

.panel h2,
.panel h3,
.panel h4 {
  margin-top: 0;
}

.muted { color: var(--muted); }
.hidden { display: none !important; }
.small { font-size: 12px; }

.inline-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Form Layout ---------- */

.grid-2,
.grid-3,
.grid-4 {
  display: grid;
  gap: 12px;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

textarea {
  min-height: 70px;
  resize: vertical;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

/* ---------- Status Boxes ---------- */

.status-box,
.warn-box,
.error-box {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-line;
}

.status-box { background: var(--ok-bg); color: var(--ok); }
.warn-box { background: var(--warn-bg); color: var(--warn); }
.error-box { background: var(--error-bg); color: var(--error); }

/* ---------- Term Cards ---------- */

.term-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.term-header {
  background: #f8fafc;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.term-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
}

.term-actions,
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tiny-btn {
  padding: 6px 8px;
  font-size: 12px;
  min-height: 32px;
}

.term-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.term-body[hidden] {
  display: none !important;
}

.course-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: grid;
  gap: 12px;
  background: #fff;
}

.row-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

/* ---------- Mobile Top Controls ---------- */

.mobile-top-controls {
  display: none;
}

.mobile-screen-nav,
.mobile-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- Autocomplete ---------- */

.autocomplete {
  position: relative;
}

.autocomplete-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15,23,42,0.12);
  max-height: 260px;
  overflow: auto;
  z-index: 20;
}

.autocomplete-item {
  padding: 12px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: #eff6ff;
}

.autocomplete-item .code {
  font-weight: 700;
}

.autocomplete-item .meta {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Tables ---------- */

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid #e5e7eb;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  font-weight: 700;
}

td .tiny-btn {
  margin-right: 6px;
  margin-bottom: 4px;
}

.print-report-root {
  display: grid;
  gap: 16px;
}

.course-summary-table th:last-child,
.course-summary-table td:last-child {
  white-space: nowrap;
}

.compact-row-actions {
  justify-content: flex-start;
}

.inline-editor-row td {
  background: #f8fafc;
  padding: 10px;
  border-bottom: 1px solid #dbe3ef;
}

.inline-editor-card {
  border: 1px solid #dbe3ef;
  background: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
}

/* ---------- Row Type Tints ---------- */

tr.rowtype-major-core td {
  background: var(--major-core-bg);
}

tr.rowtype-major-elective td {
  background: var(--major-elective-bg);
}

tr.rowtype-ge-core td {
  background: var(--ge-core-bg);
}

tr.rowtype-ge-elective td {
  background: var(--ge-elective-bg);
}

tr.rowtype-pe td {
  background: var(--pe-bg);
}

tr.rowtype-nstp td {
  background: var(--nstp-bg);
}

tr.rowtype-major-core th,
tr.rowtype-major-elective th,
tr.rowtype-ge-core th,
tr.rowtype-ge-elective th,
tr.rowtype-pe th,
tr.rowtype-nstp th {
  background: #f8fafc;
}

tr.rowtype-major-core td:first-child {
  border-left: 4px solid #60a5fa;
}

tr.rowtype-major-elective td:first-child {
  border-left: 4px solid #3b82f6;
}

tr.rowtype-ge-core td:first-child {
  border-left: 4px solid #4ade80;
}

tr.rowtype-ge-elective td:first-child {
  border-left: 4px solid #22c55e;
}

tr.rowtype-pe td:first-child {
  border-left: 4px solid #f59e0b;
}

tr.rowtype-nstp td:first-child {
  border-left: 4px solid #8b5cf6;
}

.preprogram-course-table tr.preprogram-summary-row td {
  background: #fff7ed;
}

.preprogram-course-table tr.preprogram-summary-row td:first-child {
  border-left: 4px solid #f97316;
}

.advising-course-table tr.advising-summary-row td:first-child {
  border-left-width: 4px;
}

.advising-course-table tr.advising-summary-row.is-source td {
  background: #f8fafc;
}

.advising-course-table tr.advising-summary-row.is-source td:first-child {
  border-left-color: #6b7280;
}

.advising-course-table tr.advising-summary-row.is-preprogram td {
  background: #fff7ed;
}

.advising-course-table tr.advising-summary-row.is-preprogram td:first-child {
  border-left-color: #f97316;
}

.advising-course-table tr.advising-summary-row.is-projected td {
  background: #eff6ff;
}

.advising-course-table tr.advising-summary-row.is-projected td:first-child {
  border-left-color: #3b82f6;
}

.advising-course-table tr.advising-summary-row.is-manual td {
  background: #f5f3ff;
}

.advising-course-table tr.advising-summary-row.is-manual td:first-child {
  border-left-color: #8b5cf6;
}

.advising-course-table tr.advising-summary-row.is-locked td {
  background-image: linear-gradient(rgba(243,244,246,0.55), rgba(243,244,246,0.55));
}

.advising-inline-editor-row td,
.advising-advisory-row td {
  background: #f8fafc;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.42);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop:not([hidden]) {
  display: flex;
}

.modal-backdrop.show {
  display: flex;
}

.modal {
  width: min(720px, 100%);
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 18px;
  display: grid;
  gap: 14px;
}

.modal-card {
  width: min(560px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
  padding: 20px;
  display: grid;
  gap: 12px;
}

.modal-card h2,
.modal-card p {
  margin: 0;
}

.modal-actions {
  justify-content: flex-end;
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .mobile-top-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: nowrap;
  }

  .mobile-screen-nav {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
  }

  .mobile-action-row {
    flex: 0 0 auto;
    margin-left: auto;
    flex-wrap: nowrap;
  }

  .grid-4,
  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .toolbar {
    padding: 10px 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .toolbar .right {
    display: none;
  }

  .toolbar .left {
    gap: 6px;
  }

  #toolbarTitle {
    font-size: 16px;
  }

  .section-heading-row {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .brand-block {
    gap: 10px;
  }

  .site-logo {
    width: 56px;
    height: 56px;
  }

  .content {
    padding: 10px;
    gap: 10px;
  }

  .panel {
    padding: 10px;
    border-radius: 10px;
  }

  .panel h2 {
    font-size: 18px;
    margin-bottom: 8px;
  }

  .panel h3,
  .panel h4 {
    margin-bottom: 6px;
  }

  label {
    gap: 4px;
    font-size: 12px;
  }

  input, select, textarea {
    padding: 8px 10px;
  }

  button {
    min-height: 36px;
    padding: 7px 10px;
  }

  .tiny-btn {
    min-height: 34px;
    padding: 6px 8px;
    font-size: 12px;
  }

  .mobile-top-controls {
    gap: 6px;
  }

  .mobile-screen-nav button,
  .mobile-action-row button {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
    line-height: 1.2;
  }

  th, td {
    padding: 5px 6px;
    font-size: 12px;
  }

  td .tiny-btn {
    display: block;
    width: 100%;
    margin-right: 0;
  }

  .course-title-col {
    display: none;
  }

  .course-summary-table th.course-title-col,
  .course-summary-table td.course-title-col {
    display: none;
  }

  .term-header {
    grid-template-columns: 1fr;
    padding: 10px 12px;
  }

  .term-actions {
    width: 100%;
  }

  .term-body,
  .course-row {
    padding: 10px;
    gap: 10px;
  }

  .term-actions .tiny-btn,
  .row-actions .tiny-btn,
  .row-actions .secondary,
  .row-actions .primary {
    width: 100%;
  }

  .inline-editor-row td {
    padding: 6px;
  }
}

/* ---------- Report Tables ---------- */

.report-table {
  width: auto;
  table-layout: fixed;
  border-collapse: collapse;
}

.report-table th,
.report-table td {
  vertical-align: middle;
}

.report-table th.report-center,
.report-table td.report-center {
  text-align: center;
}

.report-table th.report-right,
.report-table td.report-right {
  text-align: right;
}

.report-table th.report-col-code,
.report-table td.report-col-code,
.report-table th.report-nowrap,
.report-table td.report-nowrap {
  white-space: nowrap;
}

.report-table th.report-wrap,
.report-table td.report-wrap {
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

.report-table th.report-wrap-tight,
.report-table td.report-wrap-tight {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---------- Print / PDF ---------- */

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body {
    background: #fff;
  }

  .app {
    display: block;
  }

  .sidebar,
  .toolbar,
  .mobile-top-controls,
  .modal-backdrop,
  .no-print {
    display: none !important;
  }

  .content {
    padding: 0;
    gap: 10px;
  }

  .panel {
    box-shadow: none;
    border: 1px solid #bbb;
    border-radius: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .term-card,
  .course-row,
  .print-section {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  table {
    font-size: 11px;
  }

  th, td {
    padding: 3px 3px;
  }
}
.term-card.collapsed .term-header {
  border-bottom: 0;
}

/* ---------- Advising ---------- */

.advising-content {
  gap: 18px;
}

.sidebar-secondary {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.sidebar-version {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading-row h2 {
  margin-bottom: 0;
}

.advising-load-copy {
  max-width: 820px;
  font-size: 18px;
  line-height: 1.45;
}

.advising-load-actions {
  margin: 16px 0;
}

.advising-file-summary {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
}

.advising-file-summary h3 {
  margin: 0 0 8px;
  font-size: 20px;
}

.advising-file-summary.is-empty {
  color: var(--muted);
  background: #fff;
}

.advising-changelog {
  margin-top: 18px;
}

.advising-changelog-list {
  display: grid;
  gap: 8px;
}

.advising-changelog-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.advising-changelog-item strong {
  margin-right: 6px;
}

.advising-file-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 16px;
  align-items: start;
}

.advising-schedule {
  display: grid;
  gap: 12px;
}

.advising-term.is-locked .term-header {
  background: #f3f4f6;
}

.advising-term.is-source {
  border-color: #9ca3af;
}

.advising-term.is-projected {
  border-color: #bfdbfe;
}

.advising-term-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.advising-term-source {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.advising-term-header {
  align-items: start;
  grid-template-columns: minmax(0, 1fr) auto;
}

.advising-term-header .term-actions {
  align-items: flex-start;
  justify-content: flex-end;
}

.advising-term-header .term-actions .tiny-btn {
  align-self: flex-start;
  min-height: 40px;
  width: auto;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lock-toggle {
  flex: 0 0 auto;
}

tr.is-locked td {
  background-image: linear-gradient(rgba(243,244,246,0.55), rgba(243,244,246,0.55));
}

.advising-select-row {
  display: grid;
  gap: 6px;
  max-width: 520px;
}

.adviser-sheet {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: #fff;
  margin-bottom: 18px;
}

.adviser-sheet h3,
.adviser-sheet h4 {
  margin-top: 0;
}

.adviser-sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.adviser-actions {
  margin-top: 14px;
}

.adviser-term-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.adviser-term-block {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.critical-text {
  color: var(--error);
  font-weight: 700;
}

.advising-term-summary-block + .advising-term-summary-block {
  margin-top: 24px;
}

.advising-projection-heading {
  color: #1d4ed8;
}

.advising-report-pending td {
  background: #fffbeb;
  border-left-color: #f59e0b;
}

.advising-report-projected td {
  background: #eff6ff;
  border-left-color: #3b82f6;
}

.advising-report-pending td:first-child,
.advising-report-projected td:first-child {
  border-left-width: 4px;
}

@media (max-width: 860px) {
  .advising-file-grid,
  .adviser-sheet-grid {
    grid-template-columns: 1fr;
  }
}

.term-header.clickable {
  cursor: pointer;
}

.row-clickable {
  cursor: pointer;
}

.row-clickable:hover {
  filter: brightness(0.99);
}

.floating-add-term {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
}

@media (max-width: 768px) {
  .floating-add-term {
    right: 16px;
    bottom: 84px;
  }
}
