:root {
  --bg-dark: #09040F;
  --card: rgba(255, 255, 255, 0.03);
  --card-border: rgba(255, 255, 255, 0.08);
  --ink: #FFFFFF;
  --muted: #9BA1B0;
  --board: rgba(20, 15, 30, 0.5);
  --board-edge: transparent;
  --chalk: #FFFFFF;
  --chalk-dim: rgba(255, 255, 255, 0.5);
  --primary-gradient: linear-gradient(90deg, #A838FF, #FF4B9E);
  --c1: #F2C14E;
  --c2: #E8879C;
  --c3: #74B3E8;
  --c4: #E8985A;
  --c5: #8FD9B6;
  --c6: #C9A6E8;
  --surface2: #150F20;
  --input-bg: rgba(0, 0, 0, 0.2);
  --input-scheme: dark;
  --soft-fill: rgba(255, 255, 255, 0.05);
  --soft-fill-hover: rgba(255, 255, 255, 0.1);
  --faint-dot: rgba(255, 255, 255, 0.2);
  --faint-glyph: rgba(255, 255, 255, 0.15);
  --grid-line: rgba(255, 255, 255, 0.25);
}

:root[data-theme="light"] {
  --bg-dark: #F3F1FA;
  --card: rgba(255, 255, 255, 0.65);
  --card-border: rgba(20, 10, 40, 0.1);
  --ink: #201A2E;
  --muted: #6C6884;
  --board: rgba(255, 255, 255, 0.6);
  --chalk: #201A2E;
  --chalk-dim: rgba(32, 26, 46, 0.55);
  --surface2: #FFFFFF;
  --input-bg: rgba(20, 10, 40, 0.04);
  --input-scheme: light;
  --soft-fill: rgba(20, 10, 40, 0.045);
  --soft-fill-hover: rgba(20, 10, 40, 0.09);
  --faint-dot: rgba(20, 10, 40, 0.18);
  --faint-glyph: rgba(20, 10, 40, 0.15);
  --grid-line: rgba(20, 10, 40, 0.15);
}

:root[data-theme="light"] body {
  background-image:
    radial-gradient(circle at 15% 30%, rgba(168, 56, 255, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(255, 75, 158, 0.07) 0%, transparent 45%);
}

:root[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.75); }

* { box-sizing: border-box; }

html, body {
  height: auto;
  min-height: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  color: var(--ink);
  min-height: 100vh;
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(circle at 15% 30%, rgba(168, 56, 255, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(255, 75, 158, 0.1) 0%, transparent 45%);
  background-attachment: fixed;
  overflow-y: auto;
}

/* ---------------- TOP BAR ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(9, 4, 15, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-border);
}

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

.brand-icon {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--primary-gradient);
  font-size: 18px;
  overflow: hidden;
  flex-shrink: 0;
}

.brand-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.pdf-btn {
  padding: 11px 20px;
  border: none;
  border-radius: 20px;
  background: var(--primary-gradient);
  color: #FFF;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(255, 75, 158, 0.25);
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.pdf-btn:hover { opacity: 0.9; }
.pdf-btn:active { transform: scale(0.98); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.reset-btn {
  padding: 11px 18px;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: transparent;
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.reset-btn:hover { background: rgba(255, 255, 255, 0.08); }
.reset-btn:active { transform: scale(0.98); }
:root[data-theme="light"] .reset-btn:hover { background: rgba(0, 0, 0, 0.05); }

/* ---------------- GRID LAYOUT ---------------- */
.app {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  padding: 28px 32px 60px;
  max-width: 1680px;
  margin: 0 auto;
  transition: grid-template-columns 0.2s ease;
}

.panel { min-width: 0; }

.panel-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
}

.panel-head h2 {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 2px;
  letter-spacing: -0.01em;
}

.panel-sub {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.panel-icon {
  flex-shrink: 0;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: rgba(168, 56, 255, 0.15);
  color: #C9A6E8;
  font-size: 15px;
  object-fit: contain;
}

.ai-generate-devy {
  width: 20px; height: 20px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 6px;
  margin-bottom: 2px;
}

label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field { margin-bottom: 18px; }

input[type="text"], input[type="time"], select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--ink);
  outline: none;
  transition: all 0.2s ease;
  color-scheme: var(--input-scheme);
}

