/* pdaudit cabinet — v1 07.07.2026
   Стек: чистый CSS без билда, референсы Plausible/Healthchecks/Fathom.
   Никаких !important, никаких CDN Tailwind. Работает в любом браузере > 2022г.
*/

:root {
  --c-bg: #f8fafc;
  --c-surface: #ffffff;
  --c-surface-alt: #f1f5f9;
  --c-border: #e2e8f0;
  --c-border-strong: #cbd5e1;
  --c-text: #0f172a;
  --c-text-muted: #475569;   /* slate-600, был #64748b (слишком бледно) */
  --c-text-soft: #64748b;    /* slate-500 — совместимость со старыми шаблонами */
  --c-text-subtle: #94a3b8;  /* slate-400 — ТОЛЬКО декор/иконки/плейсхолдеры, НЕ читаемый текст (AA <4.5:1) */
  --c-primary: #1d4ed8;
  --c-primary-hover: #1e40af;
  --c-primary-soft: #dbeafe;
  --c-success: #059669;
  --c-success-soft: #d1fae5;
  --c-warn: #d97706;
  --c-warn-soft: #fef3c7;
  --c-error: #dc2626;
  --c-error-soft: #fee2e2;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 2px 4px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);
  --t-fast: 120ms cubic-bezier(.4, 0, .2, 1);
  --t-med: 200ms cubic-bezier(.4, 0, .2, 1);
  --font-sans: -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Inter", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

/* Уважение к пользовательским настройкам */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--c-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

/* Focus visible — доступность (Fabl: AA везде дёшево) */
:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ═══════════════════ APP SHELL ═══════════════════ */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  min-height: 100vh;
}

.app-topbar {
  grid-area: topbar;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.app-topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: var(--c-text);
}

.app-topbar__brand-logo {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #1e40af;  /* тот же тёмно-синий что в favicon.svg */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.app-topbar__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-topbar__legacy-btn {
  background: var(--c-surface-alt);
  color: var(--c-text-muted);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  text-decoration: none;
}

.app-topbar__legacy-btn:hover {
  background: var(--c-border);
  color: var(--c-text);
  text-decoration: none;
}

.app-topbar__notif-btn {
  position: relative;
  background: transparent;
  border: none;
  color: var(--c-text-muted);
  padding: 6px;
  border-radius: var(--radius);
  font-size: 18px;
  line-height: 1;
}

.app-topbar__notif-btn:hover {
  background: var(--c-surface-alt);
}

.app-topbar__notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--c-error);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-topbar__profile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 20px;
  background: var(--c-surface-alt);
  color: var(--c-text);
  font-size: 13px;
  border: 1px solid var(--c-border);
}

.app-topbar__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

/* ═══════════════════ SIDEBAR ═══════════════════ */

.app-sidebar {
  grid-area: sidebar;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: 12px 8px 16px;
  overflow-y: auto;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  display: flex;
  flex-direction: column;
}

/* Footer sidebar — прижат к низу через margin-top:auto */
.app-sidebar__footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-sidebar__footer-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--c-text-soft);
  text-decoration: none;
  font-size: 12px;
  transition: background-color 0.1s, color 0.1s;
}

.app-sidebar__footer-link:hover {
  background: var(--c-surface-alt);
  color: var(--c-text);
  text-decoration: none;
}

.app-sidebar__footer-link__icon {
  width: 18px;
  text-align: center;
  font-size: 13px;
  flex-shrink: 0;
}

.app-sidebar__brand-mini {
  padding: 12px 12px 4px;
  font-size: 11px;
  color: var(--c-text-soft);
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-sidebar__brand-mini__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-success);
  display: inline-block;
}

/* Profile dropdown в top-bar (правый верхний угол) */
.app-topbar__profile-dropdown {
  position: relative;
}

.app-topbar__profile-dropdown > summary {
  cursor: pointer;
  list-style: none;
  outline: none;
}

.app-topbar__profile-dropdown > summary::-webkit-details-marker { display: none; }

.app-topbar__dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 240px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 40;
  padding: 4px 0;
}

.app-topbar__dropdown-header {
  padding: 10px 14px 12px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 4px;
}

.app-topbar__dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--c-text);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.1s;
}

.app-topbar__dropdown-item:hover {
  background: var(--c-surface-alt);
  color: var(--c-text);
  text-decoration: none;
}

.app-topbar__dropdown-item--danger {
  color: var(--c-error);
}

