:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-sidebar: #0a0e14;
  --border: #2d3a4a;
  --text: #e6edf3;
  --text-muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
  --font: 'Manrope', -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.hidden { display: none !important; }

.banner {
  padding: 0.6rem 1rem;
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}
.banner-warning {
  background: rgba(234, 179, 8, 0.15);
  border-bottom: 1px solid rgba(234, 179, 8, 0.4);
  color: #facc15;
}

/* Login */
#init-loading {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(145deg, #0a0e14 0%, #151d2b 50%, #0f1419 100%);
}
#init-loading.hidden { display: none !important; }

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(145deg, #0a0e14 0%, #151d2b 50%, #0f1419 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.login-title {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
}

.login-subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-form label {
  display: block;
  margin-bottom: 1rem;
}

.login-form label span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.login-form input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.login-form input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-call-timer {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  margin: 0.5rem 0;
  color: var(--text);
}

.error-msg {
  color: var(--danger);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  font: inherit;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 0.75rem;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary { background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); color: var(--text); }

.btn-danger { background: #8b2635; color: #fff; border: none; }
.btn-danger:hover { background: #a52d3f; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.05); }

/* App layout */
#app-screen {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}

.logo {
  font-weight: 700;
  font-size: 1.1rem;
}

.user-role {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-header-context {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.sidebar-header-context .context-line {
  display: block;
}

.sidebar-header-branch {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.sidebar-header-branch-label {
  display: block;
  margin-bottom: 0.2rem;
}

.sidebar-header-branch select {
  width: 100%;
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

.sidebar-header-exit-impersonate {
  margin-top: 0.5rem;
}

.sidebar-header-exit-impersonate .btn {
  width: 100%;
  justify-content: center;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  position: relative;
  z-index: 1;
  min-height: 0;
}

.nav-link {
  display: block;
  padding: 0.6rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link.active { color: var(--accent); background: rgba(59,130,246,0.1); }

.nav-admin,
.nav-client,
.nav-superadmin-only { display: none; }
.role-admin .nav-admin,
.role-org_main_admin .nav-admin,
.role-superadmin .nav-admin { display: block; }
.role-superadmin .nav-superadmin-only { display: block; }
/* Суперадмин без выбранной организации: скрыть разделы, требующие контекста организации */
.superadmin-no-org .nav-requires-org { display: none !important; }
.superadmin-no-org .nav-requires-org.nav-widget-for-superadmin { display: block !important; }
.superadmin-no-org .nav-requires-org.nav-settings-for-superadmin { display: block !important; }
/* Филиалы показываем только организациям с флагом «сеть» */
.nav-link[data-page="branches"] { display: none !important; }
.org-is-network .nav-link[data-page="branches"] { display: block !important; }
.role-client .nav-client { display: block; }
.role-trainer .nav-client { display: none; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.main-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.user-info {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.page-content {
  flex: 1;
  padding: 1.5rem;
  overflow-auto;
}

.content-section {
  width: 100%;
  max-width: none;
}

.content-section.hidden { display: none; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.card h3 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.card .muted { color: var(--text-muted); font-size: 0.9rem; }

.nav-inline { color: var(--accent); text-decoration: none; }
.nav-inline:hover { text-decoration: underline; }

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.form-row label { display: flex; align-items: center; gap: 0.5rem; }
.form-row label:has(textarea) { align-items: flex-start; flex-direction: column; }
.form-row input, .form-row select, .form-row textarea {
  padding: 0.5rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.form-row textarea { width: 100%; min-height: 80px; resize: vertical; }

/* Секреты: поле + кнопка «показать/скрыть» */
.password-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.password-input-wrap input { flex: 1; min-width: 12rem; }
.btn-password-toggle {
  flex-shrink: 0;
  padding: 0.4rem 0.5rem;
  font-size: 1.1rem;
  line-height: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.btn-password-toggle:hover { background: var(--border); color: var(--text); }
.btn-password-toggle:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-password-toggle .icon-eye-off { display: none; }
.btn-password-toggle.is-visible .icon-eye { display: none; }
.btn-password-toggle.is-visible .icon-eye-off { display: block; }

.media-display {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
/* Блок с фото: сверху превью, под ним подпись и метаданные */
.media-display-image {
  flex-direction: column;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.media-display-preview {
  width: 160px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
  background: var(--bg);
}
.media-display-preview[hidden],
.media-display-preview:not([src]) { display: none !important; }
.media-display-meta {
  width: 100%;
  margin-top: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
.form-inline label { display: flex; align-items: center; gap: 0.5rem; }
.form-inline input { min-width: 180px; }

.widget-booking-block { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.widget-booking-block h4 { margin: 0 0 0.35rem; font-size: 1rem; }
.widget-booking-block .widget-cors-hint-pre { margin: 0.5rem 0; }
.widget-promo-fieldset { margin: 1.25rem 0; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); }
.widget-promo-fieldset legend { padding: 0 0.5rem; color: var(--text-muted); font-size: 0.9rem; }
.label-inline { margin-right: 0.75rem; color: var(--text-muted); font-size: 0.9rem; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 0.35rem; margin-right: 1rem; font-size: 0.9rem; cursor: pointer; }
.checkbox-inline input { width: auto; }

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.token-created {
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: 6px;
}

.token-created code {
  display: block;
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: var(--bg);
  border-radius: 4px;
  font-size: 0.85rem;
  word-break: break-all;
}

.empty-msg { color: var(--text-muted); font-style: italic; }

/* Schedule: toolbar & view toggle */
.schedule-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.schedule-view-toggle .schedule-view-btn { margin-right: 0.25rem; }
.schedule-view-toggle .schedule-view-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.schedule-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.schedule-controls label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; }
.schedule-week-label { min-width: 140px; text-align: center; font-weight: 500; }

/* Schedule: week grid */
.schedule-week-wrap {
  overflow-x: auto;
  margin-top: 0.5rem;
}
.schedule-week-grid {
  display: grid;
  grid-template-columns: 52px repeat(7, minmax(100px, 1fr));
  grid-auto-rows: 28px;
  min-width: 700px;
  min-height: 400px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
}
.schedule-week-grid .grid-corner { grid-column: 1; grid-row: 1; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.schedule-week-grid .grid-time {
  padding: 2px 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  align-self: stretch;
}
.schedule-week-grid .grid-day {
  padding: 6px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.schedule-week-grid .grid-day:last-of-type { border-right: none; }
.schedule-week-grid .grid-cell {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  min-height: 28px;
  cursor: pointer;
  transition: background 0.15s;
}
.schedule-week-grid .grid-cell:hover { background: rgba(59, 130, 246, 0.12); }
.schedule-week-grid .grid-cell:last-of-type { border-right: none; }
.schedule-week-grid .schedule-slot-block {
  grid-column: span 1;
  margin: 2px 3px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.25;
  cursor: pointer;
  overflow: hidden;
  background: var(--accent);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  transition: opacity 0.15s;
  box-sizing: border-box;
  min-width: 0;
}
.schedule-week-grid .schedule-slot-block[style*="--schedule-max-lanes"] {
  width: calc((100% - (var(--schedule-max-lanes) - 1) * 3px) / var(--schedule-max-lanes));
  margin-left: calc(2px + var(--schedule-lane, 0) * ((100% - (var(--schedule-max-lanes) - 1) * 3px) / var(--schedule-max-lanes) + 3px));
}
.schedule-week-grid .schedule-slot-block:hover { opacity: 0.9; }
.schedule-week-grid .schedule-slot-block.slot-unavailable { background: var(--text-muted); }
.schedule-week-grid .schedule-slot-block .slot-service { font-weight: 600; }
.schedule-week-grid .schedule-slot-block .slot-trainer { font-size: 0.7rem; opacity: 0.9; }
.slot-form .form-row { margin-bottom: 0.75rem; }
.slot-form .form-row:last-of-type { margin-bottom: 0; }
.form-weekdays-label { margin-right: 0.5rem; color: var(--text-muted); }

/* Widget secrets list */
.widget-secrets-list { margin-bottom: 1rem; }
.widget-secret-row { margin-bottom: 0.75rem; }
.widget-secret-row .widget-secret-desc { min-width: 180px; }
.widget-secret-row .widget-secret-key { min-width: 200px; font-family: ui-monospace, monospace; }

/* Widget embed code */
.widget-embed-code {
  margin: 0;
  padding: 0.85rem 1rem;
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, monospace;
  font-size: 0.875rem;
  line-height: 1.4;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  overflow-x: auto;
  user-select: all;
}

.widget-embed-block {
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.widget-embed-block .widget-embed-code { flex: 1; min-width: 200px; }
.widget-embed-block .btn { flex-shrink: 0; }

/* Inline hint under embed code */
.hint-inline {
  margin-top: 0.75rem;
  margin-bottom: 0;
  font-size: 0.875rem;
}

/* CORS hint for widget */
.widget-cors-hint {
  border-left: 3px solid var(--accent);
}
.widget-cors-hint h3::before {
  content: "ℹ ";
  opacity: 0.9;
}
.widget-cors-hint .hint-list {
  margin: 0.75rem 0 0;
  padding-left: 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}
.widget-cors-hint .hint-list li { margin-bottom: 0.5rem; }
.widget-cors-hint .hint-list li:last-child { margin-bottom: 0; }
.widget-cors-hint code {
  font-family: ui-monospace, 'Cascadia Code', Menlo, monospace;
  font-size: 0.85em;
  padding: 0.15em 0.4em;
  background: var(--bg);
  border-radius: 4px;
  color: var(--accent);
}

/* Superadmin impersonation */
.widget-cors-hint-pre {
  margin: 0.5rem 0 0;
  padding: 0.85rem 1rem;
  font-family: ui-monospace, 'Cascadia Code', Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  overflow-x: auto;
  white-space: pre;
}

/* Блоки суперадмина: скрыты по умолчанию, видны только при .role-superadmin на app-screen */
.superadmin-only { display: none !important; }
.role-superadmin .superadmin-only { display: block !important; }
.superadmin-impersonate { margin-top: 1rem; border-left: 3px solid var(--accent); }
.superadmin-impersonate .org-list { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.superadmin-impersonate .org-list li { margin-bottom: 0.5rem; }
.superadmin-impersonate .org-list li:last-child { margin-bottom: 0; }

.widget-superadmin-org-list .org-list { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.widget-superadmin-org-list .org-list li { margin-bottom: 0.75rem; display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.widget-superadmin-org-list .org-list li:last-child { margin-bottom: 0; }
.widget-superadmin-org-list .org-list-name { font-weight: 500; }

/* Модальное окно «Посмотреть виджет» — виджет в рамке телефона */
.widget-phone-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.widget-phone-modal.hidden { display: none !important; }
.widget-phone-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  cursor: pointer;
}
.widget-phone-frame {
  position: relative;
  width: 320px;
  height: 640px;
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 2rem);
  background: #1a1a1a;
  border-radius: 36px;
  padding: 12px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5), 0 0 0 3px #2d2d2d, inset 0 0 0 2px rgba(255,255,255,0.05);
}
.widget-phone-notch {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 24px;
  background: #0a0a0a;
  border-radius: 0 0 16px 16px;
  z-index: 1;
}
.widget-phone-screen {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 24px;
  overflow: hidden;
  position: relative;
}
.widget-phone-screen iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}
.widget-phone-close {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.widget-phone-close:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.superadmin-create-org { margin-top: 1rem; }
.superadmin-create-org .form-row { margin-bottom: 0.75rem; }

/* ——— Mobile: sidebar toggle (hidden on desktop) ——— */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0 0.5rem 0 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.06); }
.sidebar-toggle-icon {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* ——— Mobile breakpoint ——— */
@media (max-width: 768px) {
  body.sidebar-open { overflow: hidden; }
  .sidebar-toggle { display: inline-flex; }

  .sidebar-overlay {
    display: block;
  }
  #app-screen.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 101;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }
  #app-screen.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
  }

  .main { min-width: 0; }
  .main-header {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }
  .main-header h2 { font-size: 1.1rem; }
  .user-info { font-size: 0.8rem; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .page-content { padding: 1rem; }

  .card { padding: 1rem; margin-bottom: 1rem; }
  .card h3 { font-size: 1rem; margin-bottom: 0.75rem; }

  /* Forms: stack vertically, full-width inputs */
  .form-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
  }
  .form-row label {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
  }
  .form-row label input,
  .form-row label select,
  .form-row label textarea { width: 100%; min-width: 0; }
  .form-row .btn { width: 100%; min-height: 44px; }
  .form-weekdays-label { margin-bottom: 0.25rem; }
  .form-row#slot-form-weekdays-row { flex-direction: row; flex-wrap: wrap; }
  .widget-promo-fieldset .form-row .checkbox-inline { display: flex; margin-bottom: 0.25rem; }

  /* Schedule toolbar: stack */
  .schedule-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .schedule-view-toggle { display: flex; gap: 0.25rem; }
  .schedule-view-toggle .schedule-view-btn { flex: 1; min-height: 40px; }
  .schedule-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .schedule-controls label { flex: 1 1 auto; min-width: 120px; }
  .schedule-week-label { min-width: 0; }
  .schedule-week-wrap { margin-top: 0.5rem; -webkit-overflow-scrolling: touch; }
  .schedule-week-grid {
    min-width: 600px;
    font-size: 0.7rem;
  }
  .schedule-week-grid .schedule-slot-block { padding: 3px 4px; font-size: 0.7rem; }
  .schedule-week-grid .grid-time { padding: 2px 4px; }

  /* Tables: keep horizontal scroll, larger touch targets */
  .table-wrap { -webkit-overflow-scrolling: touch; margin: 0 -0.5rem; padding: 0 0.5rem; }
  .table-wrap table { font-size: 0.85rem; }
  .table-wrap th,
  .table-wrap td { padding: 0.5rem 0.5rem; }
  .table-wrap .btn-sm { min-height: 36px; padding: 0.4rem 0.6rem; }

  .btn, .btn-primary, .btn-secondary { min-height: 44px; }
  .login-card { padding: 1.5rem; margin: 0 0.5rem; }
  .form-inline { flex-direction: column; align-items: stretch; }
  .form-inline label { width: 100%; min-width: 0; flex-direction: column; align-items: stretch; }
  .form-inline input { min-width: 0; width: 100%; }
  .form-inline .btn { width: 100%; }
}

/* Modal overlay */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding: 1rem;
}
.modal.hidden { display: none !important; }
.modal .modal-content { max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto; }

/* Crop modal — редактор фото при загрузке (z-index выше остальных модалок) */
.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}
.crop-modal.hidden { display: none !important; visibility: hidden !important; pointer-events: none !important; }
.crop-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}
.crop-modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}
.crop-modal-title {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}
.crop-modal-hint {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.crop-modal-meta {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.crop-modal-ratio-hint,
.crop-modal-size-hint { display: block; }
.crop-modal-src-size {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.crop-modal-body {
  flex: 1;
  min-height: 0;
  margin-bottom: 1rem;
}
.crop-container {
  width: 100%;
  max-width: 560px;
  height: 360px;
  margin: 0 auto;
  background: #111;
  overflow: hidden;
  position: relative;
}
.crop-container img {
  display: block;
  max-width: 100%;
  max-height: 100%;
}
/* Рамка кадрирования как в виджете (скругление 10px у блока «Об организации») */
.crop-container .cropper-crop-box {
  border-radius: 10px;
}
.crop-container .crop-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.crop-container.crop-ready .crop-loading { display: none; }
.crop-modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-shrink: 0;
}
@media (max-width: 600px) {
  .crop-container { height: 280px; }
}

/* Small phones */
@media (max-width: 480px) {
  .main-header h2 { font-size: 1rem; }
  .user-info { max-width: 40%; }
  .sidebar { width: 260px; max-width: 90vw; }
}