input:focus, select:focus {
  border-color: #A838FF;
  box-shadow: 0 0 0 3px rgba(168, 56, 255, 0.15);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%239BA1B0'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 32px;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.input-with-dot {
  position: relative;
}
.input-with-dot input[type="text"] {
  padding-left: 34px;
}
.input-with-dot .swatch-dot {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
}

.swatch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.swatch-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
.swatch-dot::-webkit-color-swatch-wrapper { padding: 0; }
.swatch-dot::-webkit-color-swatch { border: none; border-radius: 50%; }
.swatch-dot::-moz-color-swatch { border: none; border-radius: 50%; }

.swatch-hint {
  font-size: 11px;
  color: var(--muted);
  text-decoration: underline dotted;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: 'Inter', sans-serif;
}

.conflict-banner, .editing-flag {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 10px;
  padding: 10px 14px;
}

.conflict-banner {
  color: #FF7B72;
  background: rgba(255, 123, 114, 0.08);
  border: 1px solid rgba(255, 123, 114, 0.2);
  margin: -4px 0 16px;
}
.conflict-banner.show { display: flex; }

.editing-flag {
  color: #F2C14E;
  background: rgba(242, 193, 78, 0.08);
  border: 1px solid rgba(242, 193, 78, 0.2);
  margin-bottom: 18px;
}
.editing-flag.show { display: flex; }

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.add-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 30px;
  background: var(--primary-gradient);
  color: #FFF;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
  box-shadow: 0 4px 15px rgba(255, 75, 158, 0.25);
}
.add-btn:hover { opacity: 0.9; }
.add-btn:active { transform: scale(0.98); }