.app-topbar__dropdown-item--danger:hover {
  background: var(--c-error-soft);
  color: var(--c-error);
}

.app-topbar__dropdown-sep {
  height: 1px;
  background: var(--c-border);
  margin: 4px 0;
}

.app-sidebar__group {
  margin-bottom: 16px;
}

.app-sidebar__group-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--c-text-soft);
  padding: 8px 12px 4px;
  margin: 0;
}

.app-sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #334155;             /* slate-700 — читаемее чем muted */
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}

.app-sidebar__link:hover {
  background: var(--c-surface-alt);
  color: var(--c-text);
  text-decoration: none;
}

/* Активный пункт: цветной индикатор-грань слева вместо жирной заливки (Linear-стиль) */
.app-sidebar__link--active {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--c-primary);
}

.app-sidebar__link--active:hover {
  background: var(--c-primary-soft);
  color: var(--c-primary);
}

.app-sidebar__link .ico {
  color: currentColor;
  flex-shrink: 0;
}

/* legacy: старый emoji-стиль, оставлен пока не заменил во всех местах */
.app-sidebar__icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* ═══════════════════ MAIN ═══════════════════ */

.app-main {
  grid-area: main;
  padding: 28px 32px 60px;
  width: 100%;
  min-width: 0;  /* важно чтобы grid-child не переполнялся */
}

/* Форменные страницы (Профиль, Поддержка) — не растягиваем на ширь экрана */
.app-main--form {
  max-width: 900px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-header__title {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
  color: var(--c-text);
  letter-spacing: -0.01em;
}

.page-header__subtitle {
  margin: 0;
  color: var(--c-text-muted);
  font-size: 14px;
}

/* ═══════════════════ CARDS ═══════════════════ */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card + .card {
  margin-top: 16px;
}

.card__title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--c-text);
}

.card__body {
  font-size: 14px;
  color: var(--c-text);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.card-stat__label {
  font-size: 12px;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
  font-weight: 600;
}

.card-stat__value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--c-text);
  letter-spacing: -0.02em;
}

.card-stat__hint {
  font-size: 12px;
  color: var(--c-text-soft);
  margin-top: 4px;
}

/* ═══════════════════ BUTTONS ═══════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  color: var(--c-text);
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  text-decoration: none;
}

.btn--primary {
  background: var(--c-primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--c-primary-hover);
  color: #fff;
}

.btn--secondary {
  background: var(--c-surface);
  color: var(--c-text);
  border-color: var(--c-border-strong);
}

.btn--secondary:hover {
  background: var(--c-surface-alt);
}

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

.btn--ghost:hover {
  background: var(--c-surface-alt);
  color: var(--c-text);
}

.btn--sm {
  padding: 4px 10px;
  font-size: 13px;
}

/* ═══════════════════ FORMS ═══════════════════ */

.form-row {
  margin-bottom: 16px;
}

.form-row__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text);
  margin-bottom: 6px;
}

.form-row__hint {
  font-size: 12px;
  color: var(--c-text-muted);
  margin-top: 4px;
}

.form-row__input,
.form-row__textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-surface);
}

.form-row__input:focus,
.form-row__textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}

.form-row__input:disabled {
  background: var(--c-surface-alt);
  color: var(--c-text-muted);
}

/* ═══════════════════ TABLES ═══════════════════ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--c-text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--c-border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-border);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--c-surface-alt);
}

/* ═══════════════════ BADGES ═══════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

.badge--success {
  background: var(--c-success-soft);
  color: var(--c-success);
}

.badge--warn {
  background: var(--c-warn-soft);
  color: var(--c-warn);
}

.badge--error {
  background: var(--c-error-soft);
  color: var(--c-error);
}

.badge--muted {
  background: var(--c-surface-alt);
  color: var(--c-text-muted);
}

/* ═══════════════════ EMPTY / ERROR STATES ═══════════════════ */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--c-text-muted);
}

.empty-state__icon {
  font-size: 32px;
  margin-bottom: 8px;
  display: block;
  opacity: 0.6;
}

.empty-state__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--c-text);
  margin: 0 0 4px;
}

.empty-state__hint {
  font-size: 14px;
  margin: 0 0 12px;
}

.error-state {
  padding: 20px;
  border: 1px solid var(--c-error-soft);
  background: #fef7f7;
  border-radius: var(--radius);
  color: var(--c-text);
  font-size: 14px;
}

