/* =========================================================
   CRM v2 — стили с поддержкой тёмной темы
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;600;700;800&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-grad:   linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-bg:   #ffffff;
  --soft-bg:   #f7f8fc;
  --text:      #1f2240;
  --text-muted:#6b6f8c;
  --border:    #e7e9f2;
  --accent:    #667eea;
  --accent-2:  #764ba2;
  --success:   #16a34a;
  --danger:    #dc2626;
  --warn:      #f59e0b;
  --row-hover: #faf9ff;

  --radius:    24px;
  --radius-sm: 14px;
  --shadow-lg: 0 20px 60px rgba(31, 34, 64, 0.18);
  --shadow-md: 0 8px 24px rgba(31, 34, 64, 0.08);
  --shadow-sm: 0 2px 8px rgba(31, 34, 64, 0.06);
  --font: 'Manrope', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body.theme-dark {
  --bg-grad:   linear-gradient(135deg, #1f1d3b 0%, #2b1d4a 100%);
  --card-bg:   #232542;
  --soft-bg:   #1c1e38;
  --text:      #e9ecff;
  --text-muted:#9aa0c9;
  --border:    #353858;
  --row-hover: #2a2d4d;
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
}

html, body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s;
}

/* ---------- Контейнер ---------- */
.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---------- Шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  color: #fff;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 48px; height: 48px;
  border-radius: 14px;
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(12px);
  display: grid; place-items: center;
  font-size: 24px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
.brand h1 {
  font-size: 26px; font-weight: 800; letter-spacing: -0.02em;
}
.brand p { font-size: 13px; opacity: 0.85; }