.break-btn, .cancel-edit-btn, .manage-btn, .util-btn {
  width: 100%;
  padding: 12px 18px;
  border: 1px solid var(--card-border);
  border-radius: 30px;
  background: var(--soft-fill);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.break-btn:hover, .cancel-edit-btn:hover, .manage-btn:hover, .util-btn:hover { background: var(--soft-fill-hover); }
.break-btn:active, .cancel-edit-btn:active, .manage-btn:active, .util-btn:active { transform: scale(0.98); }

.manage-btn { border-color: rgba(168, 56, 255, 0.35); color: #C9A6E8; }
.manage-btn.active { background: rgba(168, 56, 255, 0.18); }

.cancel-edit-btn { display: none; }
.cancel-edit-btn.show { display: flex; }

.tools-group {
  margin-top: 16px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: var(--soft-fill);
  overflow: hidden;
}

.tools-group summary {
  padding: 14px 18px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.tools-group summary::-webkit-details-marker { display: none; }
.tools-group summary::after {
  content: '▾';
  font-size: 12px;
  color: var(--muted);
  transition: transform 0.2s ease;
}
.tools-group[open] summary::after { transform: rotate(-180deg); }

.tools-body {
  padding: 0 18px 18px;
  border-top: 1px solid var(--card-border);
  padding-top: 16px;
}

.days-toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.day-toggle-label {
  font-size: 13px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.day-toggle-label input {
  width: 15px;
  height: 15px;
  cursor: pointer;
  margin: 0;
  accent-color: #A838FF;
}

.theme-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.theme-toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.theme-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.theme-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid var(--card-border);
  border-radius: 30px;
  transition: background 0.2s ease;
}
.theme-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  top: 2px;
  background: #FFF;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.theme-switch input:checked + .theme-slider {
  background: var(--primary-gradient);
}
.theme-switch input:checked + .theme-slider::before {
  transform: translateX(20px);
}

.tip-box {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid rgba(116, 179, 232, 0.25);
  background: rgba(116, 179, 232, 0.06);
  border-radius: 12px;
  padding: 14px 16px;
}
.tip-box p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.tip-box strong { color: #74B3E8; }
.tip-glyph { font-size: 15px; }

/* ---------------- AI COMING SOON TEASER ---------------- */
.ai-soon-box {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  border: 1.5px solid #A838FF;
  background: linear-gradient(135deg, rgba(168, 56, 255, 0.16), rgba(255, 75, 158, 0.12));
  border-radius: 12px;
  padding: 14px 16px;
  opacity: 1;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 0 0 1px rgba(168, 56, 255, 0.15), 0 4px 14px rgba(168, 56, 255, 0.2);
}
.ai-soon-icon {
  width: 40px; height: 40px;
  flex-shrink: 0;
  object-fit: contain;
  display: flex; align-items: center; justify-content: center;
  border-radius: 9px;
  background: rgba(168, 56, 255, 0.18);
  font-size: 14px;
}
.ai-soon-text { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.ai-soon-text strong { font-size: 13px; color: var(--ink); }
.ai-soon-text span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

button.ai-soon-box {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
button.ai-soon-box:hover { background: var(--soft-fill-hover); border-color: #FF4B9E; }
button.ai-soon-box:active { transform: scale(0.99); }

.ai-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 2, 10, 0.6);
  backdrop-filter: blur(3px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.ai-modal-overlay.show { display: flex; }

.ai-modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface2);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.ai-modal-card textarea,
.ai-modal-card input[type="text"] {
  width: 100%;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  padding: 10px 12px;
  resize: vertical;
}

.ai-hint { font-size: 11px; color: var(--muted); }

.ai-modal-note { font-size: 11px; color: var(--muted); margin-top: 10px; line-height: 1.5; }

.ai-modal-error {
  background: rgba(192, 57, 43, 0.12);
  border: 1px solid rgba(192, 57, 43, 0.4);
  color: #E67E68;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  margin-bottom: 12px;
}

.ai-modal-notice {
  background: rgba(116, 179, 232, 0.12);
  border: 1px solid rgba(116, 179, 232, 0.4);
  color: #74B3E8;
}

#aiGenerateBtn.loading { opacity: 0.7; pointer-events: none; }

/* ---------------- CONFIRM MODAL (replaces native window.confirm) ---------------- */

.confirm-modal-overlay {
  display: flex;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 2, 10, 0.6);
  backdrop-filter: blur(3px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.15s ease;
}
.confirm-modal-overlay.show { opacity: 1; pointer-events: auto; }

.confirm-modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface2);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  transform: scale(0.96) translateY(6px);
  transition: transform 0.15s ease;
}
.confirm-modal-overlay.show .confirm-modal-card { transform: scale(1) translateY(0); }

.confirm-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 8px;
}

.confirm-modal-message {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-line;
  margin: 0 0 20px;
}

.confirm-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-btn {
  padding: 9px 16px;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.confirm-btn:hover { opacity: 0.9; }
.confirm-btn:active { transform: scale(0.98); }

.confirm-btn-secondary {
  background: var(--soft-fill);
  color: var(--ink);
  border: 1px solid var(--card-border);
}
.confirm-btn-secondary:hover { background: var(--soft-fill-hover); }

.confirm-btn-primary {
  background: var(--primary-gradient);
  color: #fff;
}

.confirm-btn-danger {
  background: #C0392B;
  color: #fff;
}

/* ---------------- DEV CREDIT FOOTER ---------------- */
.dev-credit {
  margin-top: 14px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}
.dev-credit strong { color: var(--ink); font-weight: 600; }
.dev-credit a {
  color: #C9A6E8;
  text-decoration: none;
}
.dev-credit a:hover { text-decoration: underline; }

/* ---------------- MIDDLE: TIMETABLE ---------------- */
.timetable-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.board {
  width: 100%;
  background: var(--board);
  border-radius: 20px;
  border: 1px solid var(--card-border);
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 32px;
  position: relative;
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px) scale(0.99);
}

.board.loaded {
  animation: boardIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes boardIn {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  position: relative;
  z-index: 1;
}

.board-title-wrap { display: flex; align-items: center; gap: 10px; }
.board-icon { font-size: 18px; }

.board-title {
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--chalk);
  margin: 0;
  letter-spacing: -0.02em;
}

.board-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--chalk-dim);
}