.error-state__title {
  color: var(--c-error);
  font-weight: 600;
  margin: 0 0 6px;
}

/* ═══════════════════ HTMX indicator ═══════════════════ */

.htmx-indicator {
  display: none;
  color: var(--c-text-muted);
  font-size: 13px;
}

.htmx-request .htmx-indicator {
  display: inline;
}

.htmx-request.htmx-indicator {
  display: inline;
}

/* ═══════════════════ MOBILE ═══════════════════ */

.app-mobile-toggle {
  display: none;
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--c-text);
  padding: 4px 8px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .app-sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    height: calc(100vh - var(--topbar-h));
    width: 260px;
    z-index: 25;
    transform: translateX(-100%);
    transition: transform 0.18s;
  }
  .app-sidebar--open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .app-main {
    padding: 20px 16px 60px;
  }
  .app-mobile-toggle {
    display: inline-flex;
  }
  .app-topbar__legacy-btn {
    display: none;
  }
}

/* ═════════════ TOAST ═════════════
   Ненавязчивое уведомление вместо alert() в правом верхнем углу.
   Используется в pdToast(text, kind='success'|'error'|'info', ttl=3800).
*/
#pd-toast-holder {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.pd-toast {
  min-width: 260px;
  max-width: 420px;
  padding: 12px 16px 12px 44px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--c-border);
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.15);
  font-size: 14px;
  line-height: 1.4;
  color: var(--c-text);
  position: relative;
  animation: pd-toast-in 0.28s cubic-bezier(.2,.9,.2,1);
  pointer-events: auto;
}
.pd-toast::before {
  content: '';
  position: absolute;
  left: 14px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}
.pd-toast--success { border-color: var(--c-success); }
.pd-toast--success::before { background: var(--c-success); content: '✓'; }
.pd-toast--error   { border-color: var(--c-error); }
.pd-toast--error::before   { background: var(--c-error); content: '!'; }
.pd-toast--info    { border-color: var(--c-primary); }
.pd-toast--info::before    { background: var(--c-primary); content: 'i'; font-style: italic; }
.pd-toast.pd-toast--closing { animation: pd-toast-out 0.22s ease-in both; }
@keyframes pd-toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes pd-toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}

/* ═══════════════════ ICONS (Lucide inline SVG) ═══════════════════ */
/* Заменяют эмодзи в UI. currentColor наследует цвет текста родителя */
.ico {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: -0.15em;
  color: currentColor;
}
.ico--muted   { color: var(--c-text-muted); }
.ico--subtle  { color: var(--c-text-subtle); }
.ico--primary { color: var(--c-primary); }
.ico--success { color: var(--c-success); }
.ico--warn    { color: var(--c-warn); }
.ico--danger  { color: var(--c-error); }

/* Иконка в кружке — используется в KPI-плитках и empty-state */
.ico-tile {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--c-surface-alt);
  color: var(--c-text-subtle);
  flex-shrink: 0;
}
.ico-tile--lg {
  width: 72px;
  height: 72px;
  border-radius: 50%;
}

/* ═══════════════════ BUTTON POLISH ═══════════════════ */
.btn {
  transition: background-color var(--t-fast), color var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.btn--primary {
  box-shadow: var(--shadow-sm);
}
.btn--primary:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

/* ═══════════════════ CARD HOVER (тонкий) ═══════════════════ */
.card--hover {
  transition: border-color var(--t-med), box-shadow var(--t-med);
}
.card--hover:hover {
  border-color: var(--c-border-strong);
  box-shadow: var(--shadow-md);
}

/* Моноширинный шрифт для цифр (суммы, ИНН, коды, site_id) */
.mono, code, kbd, .form-row__input[type="number"] {
  font-family: var(--font-mono);
}

/* ═══════════════════ EMPTY STATE v2 ═══════════════════ */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--c-text-muted);
}
.empty-state__icon {
  margin: 0 auto 12px;
}
.empty-state__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--c-text);
  margin: 0 0 4px;
}
.empty-state__desc {
  font-size: 13px;
  color: var(--c-text-muted);
  margin: 0 auto;
  max-width: 320px;
}
.empty-state__action {
  margin-top: 14px;
}

/* ═══════════════════ ANIMATION: HTMX swap-in ═══════════════════ */
.htmx-added {
  animation: pd-fade-slide 0.22s ease-out both;
}
@keyframes pd-fade-slide {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
