/* ==========================================================================
   Thời Khóa Biểu & Lịch Báo Giảng Tuần - TCT.VN Stylesheet
   ========================================================================== */

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --border-light: #e2e8f0;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-light);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

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

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #475569;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  transition: all 0.2s;
  border: 1px solid var(--border-light);
}

.btn-back:hover {
  background: #e2e8f0;
  color: var(--primary-color);
}

.header-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: white;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.header-icon svg {
  width: 22px;
  height: 22px;
}

.app-header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

/* Buttons */
button {
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 6px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: white;
  color: #334155;
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
}

.btn-backup {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #0284c7;
  color: white;
  border: none;
  padding: 8px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(2, 132, 199, 0.2);
}

.btn-backup:hover {
  background: #0369a1;
  box-shadow: 0 4px 6px rgba(2, 132, 199, 0.3);
}

.btn-restore {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #475569;
  color: white;
  border: none;
  padding: 8px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(71, 85, 105, 0.2);
}

.btn-restore:hover {
  background: #334155;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: #1e293b;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  z-index: 9999;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.btn-outline-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: white;
  color: #ef4444;
  border: 1px solid #fecaca;
  padding: 6px 12px;
  font-size: 0.825rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.btn-outline-danger:hover {
  background: #fef2f2;
  border-color: #ef4444;
}

/* Main Container */
.main-container {
  max-width: 1380px;
  margin: 18px auto 8px;
  padding: 0 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
}

.card-title svg {
  color: var(--primary-color);
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.825rem;
  font-weight: 600;
  color: #475569;
}

.form-control {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 0.875rem;
  color: #0f172a;
  background-color: #ffffff;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Schedule Action Bar */
.schedule-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 10px 16px;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
  gap: 12px;
}

.stats-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: #475569;
}

.stats-badge strong {
  color: var(--primary-color);
  font-weight: 700;
}

.stats-badge .dot {
  color: #cbd5e1;
}

/* Quick Tips */
.quick-tips {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.825rem;
  color: #0284c7;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
}

.quick-tips svg {
  flex-shrink: 0;
}

/* Preview & Paper (A4 Landscape Print Sheet) */
.preview-wrapper {
  max-width: 1380px;
  margin: 12px auto 40px;
  padding: 0 20px;
}

.print-paper {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  box-shadow: var(--shadow-md);
  border-radius: 4px;
  padding: 24px 28px;
  min-height: 600px;
  margin: 0 auto;
  box-sizing: border-box;
}

/* Paper Header */
.paper-header {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid #0f172a;
  margin-bottom: 14px;
}

.paper-school-box {
  text-align: left;
}

.paper-school {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #0f172a;
}

.paper-subject {
  font-size: 0.825rem;
  color: #334155;
  margin-top: 3px;
}

.paper-title-box {
  text-align: center;
}

.paper-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.paper-sub-info {
  font-size: 0.825rem;
  color: #475569;
  font-weight: 500;
}

.paper-sub-info .divider {
  margin: 0 6px;
  color: #cbd5e1;
}

.paper-teacher-box {
  text-align: right;
}

.paper-teacher {
  font-size: 0.9rem;
  color: #0f172a;
}

.paper-stamp {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 2px;
  font-style: italic;
}

/* Schedule Table */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
  table-layout: fixed;
}

.schedule-table th,
.schedule-table td {
  border: 1px solid #94a3b8;
  padding: 6px 8px;
  text-align: center;
  vertical-align: middle;
}

.schedule-table th {
  background-color: #f1f5f9;
  color: #0f172a;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 6px;
}

.session-header-cell {
  background-color: #f8fafc;
  font-weight: 800;
  color: #1e293b;
  letter-spacing: 0.5px;
}

.period-cell {
  font-weight: 700;
  background-color: #fdfefe;
  color: #334155;
}

/* Schedule Lesson Slot Cell */
.slot-cell {
  background: #ffffff;
  height: 52px;
  padding: 4px;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  position: relative;
}

.slot-cell:hover {
  background-color: #f0f7ff;
}

.slot-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  height: 100%;
  border-radius: 4px;
  padding: 2px;
}

/* Slot Card styling */
.slot-filled {
  border-left: 3px solid #2563eb;
  padding-left: 4px;
  background: #f8fafc;
}

.slot-class {
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.1;
  color: #0f172a;
}