.board-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.add-period-btn {
  padding: 7px 14px;
  border: 1px solid rgba(168, 56, 255, 0.35);
  border-radius: 20px;
  background: rgba(168, 56, 255, 0.12);
  color: #C9A6E8;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}
.add-period-btn:hover { background: rgba(168, 56, 255, 0.22); }
.add-period-btn:active { transform: scale(0.98); }

.grid-wrap {
  position: relative;
  z-index: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.routine-grid {
  width: auto;
  min-width: 640px;
  table-layout: auto;
  border-collapse: collapse;
}

.routine-grid th, .routine-grid td {
  border: 1px dashed var(--grid-line);
  padding: 12px 10px;
  vertical-align: top;
}

.routine-grid th {
  text-align: center;
  padding-top: 8px;
  padding-bottom: 8px;
  border-top: none;
}

.day-cell {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--chalk);
  white-space: nowrap;
  width: 85px;
  text-align: right;
  padding-right: 14px !important;
  border-left: none !important;
  vertical-align: middle !important;
}

.time-header {
  font-family: 'JetBrains Mono', monospace !important;
  font-size: 11px !important;
  color: var(--chalk-dim) !important;
  font-weight: 500 !important;
  white-space: nowrap;
  vertical-align: middle;
  width: 118px;
}

.time-header-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

.time-static { display: none; }

.time-edit-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}

