*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f5;
  color: #222;
  font-size: 14px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  background: #8c1515;
  color: #fff;
  padding: 16px 24px;
  flex-shrink: 0;
}

header h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 10px;
}

/* Tab bar */
#tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.tab-btn {
  padding: 6px 18px;
  border: none;
  border-radius: 4px 4px 0 0;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover { background: rgba(255,255,255,0.25); color: #fff; }

.tab-btn.active {
  background: rgba(255,255,255,0.95);
  color: #8c1515;
  font-weight: 600;
}

#controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

#search {
  flex: 1;
  min-width: 200px;
  padding: 7px 12px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
}

#dept-filter, #terms-filter {
  padding: 7px 10px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  background: #fff;
  cursor: pointer;
}

#count {
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  white-space: nowrap;
}

/* Browser view */
#table-wrap {
  flex: 1;
  overflow: auto;
  padding: 16px 24px;
}

#loading {
  text-align: center;
  padding: 40px;
  color: #888;
}

#courses-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#courses-table thead {
  background: #4a4a4a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1;
}

#courses-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.col-add { width: 36px; cursor: default; padding: 10px 6px; }

#courses-table th:hover { background: #5a5a5a; }
th.col-add:hover { background: #4a4a4a; }
#courses-table th.sort-asc::after { content: ' ↑'; opacity: 0.8; }
#courses-table th.sort-desc::after { content: ' ↓'; opacity: 0.8; }

#courses-table td {
  padding: 8px 14px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}

#courses-table tbody tr:last-child td { border-bottom: none; }
#courses-table tbody tr:hover { background: #fafafa; }

td.col-add { padding: 6px 6px; text-align: center; }

.add-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: #8c1515;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
  flex-shrink: 0;
}

.add-btn:hover { background: #6b1010; transform: scale(1.1); }

.add-btn.added {
  background: #2e7d32;
  font-size: 14px;
  cursor: default;
}

.add-btn.added:hover { background: #2e7d32; transform: none; }

td.code { font-weight: 600; white-space: nowrap; color: #8c1515; }
td.name { min-width: 220px; }
td.units { white-space: nowrap; text-align: center; }
td.instructors { font-size: 12px; color: #555; min-width: 140px; }
td.instructors details summary { cursor: pointer; }
td.instructors details[open] summary { margin-bottom: 4px; }
td.terms { white-space: nowrap; font-size: 13px; }
.inactive { color: #aaa; font-style: italic; }

#pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 16px 0 8px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  color: #333;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.page-btn:hover { background: #f0f0f0; }

.page-btn.active {
  background: #8c1515;
  color: #fff;
  border-color: #8c1515;
  font-weight: 600;
  cursor: default;
}

.page-ellipsis {
  padding: 0 4px;
  color: #888;
  font-size: 14px;
  line-height: 36px;
}

/* Planner view */
#planner-view {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
}

#planner-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#add-quarter-btn {
  padding: 8px 16px;
  background: #8c1515;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

#add-quarter-btn:hover { background: #6b1010; }

#add-quarter-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

#new-quarter-input {
  padding: 7px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  width: 200px;
}

#new-quarter-confirm {
  padding: 7px 14px;
  background: #8c1515;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}

#new-quarter-confirm:hover { background: #6b1010; }

#new-quarter-cancel {
  padding: 7px 14px;
  background: #eee;
  color: #444;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}

#new-quarter-cancel:hover { background: #ddd; }

#quarters-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quarter-section {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  overflow: visible;
}

.quarter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  background: #4a4a4a;
  border-radius: 6px 6px 0 0;
  color: #fff;
}

.quarter-label {
  font-weight: 600;
  font-size: 15px;
}

.quarter-delete-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.quarter-delete-btn:hover { color: #fff; }

.quarter-table {
  width: 100%;
  border-collapse: collapse;
}

.quarter-table td {
  padding: 8px 14px;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}

.quarter-table tr:last-child td { border-bottom: none; }

.quarter-table .q-code { font-weight: 600; color: #8c1515; white-space: nowrap; width: 90px; }
.quarter-table .q-units { white-space: nowrap; text-align: center; width: 60px; color: #555; }
.quarter-table .q-remove { width: 32px; text-align: center; }

.remove-btn {
  background: none;
  border: none;
  color: #bbb;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.remove-btn:hover { color: #8c1515; }

.quarter-subtotal {
  display: flex;
  justify-content: flex-end;
  padding: 8px 16px;
  font-size: 13px;
  color: #555;
  border-top: 1px solid #eee;
  background: #fafafa;
}

.quarter-subtotal strong { color: #222; margin-left: 4px; }

/* Add-course row inside quarter */
.quarter-add-row {
  padding: 10px 14px;
  position: relative;
}

.quarter-add-wrap {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 360px;
}

.quarter-add-input {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  color: #222;
}

.quarter-add-input:focus { outline: none; border-color: #8c1515; }

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.12);
  z-index: 100;
  max-height: 260px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.autocomplete-item:hover { background: #f5f5f5; }
.autocomplete-item.already-added { color: #aaa; cursor: default; }
.autocomplete-item.already-added:hover { background: #fff; }

.ac-code { font-weight: 600; color: #8c1515; white-space: nowrap; font-size: 13px; }
.ac-name { color: #444; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ac-units { color: #888; font-size: 12px; white-space: nowrap; }
.autocomplete-item.already-added .ac-code { color: #bbb; }

#planner-grand-total {
  margin-top: 20px;
  padding: 12px 16px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  font-size: 15px;
  font-weight: 600;
  text-align: right;
  color: #222;
}

#planner-empty {
  padding: 60px 0;
  text-align: center;
  color: #888;
}

/* Add-to-planner modal */
#add-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#add-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

#add-modal-dialog {
  position: relative;
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

#add-modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #8c1515;
}

#add-modal-subtitle {
  font-size: 13px;
  color: #666;
  margin-bottom: 14px;
}

#add-modal-quarters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  max-height: 200px;
  overflow-y: auto;
}

.modal-quarter-btn {
  padding: 9px 14px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 4px;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.1s;
}

.modal-quarter-btn:hover { background: #ffe8e8; border-color: #8c1515; color: #8c1515; }

.modal-quarter-btn.already-in {
  background: #e8f5e9;
  border-color: #2e7d32;
  color: #2e7d32;
  cursor: default;
}

.modal-quarter-btn.already-in:hover { background: #e8f5e9; border-color: #2e7d32; color: #2e7d32; }

#add-modal-new {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

#add-modal-new-input {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}

#add-modal-new-btn {
  padding: 7px 14px;
  background: #8c1515;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

#add-modal-new-btn:hover { background: #6b1010; }

#add-modal-close {
  width: 100%;
  padding: 8px;
  background: #eee;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  color: #444;
  cursor: pointer;
}

#add-modal-close:hover { background: #ddd; }