.slot-meta {
  font-size: 0.725rem;
  color: #475569;
  line-height: 1.1;
  display: flex;
  gap: 4px;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.slot-lesson-title {
  font-size: 0.7rem;
  color: #64748b;
  line-height: 1.1;
  font-style: italic;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-empty-hint {
  font-size: 0.75rem;
  color: #cbd5e1;
  font-style: italic;
  opacity: 0;
  transition: opacity 0.15s;
}

.slot-cell:hover .slot-empty-hint {
  opacity: 0.7;
}

/* Color theme chips for slots */
.color-blue .slot-class { color: #1d4ed8; }
.color-blue.slot-filled { border-left-color: #2563eb; background: #eff6ff; }

.color-emerald .slot-class { color: #047857; }
.color-emerald.slot-filled { border-left-color: #059669; background: #ecfdf5; }

.color-amber .slot-class { color: #b45309; }
.color-amber.slot-filled { border-left-color: #d97706; background: #fffbeb; }

.color-purple .slot-class { color: #6d28d9; }
.color-purple.slot-filled { border-left-color: #7c3aed; background: #f5f3ff; }

.color-rose .slot-class { color: #be123c; }
.color-rose.slot-filled { border-left-color: #e11d48; background: #fff1f2; }

.color-slate .slot-class { color: #334155; }
.color-slate.slot-filled { border-left-color: #64748b; background: #f1f5f9; }

/* Báo giảng section */
.baogiang-container {
  margin-top: 20px;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #0f172a;
  margin-bottom: 8px;
  text-align: left;
}

.baogiang-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.baogiang-table th,
.baogiang-table td {
  border: 1px solid #94a3b8;
  padding: 6px 8px;
  vertical-align: middle;
}

.baogiang-table th {
  background-color: #f1f5f9;
  font-weight: 700;
  color: #0f172a;
  text-align: center;
}

.baogiang-table td.text-center {
  text-align: center;
}

/* Paper Footer */
.paper-footer {
  margin-top: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  text-align: center;
  font-size: 0.825rem;
  break-inside: avoid;
}

.footer-sign-col {
  padding: 0 10px;
}

.sign-title {
  font-weight: 700;
  color: #0f172a;
  text-transform: uppercase;
}

.sign-sub {
  font-size: 0.75rem;
  font-style: italic;
  color: #64748b;
  margin-top: 2px;
}

.sign-space {
  height: 55px;
}

.sign-name {
  font-weight: 700;
  color: #0f172a;
}

.sign-date {
  font-style: italic;
  color: #334155;
  margin-bottom: 4px;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal-dialog {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  overflow: hidden;
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #94a3b8;
  cursor: pointer;
}

.modal-close:hover {
  color: #0f172a;
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-col label,
.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.req {
  color: #ef4444;
}

.color-picker-chips {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.chip-color {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}

.chip-color:hover {
  transform: scale(1.15);
}

.chip-color.active {
  border-color: #0f172a;
  transform: scale(1.15);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.chip-color.color-blue { background: #3b82f6; }
.chip-color.color-emerald { background: #10b981; }
.chip-color.color-amber { background: #f59e0b; }
.chip-color.color-purple { background: #8b5cf6; }
.chip-color.color-rose { background: #f43f5e; }
.chip-color.color-slate { background: #64748b; }

.modal-footer {
  padding: 12px 20px;
  background: #f8fafc;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Loading Overlay */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: white;
}

.loading-overlay.open {
  display: flex;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.95rem;
  font-weight: 600;
}

/* Print CSS */
@media print {
  @page {
    size: A4 landscape;
    margin: 10mm 10mm 10mm 10mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
  }

  .no-print {
    display: none !important;
  }

  .preview-wrapper {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
  }

  .print-paper {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    width: 100% !important;
  }

  .schedule-table th,
  .schedule-table td,
  .baogiang-table th,
  .baogiang-table td {
    border: 1px solid #000000 !important;
    color: #000000 !important;
  }

  .schedule-table th,
  .baogiang-table th,
  .session-header-cell {
    background-color: #f1f5f9 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .slot-cell {
    height: 46px !important;
  }

  .slot-empty-hint {
    display: none !important;
  }

  .slot-filled {
    border-left: 2px solid #000000 !important;
    background: #ffffff !important;
  }

  .slot-class {
    color: #000000 !important;
  }

  .paper-header {
    border-bottom: 2px solid #000000 !important;
  }

  .paper-title {
    color: #000000 !important;
  }
}