.slot-time-input {
  border: 1px solid transparent;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--chalk-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  padding: 1px 3px;
  width: 60px;
  color-scheme: dark;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.slot-time-input::-webkit-calendar-picker-indicator {
  transform: scale(0.65);
  filter: opacity(0.8);
}
.slot-time-input:hover { background: rgba(255, 255, 255, 0.08); }
.slot-time-input:focus {
  outline: none;
  border-color: #A838FF;
  background: rgba(255, 255, 255, 0.1);
  color: var(--chalk);
}

.time-sep { display: none; color: var(--chalk-dim); font-size: 10px; }

.remove-slot-btn {
  background: none;
  border: none;
  color: var(--chalk-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s ease;
}
.remove-slot-btn:hover { color: #E8879C; }

.remove-day-btn {
  background: none;
  border: none;
  color: var(--chalk-dim);
  cursor: pointer;
  font-size: 16px;
  margin-left: 6px;
  transition: color 0.15s ease;
  padding: 0;
  line-height: 1;
  vertical-align: middle;
}
.remove-day-btn:hover { color: #E8879C; }

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

.class-chip {
  position: relative;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: #111;
  min-height: 50px;
  max-width: 240px;
  margin: 0 auto;
  cursor: grab;
  user-select: none;
  text-align: left;
  word-break: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.class-chip:active {
  cursor: grabbing;
  transform: scale(0.98);
}
.class-chip:hover {
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
}

.class-chip * { pointer-events: none; }
.class-chip .chip-actions, .class-chip .chip-btn { pointer-events: auto; }

.dropzone.drag-over {
  background: rgba(255, 255, 255, 0.05) !important;
  outline: 2px dashed #A838FF;
  outline-offset: -2px;
  border-radius: 8px;
}

.class-room {
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 11px;
  opacity: 0.75;
  margin-top: 4px;
}

.chip-actions {
  display: flex;
  gap: 5px;
  margin-top: 8px;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.class-chip:hover .chip-actions { opacity: 1; }

.chip-btn {
  border: none;
  background: rgba(0, 0, 0, 0.15);
  color: #111;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.chip-btn:hover { background: rgba(0, 0, 0, 0.25); }

.free-cell {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--faint-dot);
  text-align: center;
  padding-top: 18px !important;
  vertical-align: middle !important;
}

.empty-board {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  text-align: center;
  gap: 14px;
  position: relative;
  z-index: 1;
}
.empty-board .glyph {
  font-family: 'Inter', sans-serif;
  font-size: 40px;
  color: var(--faint-glyph);
}
.empty-board p {
  font-size: 14px;
  color: var(--chalk-dim);
  max-width: 260px;
  margin: 0;
  line-height: 1.5;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px dashed rgba(255,255,255,0.1);
  position: relative;
  z-index: 1;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--chalk-dim);
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.teacher-board-panel {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.teacher-board-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.teacher-board-head h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}
.teacher-board-panel .teacher-table th {
  position: static;
  background: none;
}

.summary-panel {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 20px 24px;
  backdrop-filter: blur(12px);
}

.summary-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--chalk-dim);
  margin: 0 0 14px;
}

.summary-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
}

.summary-item {
  font-size: 13px;
  color: var(--chalk);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.summary-item .sday {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  color: var(--muted);
}

.summary-total {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  font-size: 13px;
  color: var(--muted);
}

/* ---------------- RIGHT: TEACHER MANAGEMENT ---------------- */
.teacher-panel { min-width: 0; }

.teacher-card { display: flex; flex-direction: column; }

.teacher-head {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.panel-head-left { display: flex; align-items: center; gap: 12px; }
.panel-head-left h2 { font-size: 17px; font-weight: 700; margin: 0; }

.close-x {
  border: none;
  background: var(--soft-fill);
  color: var(--muted);
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.close-x:hover { background: var(--soft-fill-hover); color: var(--ink); }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 16px;
}
.tab-btn {
  flex: 1;
  padding: 10px 6px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease;
}
.tab-btn.active { color: #FF4B9E; border-bottom-color: #FF4B9E; }
.tab-btn:hover:not(.active) { color: var(--ink); }

.search-row {
  position: relative;
  margin-bottom: 14px;
}
.search-row input {
  padding-right: 36px;
}
.search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.5;
}

.teacher-list-wrap {
  max-height: 420px;
  overflow-y: auto;
}

.teacher-table {
  width: 100%;
  border-collapse: collapse;
}
.teacher-table th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  background: var(--surface2);
}
.teacher-table td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 13px;
  vertical-align: middle;
}

.teacher-row-name {
  display: flex;
  align-items: center;
  gap: 10px;
}
.teacher-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #111;
  flex-shrink: 0;
}

.subject-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: #111;
  white-space: nowrap;
}

.teacher-code-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.03em;
  color: var(--text-primary, #eee);
  background: var(--soft-fill, rgba(255,255,255,0.08));
  white-space: nowrap;
}

.row-actions { display: flex; gap: 6px; }
.row-action-btn {
  border: none;
  background: var(--soft-fill);
  width: 26px; height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s ease;
}
.row-action-btn:hover { background: var(--soft-fill-hover); }
.row-action-btn.delete:hover { background: rgba(255,123,114,0.25); }

.teacher-empty {
  display: none;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 30px 10px;
}
.teacher-empty.show { display: block; }

.tab-panel[hidden] { display: none; }

.teacher-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--card-border);
  font-size: 12px;
  color: var(--muted);
}
.teacher-footer .cancel-edit-btn { width: auto; padding: 9px 18px; }

/* ---------------- TOAST ---------------- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--surface2);
  color: var(--ink);
  padding: 14px 20px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.toast button {
  border: none;
  background: none;
  color: #FF4B9E;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

/* ---------------- PDF EXPORT SANDBOX ---------------- */
.pdf-export-root {
  position: fixed;
  left: -99999px;
  top: 0;
  min-width: 794px;
  background: var(--bg-dark);
  padding: 36px;
  font-family: 'Inter', sans-serif;
  color: var(--ink);
}
.pdf-export-root .grid-wrap { overflow: visible; display: inline-block; }
.pdf-export-root table.routine-grid { min-width: 0; }
.pdf-export-root .board { box-shadow: none; opacity: 1; transform: none; }
.pdf-export-root .chip-actions,
.pdf-export-root .remove-day-btn,
.pdf-export-root .add-period-btn,
.pdf-export-root .remove-slot-btn,
.pdf-export-root .time-edit-row { display: none !important; }
.pdf-export-root .time-static { display: inline !important; }

.pdf-teacher-block { margin-top: 30px; }
.pdf-teacher-block h3 {
  font-size: 18px;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pdf-teacher-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--board);
  border-radius: 14px;
  overflow: hidden;
}
.pdf-teacher-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--card-border);
}
.pdf-teacher-table td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px dashed rgba(255,255,255,0.08);
}

