:root {
  --page: #f4f6f9;
  --surface: #fff;
  --surface-soft: #f8fafc;
  --border: #e8edf3;
  --text: #1e293b;
  --muted: #64748b;
  --purple: #7163ba;
  --purple-dark: #4b3f8a;
  --purple-soft: #f0edfa;
  --teal: #7163ba;
  --blue-soft: #eff6ff;
  --blue: #2563eb;
  --green: #15803d;
  --green-soft: #f0fdf4;
  --red: #be123c;
  --shadow: 0 2px 12px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 24px;
  background: var(--page);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
button, input, select { font: inherit; }
.app-shell { width: min(1440px, 100%); margin: 0 auto; padding-top: 84px; display: flex; flex-direction: column; gap: 18px; }
.topbar, .panel, .summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.topbar {
  position: fixed; z-index: 100; top: 14px; left: 50%; transform: translateX(-50%);
  width: min(calc(100% - 48px), 1440px); display: flex; justify-content: space-between;
  align-items: center; gap: 20px; padding: 16px 20px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.brand-mark {
  width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center;
  color: #fff; font-size: 18px; border-radius: 12px;
  background: linear-gradient(135deg, #8978df, var(--purple-dark));
}
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; color: var(--text); font-size: 20px; font-weight: 800; }
h2 { margin-bottom: 0; font-size: 16px; font-weight: 800; }
.actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.button {
  display: inline-flex; min-height: 38px; align-items: center; justify-content: center; gap: 7px;
  padding: 0 13px; border: 1px solid transparent; border-radius: 8px;
  cursor: pointer; font-size: 11px; font-weight: 700; transition: .2s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .65; cursor: progress; transform: none; }
.button.primary { color: #fff; background: linear-gradient(135deg, #8978df, var(--purple)); box-shadow: 0 4px 12px rgba(113, 99, 186, .16); }
.button.secondary { color: var(--purple-dark); background: #fff; border-color: #dcd7ef; }
.button.secondary:hover { background: var(--purple-soft); }
.intro-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 2px 4px; }
.intro-row h2 { margin: 0 0 5px; font-size: 17px; }
.intro-row p { max-width: 780px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.status-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 20px; background: #fff; color: var(--muted); white-space: nowrap; font-size: 10px; font-weight: 700; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22a06b; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.summary-card { position: relative; display: flex; flex-direction: column; gap: 9px; min-height: 98px; padding: 16px; overflow: hidden; }
.summary-card::after { position: absolute; top: -22px; right: -15px; width: 68px; height: 68px; content: ""; border-radius: 50%; background: var(--purple); opacity: .055; }
.summary-card span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.summary-card strong { color: var(--teal); font-size: 24px; line-height: 1; }
.summary-card > i { position: absolute; top: 16px; right: 16px; color: var(--purple); font-size: 16px; opacity: .7; }
.panel { padding: 18px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 14px; }
.section-heading .eyebrow { margin-bottom: 4px; }
.section-heading h2 { font-size: 14px; }
.subtle-note { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; }
.settings-filters { display: grid; grid-template-columns: minmax(180px, 1.3fr) repeat(5, minmax(135px, 1fr)) auto; align-items: end; gap: 10px; margin: 0 0 14px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-soft); }
.settings-filter { display: grid; gap: 5px; min-width: 0; color: var(--muted); font-size: 10px; font-weight: 700; }
.settings-filter input, .settings-filter select { width: 100%; min-width: 0; height: 36px; padding: 0 10px; border: 1px solid #dfe5ec; border-radius: 7px; background: #fff; color: var(--text); font-size: 11px; }
.settings-filter input:focus, .settings-filter select:focus { outline: 2px solid rgba(113, 99, 186, .15); border-color: var(--purple); }
.clear-filters { white-space: nowrap; }
.table-scroll { width: 100%; overflow-x: auto; }
.settings-table, .week-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.settings-table { min-width: 760px; }
.settings-table thead th, .week-table thead th {
  padding: 10px 12px; background: var(--surface-soft); color: var(--muted);
  text-align: left; font-size: 9px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
}
.settings-table thead th:first-child, .week-table thead th:first-child { border-radius: 8px 0 0 0; }
.settings-table thead th:last-child, .week-table thead th:last-child { border-radius: 0 8px 0 0; }
.settings-table tbody td { padding: 11px 12px; border-bottom: 1px solid #f0f3f7; color: var(--text); font-size: 11px; vertical-align: middle; }
.settings-table tbody tr:last-child td { border-bottom: 0; }
.settings-empty { padding: 22px !important; color: var(--muted) !important; text-align: center; }
.settings-table td:first-child { min-width: 180px; }
.settings-table td:first-child strong { display: block; font-size: 11px; }
.settings-table td small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; }
.setting-input { min-width: 112px; height: 34px; padding: 0 9px; border: 1px solid #dfe5ec; border-radius: 7px; background: #fff; color: var(--text); font-size: 11px; }
.setting-input:focus { outline: 2px solid rgba(113, 99, 186, .15); border-color: var(--purple); }
.room-input { width: 150px; }
.repeat-input { width: 70px; min-width: 70px; }
.rule-note { color: var(--muted); font-size: 10px; line-height: 1.45; }
.weekly-periods { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 180px; margin: 2px 4px 2px 0; padding: 5px 7px; border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--muted); font-size: 10px; }
.weekly-periods .repeat-input { width: 58px; min-width: 58px; }
.start-time { color: var(--purple-dark) !important; font-weight: 700; }
.results-panel { min-height: 240px; }
.results-heading { align-items: flex-end; }
.view-switch { display: inline-flex; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); }
.view-button { display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 0 11px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; font-weight: 700; }
.view-button.active { color: var(--purple-dark); background: #fff; box-shadow: 0 1px 4px rgba(15, 23, 42, .08); }
.assistant-message { margin: 0 0 14px; padding: 11px 13px; border: 1px solid #e7e4f2; border-radius: 8px; background: #fbfaff; color: #514987; font-size: 11px; line-height: 1.55; }
.calendar-list { display: flex; flex-direction: column; gap: 12px; }
.calendar-card { overflow: hidden; border: 1px solid var(--border); border-radius: 11px; background: #fff; }
.calendar-card-header { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #edf1f5; background: #fcfcfe; }
.entity-icon { width: 32px; height: 32px; display: grid; flex: 0 0 auto; place-items: center; border-radius: 9px; background: var(--purple-soft); color: var(--purple-dark); font-size: 12px; }
.calendar-card-header h3 { margin: 0 0 3px; color: var(--text); font-size: 12px; }
.calendar-card-header p { margin: 0; color: var(--muted); font-size: 10px; }
.lesson-count { margin-left: auto; padding: 5px 8px; border-radius: 6px; background: #f1f5f9; color: #475569; white-space: nowrap; font-size: 9px; font-weight: 700; }
.week-table { min-width: 500px; }
.week-table thead th { padding: 9px 11px; background: #f8fafc; }
.week-table tbody th { width: 88px; padding: 8px 11px; border-bottom: 1px solid #f0f3f7; background: #fcfdff; color: #64748b; text-align: left; font-size: 10px; font-weight: 700; }
.week-table tbody td { min-width: 120px; height: 48px; padding: 5px; border-bottom: 1px solid #f0f3f7; border-left: 1px solid #f4f6f9; vertical-align: middle; }
.week-table tbody tr:last-child th, .week-table tbody tr:last-child td { border-bottom: 0; }
.lesson-block { min-height: 36px; padding: 9px 10px; border: 1px solid #dbeafe; border-radius: 6px; background: var(--blue-soft); color: #1e40af; font-size: 10px; font-weight: 700; line-height: 1.45; }
.draggable-lesson { cursor: grab; }
.draggable-lesson:active { cursor: grabbing; }
.draggable-lesson.dragging-lesson { opacity: .45; }
.week-table td.drop-target { transition: background .15s, box-shadow .15s; }
.week-table td.drop-target.drop-hover { background: #f0edfa; box-shadow: inset 0 0 0 2px var(--purple); }
.lesson-block small { display: block; margin-top: 3px; color: #526783; font-size: 9px; font-weight: 500; }
.calendar-empty { margin: 0; padding: 16px; color: var(--muted); text-align: center; font-size: 10px; }
.calendar-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.calendar-actions .button { min-height: 30px; }
.calendar-card-header { padding: 14px 16px; }
.week-table thead th { padding: 11px 13px; }
.week-table tbody th { padding: 10px 13px; }
.week-table tbody td { padding: 8px; }
.edit-dialog { width: min(1100px, calc(100% - 24px)); max-height: 90vh; padding: 20px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); box-shadow: 0 18px 55px rgba(15, 23, 42, .25); }
.ai-dialog { width: min(760px, calc(100% - 24px)); }
.ai-dialog textarea { width: 100%; min-height: 110px; padding: 11px 12px; resize: vertical; border: 1px solid #dfe5ec; border-radius: 8px; color: var(--text); font: inherit; font-size: 12px; line-height: 1.5; }
.ai-dialog textarea:focus { outline: 2px solid rgba(113, 99, 186, .15); border-color: var(--purple); }
.ai-dialog textarea:disabled { background: var(--surface-soft); }
.ai-privacy-note { margin: 0; padding: 10px 12px; border: 1px solid #dbeafe; border-radius: 8px; background: #eff6ff; color: #1e40af; font-size: 10px; line-height: 1.5; }
.ai-instruction-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.ai-status { min-height: 18px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.ai-status.error { color: var(--red); }
.ai-status.success { color: var(--green); }
.ai-proposal { max-height: 34vh; overflow: auto; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-soft); color: var(--text); font-size: 11px; line-height: 1.5; }
.ai-proposal ul { display: grid; gap: 7px; margin: 9px 0 0; padding-left: 20px; }
.ai-proposal li { padding-left: 2px; }
.ai-proposal strong { color: var(--purple-dark); }
.dialog-actions .button:disabled { opacity: .5; cursor: not-allowed; }
.edit-dialog::backdrop { background: rgba(15, 23, 42, .5); }
.edit-dialog form { display: flex; flex-direction: column; gap: 14px; }
.edit-dialog .section-heading { margin: 0; }
.dialog-close { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--muted); cursor: pointer; font-size: 22px; }
.edit-table-scroll { overflow: auto; max-height: 62vh; }
.edit-table { min-width: 760px; }
.edit-table .setting-input { width: 100%; min-width: 90px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.break-row th { padding: 5px 10px; background: #f4f1fa; color: var(--purple-dark); text-align: center; font-size: 9px; letter-spacing: .04em; }
.calendar-actions .button { white-space: nowrap; }
.blank-cell { background: #fff; }
.empty-state { display: grid; min-height: 150px; place-items: center; align-content: center; gap: 8px; color: #94a3b8; text-align: center; }
.empty-state i { color: #a7a0cb; font-size: 25px; }
.empty-state p { max-width: 420px; margin: 0; font-size: 11px; line-height: 1.5; }
footer { padding: 2px 4px 8px; color: #8793a1; text-align: center; font-size: 9px; }

@media (max-width: 900px) {
  body { padding: 14px; }
  .app-shell { padding-top: 142px; }
  .topbar { top: 9px; width: calc(100% - 28px); align-items: flex-start; flex-direction: column; }
  .actions { justify-content: flex-start; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  body { padding: 9px; }
  .app-shell { gap: 11px; padding-top: 198px; }
  .topbar { width: calc(100% - 18px); padding: 12px; gap: 10px; }
  .topbar, .panel { padding: 14px; }
  .actions { display: grid; width: 100%; grid-template-columns: 1fr 1fr; }
  .button { padding: 0 8px; font-size: 10px; }
  .intro-row, .section-heading { align-items: flex-start; flex-direction: column; }
  .status-badge { white-space: normal; }
  .view-switch { width: 100%; }
  .view-button { flex: 1; justify-content: center; padding: 0 6px; }
  .settings-filters { grid-template-columns: 1fr; }
  .clear-filters { width: 100%; }
}
