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

.dev-banner {
  background: #E8927C;
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  margin: -30px -30px 20px -30px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
  min-height: 100vh;
  padding: 30px;
}

.logo img {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

select {
  padding: 10px 16px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

select:hover {
  border-color: #999;
}

select:focus {
  outline: none;
  border-color: #667788;
  box-shadow: 0 0 0 3px rgba(102,119,136,0.15);
}

.main-layout {
  display: flex;
  gap: 10%;
}

.schedule-container {
  flex: 0 0 60%;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  overflow-x: auto;
}

.sidebar {
  flex: 0 0 30%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar label {
  font-weight: 600;
  color: #555;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.topics-summary {
  flex: 1;
  min-height: 200px;
  padding: 12px;
  font-size: 13px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: white;
  overflow-y: auto;
}

.topics-placeholder {
  color: #999;
  font-style: italic;
}

.topic-item {
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  display: flex;
  gap: 8px;
}

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

.topic-num {
  font-weight: 600;
  color: #667788;
  white-space: nowrap;
}

.topic-text {
  color: #666;
  flex: 1;
  cursor: text;
  padding: 2px 4px;
  border-radius: 4px;
  min-width: 50px;
}

.topic-text:hover {
  background: #f5f5f5;
}

.topic-text:focus {
  outline: none;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(102,119,136,0.3);
}

.topic-text:empty::before {
  content: "Add topic...";
  color: #bbb;
  font-style: italic;
}

.paste-area {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paste-area label {
  font-weight: 600;
  color: #555;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.paste-area textarea {
  min-height: 80px;
  padding: 8px;
  font-family: inherit;
  font-size: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  resize: vertical;
}

.paste-area textarea:focus {
  outline: none;
  border-color: #667788;
  box-shadow: 0 0 0 2px rgba(102,119,136,0.15);
}

.apply-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #667788;
  border-radius: 6px;
  background: #667788;
  color: white;
  cursor: pointer;
  align-self: flex-end;
}

.apply-btn:hover {
  background: #556677;
}

/* Draggable topics */
.drag-handle {
  color: #bbb;
  cursor: grab;
  user-select: none;
  font-size: 10px;
  letter-spacing: -2px;
  padding-right: 4px;
}

.drag-handle:hover {
  color: #888;
}

.topic-item:active .drag-handle {
  cursor: grabbing;
}

.topic-item.dragging {
  opacity: 0.5;
  background: #f5f5f5;
}

.topic-item.drag-over {
  border-top: 2px solid #667788;
  padding-top: 4px;
}

/* Editable event cell */
.event-cell .event-text {
  cursor: text;
}

.event-cell .event-text:focus {
  outline: none;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
}

@media (max-width: 1200px) {
  .main-layout {
    flex-direction: column;
    gap: 24px;
  }

  .schedule-container,
  .sidebar {
    flex: 1 1 auto;
  }

  .topics-summary {
    min-height: 150px;
  }
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 600px;
  table-layout: fixed;
}

#scheduleTable th,
#scheduleTable td {
  padding: 12px 10px;
  text-align: center;
  overflow: hidden;
  border-right: 2px solid silver;
}

#scheduleTable th {
  background: linear-gradient(180deg, #f8f9fa 0%, #eef0f2 100%);
  font-weight: 600;
  color: #444;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.5px;
  border-top: none;
}

#scheduleTable th:first-child {
  width: 50px;
  border-left: none;
  border-radius: 12px 0 0 0;
}

#scheduleTable th:last-child {
  border-radius: 0 12px 0 0;
}

#scheduleTable th:not(:first-child) {
  width: calc((100% - 50px) / 5);
}

.week-header {
  background: linear-gradient(180deg, #f8f9fa 0%, #eef0f2 100%);
  color: black;
  font-weight: 600;
  font-size: 12px;
  width: 50px;
  min-width: 50px;
  max-width: 50px;
  border-left: none;
}

.date-row td {
  font-weight: 600;
  font-size: 13px;
  min-height: 32px;
  height: 32px;
  vertical-align: middle;
  color: white;
  border-top: 3px double silver;
}

.date-row td.week-header {
  color: black;
}

.label-row td {
  font-size: 11px;
  min-height: 28px;
  height: 28px;
  vertical-align: middle;
  background: white;
}

.label-row td.week-header {
  background: linear-gradient(180deg, #f8f9fa 0%, #eef0f2 100%);
  color: black;
  font-weight: 600;
  font-size: 12px;
}

.event-row td {
  font-size: 11px;
  font-weight: 500;
  min-height: 28px;
  height: 28px;
  vertical-align: middle;
  background: white;
  color: white;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 30px;
  align-items: center;
  margin-bottom: 24px;
  padding: 16px 24px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.control-group:last-child {
  flex-shrink: 1;
  min-width: 0;
  overflow-x: auto;
}

.control-group label {
  font-weight: 600;
  color: #555;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.day-matrix {
  border-collapse: collapse;
  overflow: visible;
}

.day-matrix th,
.day-matrix td {
  padding: 4px 8px;
  text-align: center;
}

.day-matrix th {
  font-weight: 600;
  font-size: 12px;
  color: #666;
}

.event-label {
  font-weight: 600;
  text-align: right;
  padding-right: 12px;
  white-space: nowrap;
}

.day-btn {
  width: 26px;
  height: 26px;
  border: 2px solid #ddd;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  transition: all 0.15s;
}

.day-btn:hover {
  border-color: #999;
  transform: scale(1.05);
}

.day-btn.active {
  background: #667788;
  border-color: #667788;
  box-shadow: 0 2px 4px rgba(102,119,136,0.3);
}

.toggle-buttons {
  display: flex;
  gap: 0;
}

.toggle-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid #ddd;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn:first-child {
  border-radius: 8px 0 0 8px;
}

.toggle-btn:last-child {
  border-radius: 0 8px 8px 0;
  border-left: none;
}

.toggle-btn:hover:not(.active) {
  background: #f5f5f5;
}

.toggle-btn.active {
  background: #667788;
  color: white;
  border-color: #667788;
}

.midterm-buttons {
  display: flex;
  gap: 8px;
}

.midterm-btn {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  border: 2px solid #d4a800;
  border-radius: 6px;
  background: #fff3cd;
  color: #856404;
  cursor: grab;
  transition: all 0.15s;
}

.midterm-btn:hover {
  background: #ffe69c;
  transform: scale(1.05);
}

.midterm-btn:active {
  cursor: grabbing;
}

.midterm-btn.placed {
  display: none;
}

.midterm-btn.dragging {
  opacity: 0.5;
}

.save-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border: 2px solid #667788;
  border-radius: 6px;
  background: #667788;
  color: white;
  cursor: pointer;
  transition: all 0.15s;
}

.save-btn:hover {
  background: #556677;
  border-color: #556677;
}

.load-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border: 2px solid #667788;
  border-radius: 6px;
  background: white;
  color: #667788;
  cursor: pointer;
  transition: all 0.15s;
}

