/* ============================================================
   УПРАВЛЕНКА — macOS HIG Portal Design System
   portal.css — глобальные стили, разделяемые всеми страницами
   ============================================================ */

/* === ПЕРЕМЕННЫЕ (macOS HIG палитра) === */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;

  /* Фоны */
  --bg:           #f5f5f7;
  --card-bg:      #ffffff;
  --sidebar-bg:   rgba(248,248,250,0.88);

  /* Акцент */
  --accent:       #007AFF;
  --accent-hover: #0066dd;
  --accent-light: rgba(0,122,255,0.10);

  /* Текст */
  --text-primary:   #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary:  #aeaeb2;

  /* Состояния */
  --danger:       #ff3b30;
  --danger-light: rgba(255,59,48,0.09);
  --success:      #34c759;
  --success-light:rgba(52,199,89,0.10);
  --warning:      #ff9500;
  --warning-light:rgba(255,149,0,0.10);

  /* Границы */
  --border:       rgba(0,0,0,0.08);
  --border-input: rgba(0,0,0,0.14);
  --sidebar-border: rgba(0,0,0,0.07);

  /* Скругления */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Тени */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);

  /* Переходы */
  --transition: 0.15s ease;

  /* Сайдбар */
  --sidebar-w:    240px;
  --sidebar-w-sm:  64px;
}

/* === СБРОС === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === LAYOUT === */
.portal-layout {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 100vh;
}

.portal-main {
  flex: 1;
  display: block;
  padding: 28px 40px;
  min-width: 0;
  box-sizing: border-box;
}

.page-container {
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Стили сайдбара — в app/static/css/sections/sidebar.css */

/* === ШАПКА СТРАНИЦЫ === */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === КАРТОЧКИ === */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: var(--shadow-md);
}

.card-body   { padding: 24px; }

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

.card-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* === ТАБЛИЦЫ === */
.table-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead tr {
  background: rgba(0,0,0,0.018);
  border-bottom: 1px solid var(--border);
}

.data-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.055em;
  white-space: nowrap;
}

.data-table td {
  padding: 13px 16px;
  font-size: 13.5px;
  color: var(--text-primary);
  border-bottom: 1px solid rgba(0,0,0,0.04);
  vertical-align: middle;
}

.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: rgba(0,122,255,0.03); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table .col-actions { width: 80px; text-align: center; white-space: nowrap; }
.data-table .col-right    { text-align: right; }
.data-table .col-center   { text-align: center; }

/* === КНОПКИ === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: var(--font);
  letter-spacing: -0.01em;
  line-height: 1;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 4px rgba(0,122,255,0.25);
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,122,255,0.35);
}

.btn-secondary {
  background: rgba(0,0,0,0.06);
  color: var(--text-primary);
}
.btn-secondary:hover { background: rgba(0,0,0,0.10); }

.btn-outline {
  background: white;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-outline:hover { background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.14); }

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid rgba(255,59,48,0.18);
}
.btn-danger:hover { background: rgba(255,59,48,0.14); }

.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: var(--radius-sm); }

/* Иконочные кнопки */
.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(0,0,0,0.05);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(0,0,0,0.09); color: var(--text-primary); }
.icon-btn.danger { background: var(--danger-light); color: var(--danger); }
.icon-btn.danger:hover { background: rgba(255,59,48,0.14); }

/* === ФОРМЫ === */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.form-control {
  padding: 9px 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: var(--font);
  background: white;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
  box-sizing: border-box;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}

.form-control::placeholder { color: var(--text-tertiary); }

textarea.form-control { resize: vertical; }

.form-hint {
  font-size: 11px;
  color: var(--text-tertiary);
}

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.col-span-2  { grid-column: 1 / -1; }

/* === МОДАЛЬНЫЕ ОКНА === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.28);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }

/* Для старого стиля show/hide через display:flex */
.modal-overlay[style*="flex"] { display: flex !important; }

.modal-card {
  position: relative;
  background: rgba(255,255,255,0.97);
  border-radius: var(--radius-xl);
  padding: 28px 32px;
  width: 600px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.16);
  animation: modalIn 0.22s cubic-bezier(0.34,1.4,0.64,1);
  border: 1px solid rgba(255,255,255,0.7);
}

