/* ===== Цвета и размеры ===== */
:root {
  color-scheme: light;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e3e8ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8efff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --success: #16a34a;
  --warn-bg: #fff6d9;
  --warn-bg-strong: #ffe39a;
  --warn-border: #f2b52a;
  --warn-glow: rgba(242, 181, 42, 0.45);
  --info-bg: #eaf2ff;
  --info-border: #8db4ff;
  --st-new-bg: #dbeafe;
  --st-new-fg: #1e40af;
  --st-progress-bg: #fef3c7;
  --st-progress-fg: #92400e;
  --st-waiting-bg: #ffedd5;
  --st-waiting-fg: #9a3412;
  --st-done-bg: #dcfce7;
  --st-done-fg: #166534;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 6px 20px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d1320;
    --surface: #151d2e;
    --surface-2: #1b2539;
    --border: #2a364d;
    --text: #e5eaf3;
    --muted: #93a0b8;
    --primary: #3b7bf6;
    --primary-hover: #5b91f8;
    --primary-soft: rgba(79, 140, 255, 0.16);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.14);
    --success: #22c55e;
    --warn-bg: rgba(242, 181, 42, 0.12);
    --warn-bg-strong: rgba(242, 181, 42, 0.28);
    --warn-border: #b98a1f;
    --warn-glow: rgba(242, 181, 42, 0.35);
    --info-bg: rgba(79, 140, 255, 0.12);
    --info-border: #3d63a8;
    --st-new-bg: rgba(59, 130, 246, 0.2);
    --st-new-fg: #93c5fd;
    --st-progress-bg: rgba(245, 158, 11, 0.2);
    --st-progress-fg: #fcd34d;
    --st-waiting-bg: rgba(249, 115, 22, 0.2);
    --st-waiting-fg: #fdba74;
    --st-done-bg: rgba(34, 197, 94, 0.2);
    --st-done-fg: #86efac;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  }
}

/* ===== Основа ===== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--primary); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ===== Кнопки и поля ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.7;
}
.icon-btn:hover { opacity: 1; background: rgba(127, 127, 127, 0.15); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

input, textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: transparent;
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 14px; font-weight: 600; }
.field-hint { color: var(--muted); font-size: 13px; }
.field-error { color: var(--danger); font-size: 13px; }
.field.invalid .field-hint { display: none; }
.field-error:empty { display: none; }
.field.invalid input, .field.invalid textarea { border-color: var(--danger); }
.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

/* Переключатели «Таблица / Анкеты» и «ПК / Мобильный» */
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.segmented button {
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--primary); color: #fff; }

/* Тумблер */
.switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch .track {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--border);
  transition: background-color 0.2s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.6; }

/* ===== Статусы ===== */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.st-new { background: var(--st-new-bg); color: var(--st-new-fg); }
.st-progress { background: var(--st-progress-bg); color: var(--st-progress-fg); }
.st-waiting { background: var(--st-waiting-bg); color: var(--st-waiting-fg); }
.st-done { background: var(--st-done-bg); color: var(--st-done-fg); }

