:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e2e6ef;
  --text: #1b2233;
  --muted: #667089;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #eef0ff;
  --success: #0f9d58;
  --success-soft: #e7f6ee;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #b45309;
  --warning-soft: #fff6e5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.hidden { display: none !important; }
.mt-12 { margin-top: 12px; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand-area { display: flex; gap: 12px; align-items: center; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 11px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
}
.brand-title-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.brand-title { margin: 0; font-size: 17px; font-weight: 700; }
.brand-subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.badge {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
}
.badge-edge { background: #fff4e6; color: #c2410c; }
.badge-ai { background: var(--primary-soft); color: var(--primary); }
.badge-ai.live { background: var(--success-soft); color: var(--success); }

.header-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.doc-selector-wrap, .export-buttons { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ---------- Controls ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 12px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(79, 70, 229, 0.4); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-secondary:hover { background: #e2e5ff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-block { width: 100%; padding: 11px; }
.btn-icon {
  border: none; background: transparent; cursor: pointer; color: var(--muted);
  padding: 4px 6px; border-radius: 6px; font-size: 13px;
}
.btn-icon:hover { background: var(--danger-soft); color: var(--danger); }
.btn-link {
  border: none; background: none; color: var(--primary); cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; padding: 0;
}
.btn-close {
  border: none; background: var(--surface-2); width: 30px; height: 30px;
  border-radius: 8px; cursor: pointer; font-size: 14px;
}

.input-control, .select-control {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-control:focus, .select-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.select-control { width: auto; min-width: 220px; }
.select-sm { min-width: 140px; padding: 5px 8px; font-size: 12px; }
.mono-textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--muted); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.label-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.form-help { color: var(--muted); font-size: 11px; }

/* ---------- Stats ribbon ---------- */
.stats-ribbon {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 20px;
}
.stats-cards { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-pill {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 12px; display: flex; flex-direction: column; min-width: 110px;
}
.stat-label { font-size: 11px; color: var(--muted); }
.stat-value { font-size: 16px; }
.validation-banner {
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 13px;
}
.validation-banner.valid { background: var(--success-soft); color: var(--success); }
.validation-banner.invalid { background: var(--danger-soft); color: var(--danger); }
.validation-banner.warn { background: var(--warning-soft); color: var(--warning); }

/* ---------- Workspace ---------- */
.workspace-grid {
  display: grid;
  grid-template-columns: minmax(420px, 560px) 1fr;
  gap: 16px;
  padding: 0 20px 24px;
  align-items: start;
}
@media (max-width: 1100px) {
  .workspace-grid { grid-template-columns: 1fr; }
}

.editor-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
}
@media (max-width: 1100px) {
  .editor-sidebar { position: static; max-height: none; }
}

.tabs-nav {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.tab-btn {
  border: none; background: transparent; padding: 11px 6px; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: #fff; }

.tab-panel { display: none; padding: 14px; overflow-y: auto; }
.tab-panel.active { display: block; }
.tab-panel h2 { font-size: 15px; margin: 0 0 4px; }
.tab-panel h3 { font-size: 13px; margin: 0 0 8px; }
.panel-desc { color: var(--muted); font-size: 12px; margin: 0 0 12px; line-height: 1.45; }
.panel-card { }
.panel-header-row { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.day-add-controls { display: flex; gap: 6px; }
.action-row { margin-top: 6px; }

/* ---------- Day builder ---------- */
.days-builder-list { display: flex; flex-direction: column; gap: 10px; }
.day-card {
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.day-card-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.day-card-title { font-weight: 700; font-size: 13px; letter-spacing: 0.04em; color: var(--primary); }
.day-card-actions { display: flex; gap: 4px; }
.lesson-rows { padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.lesson-row {
  display: grid;
  grid-template-columns: 62px 1fr 120px 76px 28px 28px;
  gap: 4px;
  align-items: center;
}
.lesson-row input {
  width: 100%; border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 6px; font: inherit; font-size: 12px; background: #fff;
}
.lesson-row input:focus { outline: none; border-color: var(--primary); }
.lesson-row.is-break input { background: #f1f2f6; color: var(--muted); font-style: italic; }
.lesson-row.has-conflict input { border-color: var(--danger); background: #fff7f7; }
.lesson-row-head {
  display: grid; grid-template-columns: 62px 1fr 120px 76px 28px 28px; gap: 4px;
  padding: 0 6px; font-size: 10px; color: var(--muted); text-transform: uppercase; font-weight: 600;
}

/* ---------- Upload ---------- */
.upload-dropzone {
  position: relative;
  border: 2px dashed #c7cbe0;
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  margin-bottom: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.upload-dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.file-input-hidden { display: none; }
.dropzone-icon { font-size: 28px; }
.dropzone-title { font-weight: 600; margin-top: 4px; }
.dropzone-hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.image-preview-box { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.image-preview-box img { max-width: 100%; max-height: 220px; border-radius: 8px; border: 1px solid var(--border); }

.status-box {
  margin-top: 12px; padding: 10px 12px; border-radius: 9px; font-size: 12px; line-height: 1.5;
  background: var(--primary-soft); color: #312e81;
}
.status-box.success { background: var(--success-soft); color: #065f46; }
.status-box.error { background: var(--danger-soft); color: #991b1b; }
.status-box.loading::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.quick-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip-btn {
  border: 1px solid var(--border); background: #fff; border-radius: 999px;
  padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }

.issues-list { display: flex; flex-direction: column; gap: 6px; }
.issue-item { padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4; }
.issue-item.error { background: var(--danger-soft); color: #991b1b; }
.issue-item.warning { background: var(--warning-soft); color: #92400e; }
.issue-item.info { background: var(--primary-soft); color: #3730a3; }
.issue-item.ok { background: var(--success-soft); color: #065f46; }

/* ---------- Preview A4 ---------- */
.preview-stage { min-width: 0; }
.preview-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.preview-toolbar-left { display: flex; flex-direction: column; gap: 2px; }
.preview-badge { font-weight: 700; font-size: 13px; }
.preview-hint { color: var(--muted); font-size: 12px; }

.a4-paper-wrapper {
  overflow: auto;
  padding: 18px;
  background: #e6e9f2;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.a4-paper {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: #fff;
  color: #000;
  padding: 12mm 14mm 12mm 18mm;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
  font-family: "Times New Roman", Times, Georgia, serif;
  font-size: 12pt;
  line-height: 1.25;
}

.college-a4-sheet { width: 100%; }
.a4-approval-block { text-align: right; margin-bottom: 10pt; font-size: 11pt; line-height: 1.35; }
.approval-quote { padding-right: 28pt; }
.a4-title-block { text-align: center; margin-bottom: 10pt; }
.doc-main-title { font-size: 14pt; font-weight: bold; letter-spacing: 0.02em; text-transform: uppercase; }
.doc-institution { font-size: 12.5pt; font-weight: bold; margin-top: 2pt; }
.doc-period { font-size: 12pt; margin-top: 2pt; }
.doc-group { font-size: 12.5pt; font-weight: bold; margin-top: 6pt; }

.college-schedule-table {
  width: 100%; border-collapse: collapse; border: 1.5pt solid #000; font-size: 11pt;
}
.college-schedule-table th, .college-schedule-table td {
  border: 0.75pt solid #000; padding: 4pt 6pt; vertical-align: middle;
}
.college-schedule-table thead th {
  background: #e4e4e4; font-weight: bold; text-align: center; font-size: 10.5pt; padding: 6pt 4pt;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.th-day { width: 8%; } .th-time { width: 9%; } .th-discipline { width: 49%; }
.th-teacher { width: 20%; } .th-room { width: 14%; }
.col-day { text-align: center; font-weight: bold; padding: 4pt 2pt; }
.vertical-day-text {
  writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap;
  display: inline-block; font-weight: bold; letter-spacing: 0.06em; font-size: 10.5pt;
}
.col-time { text-align: center; white-space: nowrap; }
.col-discipline { text-align: left; }
.col-teacher, .col-room { text-align: center; }
.day-end-row td, .day-end-cell { border-bottom: 1.4pt solid #000 !important; }
.break-row td { font-style: italic; }

.a4-footer-block {
  margin-top: 16pt; display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11.5pt; padding: 0 4pt;
}
.footer-sig { margin-left: 28pt; }
.footer-right { padding-right: 48pt; }

.a4-editable, .a4-editable-cell { border-radius: 2px; transition: background 0.1s; }
.a4-editable:hover, .a4-editable-cell:hover { background: rgba(79, 70, 229, 0.08); cursor: text; }
.a4-editable:focus, .a4-editable-cell:focus {
  outline: 2px solid rgba(79, 70, 229, 0.5); background: rgba(79, 70, 229, 0.06);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 100;
  display: grid; place-items: center; padding: 16px;
}
.modal-card {
  width: min(560px, 100%); background: #fff; border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); overflow: hidden;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px 18px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px;
  border-top: 1px solid var(--border); background: var(--surface-2);
}
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: #111827; color: #fff; padding: 10px 14px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: toastIn 0.2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Print: only the A4 sheet ---------- */
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; }
  .no-print { display: none !important; }
  .workspace-grid { display: block; padding: 0; }
  .preview-stage { display: block; }
  .a4-paper-wrapper { padding: 0; background: none; border: none; overflow: visible; }
  .a4-paper { box-shadow: none; margin: 0; width: 210mm; min-height: auto; }
  .a4-editable:hover, .a4-editable-cell:hover { background: none; }
}