/* Кнопка закрытия модалки — красный кружок в стиле macOS (15×15).
   Крестик появляется при hover (как в оригинале macOS). */
.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #ff5f57;
  border: 1px solid rgba(0,0,0,0.10);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  color: rgba(0,0,0,0.65);
  font-family: inherit;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  transition: filter 0.12s ease, transform 0.12s ease;
  z-index: 5;
}
.modal-close-btn:hover { filter: brightness(1.06); }
.modal-close-btn:active { transform: scale(0.92); }
.modal-close-btn svg {
  width: 10px;
  height: 10px;
  display: block;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.modal-close-btn:hover svg { opacity: 1; }

.modal-card-sm { width: 460px; }
.modal-card-lg { width: 680px; }
.modal-card-xl { width: 880px; }
.modal-card-xxl { width: 1200px; max-width: 95vw; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.93) translateY(14px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 22px;
  letter-spacing: -0.02em;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 22px;
}

.modal-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid rgba(255,59,48,0.18);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-top: 14px;
}

/* === БЕЙДЖИ === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-info { background: rgba(0,122,255,0.10); color: #0a3d8c; }
.badge-warn { background: rgba(255,149,0,0.14); color: #a16207; }
.badge-success { background: rgba(52,199,89,0.12); color: #248a3d; }
.badge-danger  { background: rgba(255,59,48,0.12); color: #b1271b; }
.badge-neutral { background: rgba(110,110,115,0.12); color: #6e6e73; }

/* === ПОИСК === */
.search-wrapper {
  position: relative;
  display: inline-block;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  padding: 9px 14px 9px 34px;
  border: 1px solid rgba(0,0,0,0.11);
  border-radius: 20px;
  font-size: 13.5px;
  background: white;
  color: var(--text-primary);
  outline: none;
  width: 260px;
  transition: all var(--transition);
  font-family: var(--font);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.10);
  width: 300px;
}

/* === ФИЛЬТР-ПИЛЮЛИ === */
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.filter-pill {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.filter-pill:hover:not(.active) {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.14);
}