/* ===== Карточки и таблица ===== */
.card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.table th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.col-id { width: 56px; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-problem { min-width: 240px; white-space: pre-wrap; overflow-wrap: anywhere; }

.empty {
  padding: 48px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: 10px;
  background: #1e293b;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  animation: toast-in 0.2s ease-out;
}
.toast-success { background: var(--success); }
.toast-error { background: #dc2626; }

.offline {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

/* ===== Страница сотрудника ===== */
.page-header { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 22px; }
.brand-logo { font-size: 24px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.view-switches { display: flex; flex-wrap: wrap; gap: 8px; }

/* Уведомления над таблицей */
.notices { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
.notices:not(:has(> :not([hidden]))) { display: none; }
.notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 12px 12px 12px 16px;
  border: 1px solid;
  border-radius: var(--radius);
}
.notice-icon { font-size: 20px; line-height: 1.4; }
.notice-body { flex: 1; min-width: 0; }
.notice-title { font-weight: 700; }
.notice-text { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.notice-meta { color: var(--muted); font-size: 13px; }

.notice-message {
  border-color: var(--info-border);
  background: var(--info-bg);
  animation: slide-down 0.35s ease-out;
}

.notice-progress {
  border-color: var(--warn-border);
  background: var(--warn-bg);
  animation: pulse 1.8s ease-in-out infinite;
}
.progress-list { margin: 4px 0 0; padding: 0; list-style: none; }
.progress-list li { padding: 2px 0; overflow-wrap: anywhere; }
.progress-list .sep { color: var(--muted); }

.warn-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--warn-border);
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  animation: pulse 1.8s ease-in-out infinite;
}

/* Режим анкет */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.request-card { border-left-width: 4px; }
.request-card[data-status="new"] { border-left-color: var(--st-new-fg); }
.request-card[data-status="progress"] { border-left-color: var(--warn-border); }
.request-card[data-status="waiting"] { border-left-color: var(--st-waiting-fg); }
.request-card[data-status="done"] { border-left-color: var(--success); }
.request-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.card-id { color: var(--muted); font-weight: 700; }
.request-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 0;
}
.request-card dt { color: var(--muted); font-size: 13px; line-height: 1.6; }
.request-card dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.page-footer { margin-top: 24px; text-align: center; font-size: 14px; }
.page-footer a { color: var(--muted); }

/* Модальное окно */
dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.55); }
dialog[open] { animation: pop-in 0.2s ease-out; }
.dialog-form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; }
.dialog-header h2 { font-size: 19px; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Принудительный мобильный вид */
body.is-mobile .container { max-width: 480px; }
body.is-mobile .toolbar { flex-direction: column; align-items: stretch; }
body.is-mobile .toolbar > .btn { width: 100%; padding: 12px 16px; }
body.is-mobile .view-switches .segmented { flex: 1; }
body.is-mobile .segmented button { flex: 1; }
body.is-mobile .cards { grid-template-columns: 1fr; }
body.is-mobile .table { min-width: 640px; }
body.is-mobile .dialog-footer .btn { flex: 1; }

/* ===== Панель администратора ===== */
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 16px;
}
.topbar h1 { font-size: 18px; }
.tabs { display: flex; gap: 4px; margin-right: auto; }
.tabs a {
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--primary-soft); color: var(--primary); }
.topbar-actions { display: flex; gap: 8px; }

.admin .container { max-width: 1400px; }
.admin-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.admin-toolbar input[type="search"] { flex: 1; min-width: 220px; max-width: 480px; }
.count { color: var(--muted); font-size: 14px; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

.editable { cursor: text; }
.editable:hover { box-shadow: inset 0 0 0 1px var(--border); }
td.editing { padding: 6px; }
td.editing input, td.editing textarea { padding: 6px 8px; }
td.saving { opacity: 0.6; }
.col-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.col-actions { width: 48px; text-align: center; }
.status-select {
  width: auto;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.status-select option { background: var(--surface); color: var(--text); }
tr.flash td { animation: flash 1.4s ease-out; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  align-items: start;
  gap: 16px;
}
.settings-grid .card { display: flex; flex-direction: column; gap: 14px; }
.settings-grid h2 { font-size: 17px; }
.card-note { margin: 0; color: var(--muted); font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.wide { grid-column: 1 / -1; }

.message-form { display: flex; flex-direction: column; gap: 8px; }
.message-form-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.counter { color: var(--muted); font-size: 13px; }
.message-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.message-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.message-item p { margin: 0 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-item .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.tag-live {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--st-done-bg);
  color: var(--st-done-fg);
  font-weight: 600;
}

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.dropdown-menu button {
  padding: 9px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.dropdown-menu button:hover, .dropdown-menu button:focus-visible { background: var(--surface-2); }

.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { display: flex; flex-direction: column; gap: 14px; width: min(380px, 100%); }
.login-card h1 { font-size: 20px; }
.login-card .back { font-size: 14px; text-align: center; }

/* ===== Анимации ===== */
@keyframes pulse {
  0%, 100% { background-color: var(--warn-bg); box-shadow: 0 0 0 0 var(--warn-glow); }
  50% { background-color: var(--warn-bg-strong); box-shadow: 0 0 0 5px transparent; }
}
@keyframes slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes flash {
  from { background-color: var(--st-done-bg); }
  to { background-color: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 640px) {
  .container { padding: 14px 12px 32px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; }
}
