.setup-page {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

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

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 6px 6px 2px;
}

.setup-card .table-wrap {
  border-radius: calc(var(--radius) - 4px);
}

.setup-table td .row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.icon-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn-sm:hover {
  background: var(--brand-50);
  color: var(--brand-700);
}

html[data-theme="dark"] .icon-btn-sm:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--brand-200);
}

.icon-btn-sm.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-bg);
}

.icon-btn-sm .icon {
  width: 16px;
  height: 16px;
}

.icon-btn-sm[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.setup-table tr.is-deleted td {
  opacity: 0.55;
}

.setup-table tr.is-deleted .t-main {
  text-decoration: line-through;
}

.pill-deleted {
  background: var(--danger-bg);
  color: var(--danger);
}

.pill-current {
  background: var(--gold-soft-bg);
  color: var(--gold-600);
  border: 1px solid rgba(200, 150, 62, 0.4);
}

html[data-theme="dark"] .pill-current {
  color: var(--gold-300);
}

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 2px;
  font-size: var(--fs-small);
  color: var(--muted);
}

.pager .pg-group {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.pager .pg-size {
  min-width: 120px;
}

.pager .pg-size .select-btn {
  min-height: 38px;
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.18s ease;
  margin: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(3, 26, 20, 0.25);
  transition: transform 0.18s ease;
}

.switch:checked {
  background: var(--brand-600);
  border-color: var(--brand-600);
}

.switch:checked::after {
  transform: translateX(20px);
}

html[dir="rtl"] .switch:checked::after {
  transform: translateX(-20px);
}

.modal.modal-wide {
  max-width: 640px;
}

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

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
}

.form-grid .field.full {
  grid-column: 1 / -1;
}

.field .select-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.field .select-row .dd {
  flex: 1;
  min-width: 0;
}

.field .select-row .icon-btn-sm {
  width: 44px;
  height: auto;
  min-height: 44px;
}

.field .switch-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 2px;
}

.setup-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 26px 14px;
  color: var(--muted);
  font-size: var(--fs-small);
}

.routine-grid-wrap {
  overflow-x: auto;
  border-radius: calc(var(--radius) - 4px);
}

.routine-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 5px;
  min-width: 720px;
}

.routine-grid th {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 4px;
  text-align: center;
  white-space: nowrap;
}

.routine-grid td {
  padding: 0;
  vertical-align: top;
}

.routine-grid .rg-period {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  padding-top: 14px;
  white-space: nowrap;
}

.rg-cell {
  display: block;
  width: 100%;
  min-height: 52px;
  border: 1px dashed var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 7px;
  text-align: start;
  font-size: 12.5px;
  line-height: 1.45;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.rg-cell:hover {
  border-color: var(--brand-400);
}

.rg-cell.filled {
  border-style: solid;
  border-color: var(--brand-200);
  background: var(--brand-50);
  color: var(--text);
}

html[data-theme="dark"] .rg-cell.filled {
  background: rgba(29, 132, 104, 0.14);
  border-color: rgba(110, 192, 166, 0.35);
}

.rg-cell .rg-subject {
  display: block;
  font-weight: 700;
  color: var(--brand-800);
}

html[data-theme="dark"] .rg-cell .rg-subject {
  color: var(--brand-200);
}

.rg-cell .rg-teacher {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
}

.rg-cell .rg-time {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font-num);
}

.rg-cell .rg-add {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  color: var(--muted);
}

.rg-cell .rg-add .icon {
  width: 18px;
  height: 18px;
}

.routine-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 2px 12px;
}

.print-head {
  display: none;
}

@media (max-width: 820px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .setup-table {
    font-size: 13px;
  }

  .setup-table th,
  .setup-table td {
    padding: 6px 8px;
  }

  .setup-actions .btn {
    flex: 1 1 auto;
  }

  .pager {
    justify-content: center;
    text-align: center;
  }

  .pager .pg-group {
    justify-content: center;
  }
}

@media print {
  .sidebar,
  .topbar,
  .mobile-nav,
  .drawer-backdrop,
  .filterbar,
  .setup-actions,
  .pager,
  .toast-wrap,
  .modal-backdrop,
  .install-popup,
  .kbd-tip,
  .row-actions,
  .routine-hint {
    display: none !important;
  }

  body {
    background: #ffffff;
  }

  .app-shell {
    display: block;
  }

  .main-col {
    margin: 0 !important;
    padding: 0 !important;
  }

  .content {
    padding: 0 !important;
  }

  .setup-card {
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .print-head {
    display: block;
    text-align: center;
    margin-bottom: 14px;
  }

  .print-head .ph-inst {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    color: #0b4f3e;
  }

  .print-head .ph-sub {
    font-size: 13px;
    color: #444444;
  }

  .print-head .ph-title {
    font-size: 16px;
    font-weight: 700;
    margin-top: 6px;
  }

  .data-table th,
  .data-table td {
    border: 1px solid #cccccc;
  }

  .data-table .col-p2,
  .data-table .col-p3 {
    display: table-cell !important;
  }

  .data-table .t-sub-mobile {
    display: none !important;
  }

  .routine-grid {
    border-spacing: 0;
  }

  .routine-grid th,
  .routine-grid td {
    border: 1px solid #cccccc;
    padding: 4px;
  }

  .rg-cell {
    border: none;
    background: transparent;
    min-height: 0;
  }

  .rg-cell .rg-add {
    display: none;
  }
}