/* === АЛЕРТЫ === */
.alert {
  padding: 11px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.5;
}
.alert-error   { background: var(--danger-light);  color: var(--danger);  border: 1px solid rgba(255,59,48,0.18); }
.alert-warning { background: var(--warning-light); color: #9a5c00;        border: 1px solid rgba(255,149,0,0.22); }
.alert-success { background: var(--success-light); color: #1a7040;        border: 1px solid rgba(52,199,89,0.22); }

/* === НАВИГАЦИЯ НАЗАД === */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  transition: color var(--transition);
}
.back-link:hover { color: var(--accent); }

/* === ПУСТОЕ СОСТОЯНИЕ === */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* === УНИВЕРСАЛЬНЫЙ ПЕРЕКЛЮЧАТЕЛЬ (slider) ===
   Использование:
     <label class="toggle-switch">
       <input type="checkbox" ...>
       <span class="toggle-switch-slider"></span>
       <span class="toggle-switch-text">Подпись</span>
     </label>
   Вариации цвета: добавить класс `toggle-switch--accent` (синий, по умолчанию)
                   или `toggle-switch--orange` (оранжевый, как «По документам»)
*/
.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.toggle-switch-slider {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    background: rgba(0,0,0,0.18);
    border-radius: 10px;
    flex-shrink: 0;
    transition: background 0.18s ease;
}
.toggle-switch-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    top: 2px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    transition: transform 0.18s ease;
}
.toggle-switch input:checked + .toggle-switch-slider::before { transform: translateX(14px); }
.toggle-switch-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: color 0.18s ease;
}
/* Цветовые варианты */
.toggle-switch--accent input:checked + .toggle-switch-slider { background: var(--accent); }
.toggle-switch--accent input:checked ~ .toggle-switch-text  { color: var(--accent); }
.toggle-switch--orange input:checked + .toggle-switch-slider { background: #ff9500; }
.toggle-switch--orange input:checked ~ .toggle-switch-text  { color: #ff9500; }
.toggle-switch--green  input:checked + .toggle-switch-slider { background: #34c759; }
.toggle-switch--green  input:checked ~ .toggle-switch-text  { color: #34c759; }
.toggle-switch input:disabled + .toggle-switch-slider { opacity: 0.4; cursor: not-allowed; }

/* Компактный размер для строк таблицы */
.toggle-switch--sm .toggle-switch-slider { width: 28px; height: 16px; }
.toggle-switch--sm .toggle-switch-slider::before { width: 12px; height: 12px; }
.toggle-switch--sm input:checked + .toggle-switch-slider::before { transform: translateX(12px); }


/* === УТИЛИТЫ === */
.text-accent     { color: var(--accent); }
.text-danger     { color: var(--danger); }
.text-success    { color: var(--success); }
.text-warning    { color: var(--warning); }
.text-secondary  { color: var(--text-secondary); }
.text-muted      { color: var(--text-tertiary); }
.text-mono       { font-family: 'SF Mono','JetBrains Mono','Fira Code',monospace; font-size: 0.9em; }
.text-right      { text-align: right; }
.text-center     { text-align: center; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.flex         { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center  { display: flex; align-items: center; }
.flex-end     { display: flex; justify-content: flex-end; }
.flex-wrap    { flex-wrap: wrap; }
.flex-1       { flex: 1; }
.gap-4  { gap: 4px; }
.gap-6  { gap: 6px; }
.gap-8  { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.gap-24 { gap: 24px; }

.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }

.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* ─── Toast (уведомление справа внизу, macOS-style glass) ───────────────── */
.toast-flash {
    position: fixed;
    bottom: 24px;
    right: 24px;
    min-width: 240px;
    max-width: 380px;
    padding: 12px 16px 12px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 8px 24px rgba(0, 0, 0, 0.10);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    z-index: 10000;
    opacity: 0;
    transform: translateY(16px);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}
.toast-flash.show {
    opacity: 1;
    transform: translateY(0);
}
.toast-flash::before {
    content: "";
    flex: 0 0 4px;
    align-self: stretch;
    border-radius: 4px;
    background: var(--text-secondary);
}
.toast-success::before { background: #34c759; }
.toast-error::before   { background: #ff3b30; }
.toast-info::before    { background: #007aff; }

/* Пагинатор для list-страниц (M6, 2026-05-13) */
.paginator {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
    flex-wrap: wrap;
}
.paginator-btn {
    background: #fff;
    border: 1px solid var(--border, rgba(0,0,0,0.1));
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    min-width: 36px;
    text-align: center;
    color: var(--text-primary);
    transition: background 0.12s ease;
    font-variant-numeric: tabular-nums;
}
.paginator-btn:hover:not(:disabled):not(.active) { background: #f5f5f7; }
.paginator-btn.active {
    background: var(--accent, #007AFF);
    border-color: var(--accent, #007AFF);
    color: #fff;
    cursor: default;
}
.paginator-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.paginator-ellipsis {
    padding: 0 4px;
    color: var(--text-tertiary, #888);
    font-size: 13px;
}
.paginator-info {
    margin-left: 12px;
    font-size: 12.5px;
    color: var(--text-secondary, #666);
    font-variant-numeric: tabular-nums;
}

/* === Кастомный DOM-скроллбар (см. fake-scrollbar.js) ===
   Используется когда нужно стабильное отображение на macOS (overlay scrollbar скрывается). */
.fake-sb-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}
.fake-sb-target {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.fake-sb-target::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}
.fake-sb-track {
    position: absolute;
    top: 4px;
    right: 2px;
    bottom: 4px;
    width: 12px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    z-index: 5;
    user-select: none;
}
.fake-sb-thumb {
    position: absolute;
    left: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.32);
    border-radius: 4px;
    min-height: 30px;
    cursor: grab;
    transition: background 0.15s ease;
}
.fake-sb-thumb:hover, .fake-sb-track.dragging .fake-sb-thumb { background: rgba(0, 0, 0, 0.5); }
.fake-sb-track.dragging .fake-sb-thumb { cursor: grabbing; }