.load-btn:hover {
  background: #f0f2f4;
}

#scheduleTable td.drop-target {
  outline: 2px dashed #d4a800;
  outline-offset: -2px;
  background: #fff3cd !important;
}

.midterm-label {
  display: block;
  background: transparent;
  color: #856404;
  padding: 0;
  font-size: 11px;
  font-weight: 600;
  cursor: grab;
}

.midterm-label:hover {
  background: transparent;
}

.midterm-label.dragging {
  opacity: 0.5;
}

/* Style label-row cells containing midterms */
.label-row td:has(.midterm-label) {
  background: #fff3cd;
  position: relative;
}

.label-row td:has(.midterm-label) .midterm-label {
  display: flex;
  align-items: center;
  justify-content: center;
}

.midterm-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  color: white;
  font-size: 10px;
  line-height: 14px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.label-row td:has(.midterm-label):hover .midterm-remove {
  opacity: 1;
}

.midterm-remove:hover {
  background: rgba(0, 0, 0, 0.5);
}

.event-cell {
  position: relative;
}

.event-cell .event-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  color: white;
  font-size: 10px;
  line-height: 14px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.event-cell:hover .event-remove {
  opacity: 1;
}

.event-cell .event-remove:hover {
  background: rgba(0, 0, 0, 0.5);
}

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  margin-top: 24px;
  color: #666;
  font-size: 13px;
  position: relative;
}

.footer-left {
  position: absolute;
  left: 16px;
}

.footer a {
  color: #666;
  transition: color 0.15s;
}

.footer a:hover {
  color: #333;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  text-align: center;
}

.modal-content p {
  margin-bottom: 20px;
  line-height: 1.6;
  white-space: pre-line;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modal-btn {
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.modal-btn#modalShift {
  background: #667788;
  color: white;
}

.modal-btn#modalShift:hover {
  background: #556677;
}

.modal-btn#modalSkip {
  background: #e0e0e0;
  color: #333;
}

.modal-btn#modalSkip:hover {
  background: #d0d0d0;
}

/* Responsive styles */
@media (max-width: 900px) {
  body {
    padding: 16px;
  }

  .controls {
    gap: 12px 20px;
    padding: 12px 16px;
  }

  .control-group {
    gap: 8px;
  }

  .day-matrix th,
  .day-matrix td {
    padding: 3px 5px;
  }

  .day-btn {
    width: 22px;
    height: 22px;
  }

  .event-label {
    font-size: 11px;
    padding-right: 8px;
  }
}

/* Print styles */
@media print {
  * {
    visibility: hidden;
  }

  .schedule-container,
  .schedule-container * {
    visibility: visible;
  }

  body {
    background: white;
    padding: 0;
    margin: 0;
  }

  .schedule-container {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    box-shadow: none;
    border-radius: 0;
  }

  table {
    min-width: unset;
    width: 100%;
  }

  #scheduleTable th,
  #scheduleTable td {
    padding: 8px 6px;
    font-size: 11px;
    border: 1px solid #ccc;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .week-header {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .date-row td {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .label-row td {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .event-row td {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .event-cell .event-remove {
    display: none;
  }

  .midterm-label {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .modal {
    display: none !important;
  }

  .footer {
    display: none;
  }

  .sidebar {
    display: none;
  }

  .main-layout {
    display: block;
  }

  .schedule-container {
    flex: none;
    width: 100%;
  }
}

@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .controls {
    gap: 10px 16px;
    padding: 10px 12px;
  }

  .logo img {
    height: 40px;
  }

  .control-group label {
    font-size: 11px;
  }

  select {
    padding: 8px 12px;
    font-size: 13px;
  }

  .toggle-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .day-matrix th,
  .day-matrix td {
    padding: 2px 3px;
  }

  .day-btn {
    width: 20px;
    height: 20px;
    border-width: 1px;
  }

  .event-label {
    font-size: 10px;
    padding-right: 4px;
  }

  .midterm-btn {
    padding: 4px 8px;
    font-size: 10px;
  }

  .modal-content {
    margin: 16px;
    padding: 16px;
    max-width: calc(100% - 32px);
  }

  .modal-btn {
    padding: 8px 16px;
    font-size: 13px;
  }
}