/* ================= RESPONSIVE ================= */

/* Small laptops / large tablets: drop to single column, tighten spacing */
@media (max-width: 1200px) {
  .app {
    grid-template-columns: 1fr;
  }
  .builder-panel, .timetable-panel { max-width: 720px; margin: 0 auto; width: 100%; }
}

/* Tablets */
@media (max-width: 900px) {
  .app { gap: 20px; padding: 24px 24px 50px; }
  .board { padding: 24px; }
  .panel-card { padding: 20px; }
  .teacher-list-wrap { max-height: 360px; }
}

/* Large phones / small tablets (portrait) */
@media (max-width: 720px) {
  .topbar { padding: 12px 16px; }
  .brand { gap: 10px; }
  .brand-icon { width: 32px; height: 32px; font-size: 15px; }
  .brand h1 { font-size: 15px; }
  .pdf-btn { padding: 9px 14px; font-size: 12px; border-radius: 18px; }
  .reset-btn { padding: 9px 12px; font-size: 12px; border-radius: 18px; }
  .topbar-actions { gap: 8px; }

  .app { padding: 18px 14px 44px; gap: 16px; }
  .builder-panel, .timetable-panel { max-width: none; }

  .board { padding: 18px 16px; border-radius: 16px; }
  .board-header {
    flex-wrap: wrap;
    row-gap: 12px;
    margin-bottom: 18px;
  }
  .board-header-right {
    width: 100%;
    justify-content: space-between;
  }
  .board-title { font-size: 17px; }
  .board-icon { font-size: 16px; }

  .panel-card { padding: 18px; border-radius: 14px; }
  .panel-head h2 { font-size: 16px; }

  .row2 { gap: 10px; }

  /* 16px prevents iOS Safari from auto-zooming on focus */
  input[type="text"], input[type="time"], select {
    font-size: 16px;
    padding: 11px 12px;
  }
  .input-with-dot input[type="text"] { padding-left: 32px; }

  .btn-stack { gap: 8px; }
  .add-btn, .break-btn, .cancel-edit-btn, .manage-btn, .util-btn {
    padding: 12px 14px;
    font-size: 13.5px;
  }

  .legend { gap: 10px 16px; margin-top: 18px; padding-top: 16px; }

  .teacher-table th, .teacher-table td { padding: 8px 6px; font-size: 12.5px; }
  .teacher-list-wrap { max-height: 300px; }

  .toast {
    left: 14px;
    right: 14px;
    bottom: 18px;
    transform: translateY(10px);
    width: auto;
    max-width: none;
    padding: 12px 16px;
  }
  .toast.show { transform: translateY(0); }

  .summary-panel, .teacher-board-panel { padding: 16px 18px; }
}

/* Phones */
@media (max-width: 480px) {
  .topbar { padding: 10px 14px; }
  .brand h1 { font-size: 14px; }
  .pdf-btn { padding: 8px 12px; font-size: 11px; }
  .reset-btn { padding: 8px 10px; font-size: 11px; }

  .app { padding: 14px 10px 40px; gap: 14px; }

  .board { padding: 14px 12px; }
  .board-title { font-size: 15.5px; }
  .board-sub { font-size: 11px; }
  .add-period-btn { padding: 6px 11px; font-size: 11.5px; }

  .panel-card { padding: 14px; }
  .theme-toggle-row { padding: 10px 14px; }

  .days-toggle-grid { grid-template-columns: 1fr; gap: 10px; }

  .class-chip { max-width: 100%; font-size: 12.5px; padding: 9px 10px; }

  .tab-btn { font-size: 12px; padding: 9px 4px; }

  .teacher-table th, .teacher-table td { padding: 7px 5px; font-size: 12px; }
  .teacher-avatar { width: 24px; height: 24px; font-size: 10px; }
  .row-action-btn { width: 24px; height: 24px; }

  .toast { flex-direction: column; align-items: flex-start; gap: 8px; }
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #A838FF;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}