.top-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.badge-pill {
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(12px);
  font-weight: 600;
  font-size: 13px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
  color: #fff;
}
.icon-toggle {
  width: 42px; height: 42px;
  border-radius: 12px;
  border: none;
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(12px);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  transition: transform 0.15s, background 0.2s;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
.icon-toggle:hover { background: rgba(255,255,255,0.28); transform: translateY(-2px); }

/* ---------- Вкладки ---------- */
.tabs {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: rgba(255,255,255,0.16);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  margin-bottom: 24px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
  flex-wrap: wrap;
}
.tab {
  flex: 1;
  min-width: 140px;
  padding: 12px 20px;
  border-radius: 14px;
  border: none;
  background: transparent;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.25s ease;
  font-family: inherit;
}
.tab:hover { background: rgba(255,255,255,0.12); }
.tab.active {
  background: #fff;
  color: var(--accent-2);
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}
body.theme-dark .tab.active { background: var(--card-bg); color: var(--text); }

/* ---------- Карточки ---------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  transition: background 0.3s;
}
.card + .card { margin-top: 20px; }
.card h2 {
  font-size: 18px; margin-bottom: 18px; letter-spacing: -0.01em;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.card h3 {
  font-size: 14px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 12px; font-weight: 700;
}

/* ---------- Сетка верхней зоны ---------- */
.top-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
@media (max-width: 900px) {
  .top-grid { grid-template-columns: 1fr; }
}

/* ---------- Формы ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
}

label.field {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--soft-bg);
  outline: none;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  width: 100%;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: var(--card-bg);
  box-shadow: 0 0 0 4px rgba(102,126,234,0.18);
}

.btn {
  display: inline-flex;
  align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px;
  border-radius: 12px;
  border: none;
  background: var(--bg-grad);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: var(--shadow-md);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(102,126,234,0.35); }
.btn:active { transform: translateY(0); }
.btn.ghost {
  background: transparent; color: var(--text);
  border: 1.5px solid var(--border); box-shadow: none;
}
.btn.ghost:hover { background: var(--soft-bg); transform: none; box-shadow: none; }
.btn.danger  { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.btn.success { background: linear-gradient(135deg, #10b981, #059669); }
.btn.sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn.xs { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

/* ---------- Отчёт ---------- */
.report .amount {
  font-size: 44px; font-weight: 800;
  background: var(--bg-grad);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  letter-spacing: -0.03em; line-height: 1.1;
  margin: 8px 0 4px;
}
.report .sub { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.report-filters {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
@media (max-width: 560px) { .report-filters { grid-template-columns: 1fr; } }

/* ---------- Фильтры ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}
.filters .field { min-width: 160px; flex: 1; }

/* ---------- Таблица ---------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 720px;
}
table.data thead th {
  background: var(--soft-bg);
  text-align: left;
  padding: 12px 8px;
  font-weight: 700;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  user-select: none;
  white-space: nowrap;
}
table.data thead th.sortable { cursor: pointer; transition: color 0.15s; }
table.data thead th.sortable:hover { color: var(--accent); }
table.data thead th.sorted-asc::after  { content: ' ↑'; color: var(--accent); }
table.data thead th.sorted-desc::after { content: ' ↓'; color: var(--accent); }
table.data tbody td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  vertical-align: middle;
  max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--row-hover); }
table.data tbody tr.selected td { background: rgba(102,126,234,0.12); }
table.data td.no-edit { cursor: default; }
table.data td .empty { color: #c3c6d8; font-style: italic; }
body.theme-dark table.data td .empty { color: #5a5e82; }

/* Подсветка дедлайнов */
tr.deadline-soon    td { background: rgba(245, 158, 11, 0.08) !important; }
tr.deadline-overdue td { background: rgba(220, 38, 38, 0.10) !important; }
tr.deadline-soon    td:first-child { border-left: 4px solid var(--warn); }
tr.deadline-overdue td:first-child { border-left: 4px solid var(--danger); }

/* ---------- Inline-редактирование ---------- */
td.editing {
  padding: 4px !important;
  background: var(--card-bg) !important;
}
td.editing input, td.editing select {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  border-radius: 8px;
}

/* ---------- Статусы ---------- */
.status {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.status:hover { transform: scale(1.05); box-shadow: var(--shadow-sm); }
.status.new        { background: #e0e7ff; color: #4338ca; }
.status.processing { background: #fef3c7; color: #b45309; }
.status.paid       { background: #dcfce7; color: #15803d; }
.status.unpaid     { background: #ffe4e6; color: #be123c; }
.status.done       { background: #e0f2fe; color: #0369a1; }
body.theme-dark .status.new        { background: rgba(67,56,202,0.25);   color: #a5b4fc; }
body.theme-dark .status.processing { background: rgba(180,83,9,0.25);    color: #fcd34d; }
body.theme-dark .status.paid       { background: rgba(21,128,61,0.25);   color: #86efac; }
body.theme-dark .status.unpaid     { background: rgba(190,18,60,0.25);   color: #fda4af; }
body.theme-dark .status.done       { background: rgba(3,105,161,0.25);   color: #7dd3fc; }

/* ---------- Иконки в таблице ---------- */
.icon-btn {
  border: none;
  background: #fff1f2;
  color: #be123c;
  width: 34px; height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  display: inline-grid; place-items: center;
  transition: background 0.15s, transform 0.15s;
}
.icon-btn:hover { background: #ffe4e6; transform: scale(1.05); }
.icon-btn.copy {
  background: #e0e7ff; color: #4338ca;
  width: 26px; height: 26px;
  font-size: 12px;
  margin-left: 6px;
}
.icon-btn.copy:hover { background: #c7d2fe; }
body.theme-dark .icon-btn      { background: rgba(190,18,60,0.2); color: #fda4af; }
body.theme-dark .icon-btn:hover{ background: rgba(190,18,60,0.35); }
body.theme-dark .icon-btn.copy      { background: rgba(67,56,202,0.25); color: #a5b4fc; }
body.theme-dark .icon-btn.copy:hover{ background: rgba(67,56,202,0.4); }

.copyable { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Чекбоксы ---------- */
.data input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Пагинация ---------- */
.pagination {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 16px; flex-wrap: wrap; gap: 12px;
}
.pagination .controls { display: flex; align-items: center; gap: 8px; }
.pagination button {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s;
}
.pagination button:hover:not(:disabled) { background: var(--soft-bg); border-color: var(--accent); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--text-muted); }
.pagination select { width: auto; padding: 8px 10px; font-size: 13px; }

/* ---------- Модальное окно ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(31, 34, 64, 0.55);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--card-bg);
  color: var(--text);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.modal h3 { margin-bottom: 18px; font-size: 18px; }
.modal .actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px;
}

/* ---------- Окно входа ---------- */
.login-screen {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-card .lock { font-size: 44px; margin-bottom: 10px; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p  { color: var(--text-muted); font-size: 14px; margin-bottom: 22px; }
.login-card .field { text-align: left; margin-bottom: 12px; }

/* ---------- Toast ---------- */
.toasts {
  position: fixed; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
  max-width: calc(100vw - 40px);
}
.toast {
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 600;
  min-width: 240px;
  border-left: 5px solid var(--success);
  animation: slideIn 0.25s ease, fadeOut 0.4s ease 2.3s forwards;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn  { border-left-color: var(--warn); }

/* ---------- Анимации ---------- */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn   { from { opacity: 0; transform: translateY(16px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(30%); } }

/* ---------- Состояние: пусто ---------- */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty-state .icon { font-size: 40px; margin-bottom: 10px; opacity: 0.6; }

/* ---------- Панель массовых действий ---------- */
.bulk-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--soft-bg);
  border-radius: 14px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.bulk-bar.show { display: flex; }
.bulk-bar .count { font-weight: 700; }

/* ---------- Аналитика ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-box {
  background: var(--card-bg);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow-md);
}
.stat-box .label {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
  margin-bottom: 8px;
}
.stat-box .value {
  font-size: 28px; font-weight: 800; letter-spacing: -0.02em;
}
.stat-box.accent .value {
  background: var(--bg-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.stat-box.urgent .value { color: var(--danger); }
.stat-box.warn   .value { color: var(--warn); }

.bar-chart { margin-top: 10px; }
.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 90px;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.bar-row .bar-label { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar-track {
  height: 12px; background: var(--soft-bg); border-radius: 999px; overflow: hidden;
}
.bar-row .bar-fill {
  height: 100%;
  background: var(--bg-grad);
  border-radius: 999px;
  transition: width 0.5s ease;
}
.bar-row .bar-value { text-align: right; font-weight: 700; color: var(--text-muted); }

/* ---------- Студент-профиль ---------- */
.student-orders-list {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.student-order-item {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px dashed var(--border);
}
.student-order-item:last-child { border-bottom: none; }

/* =========================================================
   Индивидуальные ширины колонок таблиц
   ========================================================= */

/* ---------- Таблица ЗАКАЗОВ ---------- */
#ordersTable th:nth-child(1),
#ordersTable td:nth-child(1)  { width: 36px; padding-left: 12px; padding-right: 4px; }   /* чекбокс */
#ordersTable th:nth-child(2),
#ordersTable td:nth-child(2)  { width: 50px; }                                            /* ID */
#ordersTable th:nth-child(3),
#ordersTable td:nth-child(3)  { max-width: 170px; }                                       /* Студент */
#ordersTable th:nth-child(4),
#ordersTable td:nth-child(4)  { max-width: 120px; }                                       /* От кого */
#ordersTable th:nth-child(5),
#ordersTable td:nth-child(5)  { width: 90px; }                                            /* Стоимость */
#ordersTable th:nth-child(6),
#ordersTable td:nth-child(6)  { max-width: 140px; }                                       /* Предмет */
#ordersTable th:nth-child(7),
#ordersTable td:nth-child(7)  { width: 130px; }                                           /* Статус */
#ordersTable th:nth-child(8),
#ordersTable td:nth-child(8),
#ordersTable th:nth-child(9),
#ordersTable td:nth-child(9),
#ordersTable th:nth-child(10),
#ordersTable td:nth-child(10) { width: 92px; }                                            /* Даты */
#ordersTable th:nth-child(11),
#ordersTable td:nth-child(11) { width: 50px; text-align: center; }                        /* Коммент */
#ordersTable th:nth-child(12),
#ordersTable td:nth-child(12) { width: 95px; padding-right: 12px; }                       /* Действия */

/* ---------- Таблица СТУДЕНТОВ ---------- */
#studentsTable th:nth-child(1),
#studentsTable td:nth-child(1)  { width: 50px; padding-left: 12px; }   /* ID */
#studentsTable th:nth-child(2),
#studentsTable td:nth-child(2)  { max-width: 200px; }                  /* ФИО */
#studentsTable th:nth-child(3),
#studentsTable td:nth-child(3)  { width: 90px; }                       /* Группа */
#studentsTable th:nth-child(4),
#studentsTable td:nth-child(4)  { max-width: 170px; }                  /* Телефон */
#studentsTable th:nth-child(5),
#studentsTable td:nth-child(5)  { max-width: 140px; }                  /* TG */
#studentsTable th:nth-child(6),
#studentsTable td:nth-child(6)  { width: 90px; }                       /* Зачетка */
#studentsTable th:nth-child(7),
#studentsTable td:nth-child(7)  { max-width: 220px; }                  /* Комментарий */
#studentsTable th:nth-child(8),
#studentsTable td:nth-child(8)  { width: 90px; padding-right: 12px; }  /* Действия */

/* ---------- Таблица НА ОФОРМЛЕНИИ ---------- */
#processingTable th:nth-child(1),
#processingTable td:nth-child(1)  { width: 50px; padding-left: 12px; }
#processingTable th:nth-child(2),
#processingTable td:nth-child(2)  { max-width: 180px; }                /* Студент */
#processingTable th:nth-child(3),
#processingTable td:nth-child(3)  { width: 90px; }                     /* Стоимость */
#processingTable th:nth-child(4),
#processingTable td:nth-child(4)  { max-width: 150px; }                /* Предмет */
#processingTable th:nth-child(5),
#processingTable td:nth-child(5)  { width: 130px; }                    /* Статус */
#processingTable th:nth-child(6),
#processingTable td:nth-child(6),
#processingTable th:nth-child(7),
#processingTable td:nth-child(7)  { width: 100px; }                    /* Даты */
#processingTable th:nth-child(8),
#processingTable td:nth-child(8)  { width: 120px; padding-right: 12px;}/* Действие */

/* На очень узких экранах скрываем второстепенные колонки,
   чтобы избежать горизонтального скролла */
@media (max-width: 1100px) {
  table.data { min-width: auto; }
  /* скрываем "От кого" */
  #ordersTable th:nth-child(4),
  #ordersTable td:nth-child(4) { display: none; }
}
@media (max-width: 900px) {
  /* скрываем "Коммент" иконку — она всё равно есть при клике */
  #ordersTable th:nth-child(11),
  #ordersTable td:nth-child(11) { display: none; }
  /* скрываем "Дата оплаты" */
  #ordersTable th:nth-child(10),
  #ordersTable td:nth-child(10) { display: none; }
}

/* =========================================================
   Ролевая модель: по умолчанию .admin-only отображаются.
   JS скрывает их для роли processor через style.display = 'none'.
   ========================================================= */

/* =========================================================
   Кнопка "В TickTick" в таблице заказов
   ========================================================= */
.icon-btn.ticktick {
  background: #dbeafe;
  color: #2563eb;
}
.icon-btn.ticktick:hover {
  background: #bfdbfe;
}
body.theme-dark .icon-btn.ticktick {
  background: rgba(37, 99, 235, 0.25);
  color: #93c5fd;
}
body.theme-dark .icon-btn.ticktick:hover {
  background: rgba(37, 99, 235, 0.4);
}

/* =========================================================
   Мультивыбор статусов (кнопки-тоггеры в фильтре)
   ========================================================= */
.status-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 2px;
}
.status-toggle {
  padding: 5px 12px;
  border-radius: 999px;
  border: 2px solid transparent;
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, border-color 0.15s;
  white-space: nowrap;
  opacity: 0.55;
}
.status-toggle:hover { transform: translateY(-1px); opacity: 0.9; }
.status-toggle.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px rgba(102,126,234,0.25);
  transform: translateY(-1px);
  opacity: 1;
}
.status-toggle.status-new        { background: #e0e7ff; color: #4338ca; }
.status-toggle.status-processing { background: #fef3c7; color: #b45309; }
.status-toggle.status-paid       { background: #dcfce7; color: #15803d; }
.status-toggle.status-unpaid     { background: #ffe4e6; color: #be123c; }
.status-toggle.status-done       { background: #e0f2fe; color: #0369a1; }
body.theme-dark .status-toggle.status-new        { background: rgba(67,56,202,0.25);   color: #a5b4fc; }
body.theme-dark .status-toggle.status-processing { background: rgba(180,83,9,0.25);    color: #fcd34d; }
body.theme-dark .status-toggle.status-paid       { background: rgba(21,128,61,0.25);   color: #86efac; }
body.theme-dark .status-toggle.status-unpaid     { background: rgba(190,18,60,0.25);   color: #fda4af; }
body.theme-dark .status-toggle.status-done       { background: rgba(3,105,161,0.25);   color: #7dd3fc; }

/* =========================================================
   ===  МОБИЛЬНАЯ ВЕРСИЯ  ==================================
   =========================================================
   Подход: один HTML, адаптивный CSS.
   - <=900px: компактные отступы, шапка/вкладки/фильтры адаптируются
   - <=640px: таблицы превращаются в карточки (каждая строка — плитка)
   - safe-area для iOS notch'ей
   ========================================================= */

/* Safe-area для iOS */
@supports (padding: max(0px)) {
  .app {
    padding-left:  max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    padding-bottom: max(64px, env(safe-area-inset-bottom));
  }
}

/* iOS Safari зумит при тапе на input с font-size < 16px.
   Это сильно ломает UX, поэтому форсим 16px на телефоне. */
@media (max-width: 900px) {
  input, select, textarea {
    font-size: 16px;
  }
  /* Кроме мелких контролов, где это сломает вёрстку */
  .pagination select,
  td.editing input,
  td.editing select {
    font-size: 14px;
  }
}

/* ---------- Планшетная зона: <=900px ---------- */
@media (max-width: 900px) {
  .app {
    padding: 16px 14px 32px;
  }

  /* Шапка компактнее */
  .topbar {
    margin-bottom: 16px;
    gap: 10px;
  }
  .brand-logo { width: 40px; height: 40px; font-size: 20px; border-radius: 12px; }
  .brand h1 { font-size: 20px; }
  .brand p { font-size: 12px; }

  /* Кнопки шапки чуть меньше — но всё ещё тыкабельны */
  .icon-toggle { width: 40px; height: 40px; font-size: 16px; }
  .badge-pill { padding: 8px 14px; font-size: 12px; }

  /* Вкладки — горизонтальный скролл, как в чатах, чем перенос в 2 строки */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;     /* Firefox */
    padding: 6px;
    border-radius: 16px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 0 0 auto;
    min-width: auto;
    padding: 10px 16px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* Карточки компактнее */
  .card { padding: 18px; border-radius: 18px; }
  .card + .card { margin-top: 14px; }
  .card h2 { font-size: 16px; margin-bottom: 14px; }

  /* Топ-grid в одну колонку (уже было, но усиливаем) */
  .top-grid { gap: 14px; margin-bottom: 14px; }

  /* Большая сумма в "Заработано" не должна вылезать */
  .report .amount { font-size: 34px; }

  /* Фильтры — каждый в отдельной строке для удобства тапа */
  .filters { gap: 12px; }
  .filters .field { min-width: 100%; flex: 1 1 100%; }

  /* Аналитика: карточки чуть меньше */
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
  }
  .stat-box { padding: 14px; border-radius: 14px; }
  .stat-box .value { font-size: 22px; }
  .stat-box .label { font-size: 11px; }

  /* График: подпись бара переносится наверх */
  .bar-row {
    grid-template-columns: 1fr 70px;
    grid-template-areas:
      "label  value"
      "track  track";
    gap: 4px 8px;
    margin-bottom: 12px;
  }
  .bar-row .bar-label { grid-area: label; font-size: 12px; }
  .bar-row .bar-value { grid-area: value; font-size: 12px; }
  .bar-row .bar-track { grid-area: track; height: 10px; }
}

/* ---------- Маленькие экраны: <=640px ---------- */
@media (max-width: 640px) {

  /* Шапка: подзаголовок прячем, чтобы влезало */
  .brand p { display: none; }
  .brand h1 { font-size: 18px; }
  /* "Кол-во заказов" в шапке скрываем — оно дублируется в карточках */
  #topBadge { display: none; }
  #roleBadge { display: none; }

  /* === Таблицы → карточки === */
  /* Контейнер больше не скроллит горизонтально — карточки укладываются вертикально */
  .table-wrap {
    overflow-x: visible;
    border: none;
    border-radius: 0;
    background: transparent;
  }
  table.data {
    display: block;
    min-width: 0;
    width: 100%;
    font-size: 14px;
  }
  table.data thead { display: none; }              /* Заголовки колонок не нужны — есть data-label */
  table.data tbody { display: block; }
  table.data tbody tr {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
  }
  table.data tbody tr:last-child td { border-bottom: 1px dashed var(--border); } /* возвращаем разделитель — мы переопределили снизу */
  table.data tbody tr:hover td { background: transparent; }
  table.data tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px dashed var(--border);
    white-space: normal;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    text-align: right;
    min-height: 32px;
  }
  table.data tbody tr td:last-child { border-bottom: none; }
  table.data tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    text-align: left;
  }
  /* td без data-label (пусто) — не показываем псевдоэлемент-подпись */
  table.data tbody td[data-label=""]::before { display: none; }

  /* Подсветка дедлайнов через рамку слева у плитки */
  table.data tbody tr.deadline-soon    { border-left: 4px solid var(--warn); }
  table.data tbody tr.deadline-overdue { border-left: 4px solid var(--danger); }
  table.data tbody tr.deadline-soon    td,
  table.data tbody tr.deadline-overdue td { background: transparent !important; }
  /* Возвращаем border-left у первой ячейки в норму (он не нужен в режиме карточки) */
  table.data tbody tr.deadline-soon    td:first-child,
  table.data tbody tr.deadline-overdue td:first-child { border-left: none; }

  /* Выбранная строка */
  table.data tbody tr.selected {
    background: rgba(102,126,234,0.08);
    border-color: var(--accent);
  }

  /* Чекбокс и ID в шапке плитки — без подписи слева */
  table.data tbody td.cell-check {
    border-bottom: 1px dashed var(--border);
    justify-content: flex-start;
    padding: 4px 0 10px;
  }
  table.data tbody td.cell-check input[type="checkbox"] {
    width: 22px; height: 22px;
  }
  table.data tbody td.cell-id {
    color: var(--text-muted);
    font-weight: 700;
    font-size: 12px;
  }
  table.data tbody td.cell-id::before {
    color: var(--accent);
  }

  /* Иконки действий в плитке — справа в ряд, крупнее для пальца */
  table.data tbody td.cell-actions {
    justify-content: flex-end;
    gap: 10px;
    padding-top: 10px;
  }
  .icon-btn { width: 40px; height: 40px; font-size: 17px; }
  .icon-btn.copy { width: 28px; height: 28px; font-size: 13px; }

  /* Статус-бейдж не нужно растягивать на всю ширину */
  table.data tbody td[data-field="status"] .status,
  table.data tbody td[data-label="Статус"] .status {
    font-size: 12px;
    padding: 5px 12px;
  }

  /* Pagination на мобилке: всё в столбец */
  .pagination {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 10px;
  }
  .pagination .controls {
    justify-content: center;
  }
  .pagination button { width: 44px; height: 44px; }

  /* Bulk-bar (массовые действия) — закрепляем внизу экрана как тулбар */
  .bulk-bar.show {
    position: fixed;
    left: 8px; right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    z-index: 90;
    margin: 0;
    box-shadow: 0 10px 30px rgba(31,34,64,0.25);
    background: var(--card-bg);
    border: 1px solid var(--border);
  }

  /* Кнопки в формах крупнее под палец */
  .btn { padding: 14px 22px; min-height: 48px; }
  .btn.sm { padding: 10px 14px; min-height: 40px; }
  .btn.xs { padding: 8px 12px; min-height: 32px; }

  /* Модалка — bottom-sheet снизу */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 22px 22px 0 0;
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom, 0px));
    animation: slideUp 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.05);
  }
  .modal h3 { font-size: 17px; margin-bottom: 14px; }
  .modal .actions { flex-direction: column-reverse; gap: 8px; }
  .modal .actions .btn { width: 100%; }

  /* Toast — снизу по центру, не съезжает */
  .toasts {
    right: 8px; left: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    align-items: stretch;
  }
  .toast { min-width: 0; }

  /* Окно входа */
  .login-card { padding: 26px 20px; border-radius: 20px; }

  /* Группа фильтр-чипов — компактнее */
  .status-toggles { gap: 5px; }
  .status-toggle { padding: 7px 12px; font-size: 12px; }

  /* Скрываем колонки, которые мы прятали на ширине 900px и менее —
     возвращаем их видимость, ведь теперь у нас карточки */
  #ordersTable th:nth-child(4),
  #ordersTable td:nth-child(4),
  #ordersTable th:nth-child(10),
  #ordersTable td:nth-child(10),
  #ordersTable th:nth-child(11),
  #ordersTable td:nth-child(11) { display: flex; }
  /* (th не отображаются — мы их скрыли через `table.data thead { display: none; }`) */

  /* Сбрасываем фиксированные ширины колонок (они только для table-режима) */
  #ordersTable td,
  #studentsTable td,
  #processingTable td,
  #paidTable td,
  #usersTable td {
    width: auto !important;
    max-width: none !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  /* Инлайн-редактирование внутри плитки выглядит лучше с фоном */
  td.editing {
    background: var(--soft-bg) !important;
    border-radius: 10px;
    padding: 8px !important;
  }
  td.editing::before { display: none; }
  td.editing input, td.editing select {
    font-size: 16px;
    padding: 10px 12px;
  }
}

/* ---------- Совсем маленькие телефоны: <=380px ---------- */
@media (max-width: 380px) {
  .app { padding: 12px 8px 32px; }
  .card { padding: 14px; }
  .brand-logo { width: 36px; height: 36px; font-size: 18px; }
  .brand h1 { font-size: 16px; }
  .icon-toggle { width: 36px; height: 36px; font-size: 14px; }
}

/* Анимация для bottom-sheet модалки */
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: none; }
}
