/* ============================================================
   InvoicePro Georgia — Главная таблица стилей
   Версия: 1.0.0
   ============================================================ */

/* ── 1. CSS-переменные (токены дизайна) ─────────────────── */
:root {
  /* Цвета — основная палитра */
  --color-primary:        #4F46E5;   /* Indigo-600  */
  --color-primary-hover:  #4338CA;   /* Indigo-700  */
  --color-primary-light:  #EEF2FF;   /* Indigo-50   */
  --color-primary-muted:  #A5B4FC;   /* Indigo-300  */

  --color-success:        #10B981;   /* Emerald-500 */
  --color-success-light:  #D1FAE5;   /* Emerald-100 */
  --color-warning:        #F59E0B;   /* Amber-500   */
  --color-warning-light:  #FEF3C7;   /* Amber-100   */
  --color-danger:         #EF4444;   /* Red-500     */
  --color-danger-light:   #FEE2E2;   /* Red-100     */
  --color-info:           #3B82F6;   /* Blue-500    */
  --color-info-light:     #DBEAFE;   /* Blue-100    */

  /* Нейтральные тона */
  --gray-50:  #F8FAFC;
  --gray-100: #F1F5F9;
  --gray-200: #E2E8F0;
  --gray-300: #CBD5E1;
  --gray-400: #94A3B8;
  --gray-500: #64748B;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1E293B;
  --gray-900: #0F172A;

  /* Светлая тема (по умолчанию) */
  --bg:           var(--gray-50);
  --bg-card:      #FFFFFF;
  --bg-input:     #FFFFFF;
  --text-primary: var(--gray-800);
  --text-muted:   var(--gray-500);
  --text-inverse: #FFFFFF;
  --border:       var(--gray-200);
  --border-focus: var(--color-primary);

  /* Сайдбар */
  --sidebar-bg:           #1E293B;   /* Slate-800 */
  --sidebar-text:         #94A3B8;   /* Slate-400 */
  --sidebar-text-hover:   #F1F5F9;   /* Slate-100 */
  --sidebar-active-bg:    var(--color-primary);
  --sidebar-active-text:  #FFFFFF;
  --sidebar-border:       #334155;   /* Slate-700 */
  --sidebar-width:        260px;
  --sidebar-collapsed-w:  68px;

  /* Шапка */
  --header-bg:     #FFFFFF;
  --header-border: var(--gray-200);
  --header-height: 64px;

  /* Тени */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.06);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.10), 0 4px 6px -2px rgba(0,0,0,.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.10), 0 10px 10px -5px rgba(0,0,0,.04);

  /* Скругления */
  --radius-sm: .25rem;    /* 4px  */
  --radius:    .375rem;   /* 6px  */
  --radius-md: .5rem;     /* 8px  */
  --radius-lg: .75rem;    /* 12px */
  --radius-xl: 1rem;      /* 16px */
  --radius-full: 9999px;

  /* Типографика */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  --text-xs:   .75rem;    /* 12px */
  --text-sm:   .875rem;   /* 14px */
  --text-base: 1rem;      /* 16px */
  --text-lg:   1.125rem;  /* 18px */
  --text-xl:   1.25rem;   /* 20px */
  --text-2xl:  1.5rem;    /* 24px */
  --text-3xl:  1.875rem;  /* 30px */

  /* Переходы */
  --transition:      all .15s ease;
  --transition-slow: all .25s ease;
}

/* ── Тёмная тема ─────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           var(--gray-900);
  --bg-card:      var(--gray-800);
  --bg-input:     #1a2535;
  --text-primary: var(--gray-100);
  --text-muted:   var(--gray-400);
  --border:       var(--gray-700);

  --sidebar-bg:           #0A0F1E;
  --sidebar-border:       #1a2535;

  --header-bg:     var(--gray-800);
  --header-border: var(--gray-700);

  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.4);
}

/* ── 2. Сброс и базовые стили ───────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

html { overflow-x: hidden; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg);
  transition: background .2s, color .2s;
  min-height: 100vh;
}

img { display: block; max-width: 100%; }
a  { color: var(--color-primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--color-primary-hover); }
ul, ol { list-style: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ── 3. Макет: обёртка приложения ───────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── 4. Сайдбар ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  max-height: 100vh;
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  transition: width var(--transition-slow), transform var(--transition-slow);
  overflow: hidden;
}

@supports (height: 100dvh) {
  .sidebar {
    height: 100dvh;
    max-height: 100dvh;
  }
}

.sidebar__logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.25rem;
  border-bottom: 1px solid var(--sidebar-border);
  height: var(--header-height);
  text-decoration: none;
  flex-shrink: 0;
}

.sidebar__logo-icon {
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
  color: #fff;
  font-weight: 700;
}
.sidebar__logo-mark {
  width: 20px;
  height: 20px;
  display: block;
}

.sidebar__logo-text {
  font-size: var(--text-sm);
  font-weight: 700;
  color: #F1F5F9;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar__logo-text span {
  display: block;
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--sidebar-text);
}

.sidebar__nav {
  flex: 1;
  padding: .75rem 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar__nav::-webkit-scrollbar { width: 4px; }
.sidebar__nav::-webkit-scrollbar-track { background: transparent; }
.sidebar__nav::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 2px; }

.sidebar__section-title {
  font-size: .625rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #ffffff;
  padding: 1rem 1.25rem .4rem;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.25rem;
  color: var(--sidebar-text);
  border-radius: 0;
  transition: var(--transition);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-decoration: none;
  font-size: var(--text-sm);
}

.sidebar__item:hover {
  background: rgba(255,255,255,.06);
  color: var(--sidebar-text-hover);
}

.sidebar__item.active {
  background: var(--color-primary);
  color: var(--sidebar-active-text);
}

.sidebar__item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #fff;
  border-radius: 0 2px 2px 0;
  opacity: .6;
}

.sidebar__icon {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar__label { white-space: nowrap; overflow: hidden; }

.sidebar__badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: .625rem;
  font-weight: 600;
  padding: .1rem .4rem;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}

.sidebar__footer {
  padding: .75rem 0;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.25rem;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar__avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar__user-info { flex: 1; overflow: hidden; }
.sidebar__user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-200);
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar__user-role {
  font-size: var(--text-xs);
  color: var(--sidebar-text);
}

/* Свернуть/развернуть сайдбар */
.sidebar.collapsed { width: var(--sidebar-collapsed-w); }
.sidebar.collapsed .sidebar__label,
.sidebar.collapsed .sidebar__logo-text,
.sidebar.collapsed .sidebar__section-title,
.sidebar.collapsed .sidebar__badge,
.sidebar.collapsed .sidebar__user-info { display: none; }
.sidebar.collapsed .sidebar__item { justify-content: center; padding: .6rem 0; }
.sidebar.collapsed .sidebar__user { justify-content: center; }

/* ── 5. Область контента ─────────────────────────────────── */
.app-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-slow);
}

.app-content.sidebar-collapsed { margin-left: var(--sidebar-collapsed-w); }

/* ── 6. Шапка (topbar) ───────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  box-shadow: var(--shadow-xs);
}

.topbar__toggle {
  background: none;
  border: none;
  padding: .5rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: var(--transition);
}
.topbar__toggle:hover { background: var(--gray-100); color: var(--text-primary); }

.topbar__breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.topbar__breadcrumb .crumb-current {
  color: var(--text-primary);
  font-weight: 600;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* Переключатель темы */
.btn-theme {
  background: none;
  border: none;
  padding: .5rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  transition: var(--transition);
}
.btn-theme:hover { background: var(--gray-100); color: var(--text-primary); }

/* Выбор языка в шапке */
.lang-switcher {
  position: relative;
}
.lang-switcher__btn {
  display: flex;
  align-items: center;
  gap: .375rem;
  padding: .4rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: var(--transition);
}
.lang-switcher__btn:hover { border-color: var(--color-primary); }

.lang-switcher__dropdown {
  position: absolute;
  top: calc(100% + .5rem);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 140px;
  z-index: 300;
  overflow: hidden;
  display: none;
}
.lang-switcher__dropdown.open { display: block; }

.lang-switcher__option {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: var(--transition);
}
.lang-switcher__option:hover { background: var(--gray-100); }
.lang-switcher__option.active { color: var(--color-primary); font-weight: 600; }

/* Уведомления в шапке */
.topbar__notif {
  position: relative;
}
.topbar__notif-btn {
  background: none;
  border: none;
  padding: .5rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  transition: var(--transition);
}
.topbar__notif-btn:hover { background: var(--gray-100); color: var(--text-primary); }

.notif-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 8px; height: 8px;
  background: var(--color-danger);
  border-radius: var(--radius-full);
  border: 2px solid var(--header-bg);
}

/* ── 7. Основная область страницы ───────────────────────── */
.page-main {
  flex: 1;
  padding: 1.75rem 1.75rem;
  max-width: 1400px;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-subtitle {
  margin-top: .25rem;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

/* ── 8. Карточки ─────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card__header {
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.card__title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
}

.card__body { padding: 1.25rem; }
.card__footer {
  padding: .875rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--gray-50);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
}
[data-theme="dark"] .card__footer { background: rgba(0,0,0,.15); }

/* Статистические карточки на dashboard */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}
.stat-card__icon--primary { background: var(--color-primary-light); color: var(--color-primary); }
.stat-card__icon--success  { background: var(--color-success-light); color: var(--color-success); }
.stat-card__icon--warning  { background: var(--color-warning-light); color: var(--color-warning); }
.stat-card__icon--danger   { background: var(--color-danger-light);  color: var(--color-danger);  }

.stat-card__label { font-size: var(--text-sm); color: var(--text-muted); font-weight: 500; }
.stat-card__value { font-size: var(--text-2xl); font-weight: 700; color: var(--text-primary); }
.stat-card__delta {
  font-size: var(--text-xs);
  font-weight: 500;
}
.stat-card__delta--up   { color: var(--color-success); }
.stat-card__delta--down { color: var(--color-danger);  }

/* ── 9. Кнопки ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.btn--secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--gray-100);
  border-color: var(--gray-300);
}
[data-theme="dark"] .btn--secondary:hover:not(:disabled) {
  background: var(--gray-700);
}

.btn--success {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}
.btn--success:hover:not(:disabled) { filter: brightness(.9); }

.btn--danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn--danger:hover:not(:disabled) { filter: brightness(.9); }

.btn--warning {
  background: var(--color-warning);
  color: #fff;
  border-color: var(--color-warning);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn--ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--text-primary); }
[data-theme="dark"] .btn--ghost:hover:not(:disabled) { background: var(--gray-700); }

.btn--sm { padding: .3rem .65rem; font-size: var(--text-xs); }
.btn--lg { padding: .65rem 1.5rem; font-size: var(--text-base); }
.btn--icon { padding: .5rem; }
.btn--icon.btn--sm { padding: .3rem; }
.btn--full { width: 100%; justify-content: center; }

/* ── 10. Формы ───────────────────────────────────────────── */
.form-group { margin-bottom: 1.125rem; }

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: .375rem;
}
.form-label .required { color: var(--color-danger); margin-left: .15rem; }

.form-control {
  display: block;
  width: 100%;
  padding: .5rem .75rem;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
.form-control::placeholder { color: var(--gray-400); }
.form-control:disabled { background: var(--gray-100); cursor: not-allowed; opacity: .7; }
[data-theme="dark"] .form-control:disabled { background: var(--gray-700); }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%2364748B' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .5rem center;
  background-size: 1.2em;
  padding-right: 2.25rem;
}

textarea.form-control { resize: vertical; min-height: 80px; }

.form-control--error { border-color: var(--color-danger); }
.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-top: .3rem;
  display: flex;
  align-items: center;
  gap: .25rem;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: .3rem;
}

.form-row {
  display: grid;
  gap: 1rem;
}
.form-row--2 { grid-template-columns: 1fr 1fr; }
.form-row--3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row--4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Input group (с иконкой/текстом слева/справа) */
.input-group {
  display: flex;
  align-items: stretch;
}
.input-group .form-control {
  flex: 1;
  border-radius: 0;
}
.input-group .form-control:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .form-control:last-child  { border-radius: 0 var(--radius) var(--radius) 0; }

.input-group-text {
  display: flex;
  align-items: center;
  padding: .5rem .75rem;
  background: var(--gray-100);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-sm);
  white-space: nowrap;
}
.input-group-text:first-child {
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
}
.input-group-text:last-child {
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
}
[data-theme="dark"] .input-group-text { background: var(--gray-700); }

/* Checkbox и Radio */
.form-check {
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--color-primary);
  cursor: pointer;
  flex-shrink: 0;
}
.form-check__label {
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 2rem;
  text-align: center;
  transition: var(--transition);
  cursor: pointer;
}
.upload-zone:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
.upload-zone__icon { font-size: 2rem; margin-bottom: .5rem; }
.upload-zone__text { font-size: var(--text-sm); color: var(--text-muted); }

/* ── 11. Таблицы ─────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead th {
  padding: .65rem .875rem;
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--gray-50);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
[data-theme="dark"] thead th { background: rgba(0,0,0,.2); }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }
[data-theme="dark"] tbody tr:hover { background: rgba(255,255,255,.03); }

td {
  padding: .75rem .875rem;
  color: var(--text-primary);
  vertical-align: middle;
}

.td-muted { color: var(--text-muted); font-size: var(--text-xs); }
.td-mono  { font-family: var(--font-mono); font-size: var(--text-xs); }
.td-actions { display: flex; gap: .3rem; align-items: center; }

/* ── 12. Бейджи статусов ─────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .55rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge--gray   { background: var(--gray-100);            color: var(--gray-600); }
.badge--blue   { background: var(--color-info-light);    color: var(--color-info); }
.badge--green  { background: var(--color-success-light); color: var(--color-success); }
.badge--red    { background: var(--color-danger-light);  color: var(--color-danger); }
.badge--orange { background: var(--color-warning-light); color: var(--color-warning); }
.badge--purple { background: #EDE9FE; color: #7C3AED; }

[data-theme="dark"] .badge--gray   { background: var(--gray-700); color: var(--gray-300); }
[data-theme="dark"] .badge--blue   { background: rgba(59,130,246,.2);  color: #93C5FD; }
[data-theme="dark"] .badge--green  { background: rgba(16,185,129,.2);  color: #6EE7B7; }
[data-theme="dark"] .badge--red    { background: rgba(239,68,68,.2);   color: #FCA5A5; }
[data-theme="dark"] .badge--orange { background: rgba(245,158,11,.2);  color: #FCD34D; }

/* ── 13. Алерты / уведомления ───────────────────────────── */
.alert {
  display: flex;
  gap: .75rem;
  padding: .875rem 1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  border: 1px solid transparent;
  align-items: flex-start;
}
.alert__icon { font-size: 1rem; flex-shrink: 0; margin-top: .1rem; }
.alert__body { flex: 1; }
.alert__title { font-weight: 600; margin-bottom: .125rem; }

.alert--success { background: var(--color-success-light); border-color: var(--color-success); color: #065F46; }
.alert--error   { background: var(--color-danger-light);  border-color: var(--color-danger);  color: #991B1B; }
.alert--warning { background: var(--color-warning-light); border-color: var(--color-warning); color: #92400E; }
.alert--info    { background: var(--color-info-light);    border-color: var(--color-info);    color: #1E40AF; }

[data-theme="dark"] .alert--success { color: #6EE7B7; }
[data-theme="dark"] .alert--error   { color: #FCA5A5; }
[data-theme="dark"] .alert--warning { color: #FCD34D; }
[data-theme="dark"] .alert--info    { color: #93C5FD; }

/* Toast — всплывающие уведомления */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: 360px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .875rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  animation: toastIn .25s ease;
}
.toast--success { border-left-color: var(--color-success); }
.toast--error   { border-left-color: var(--color-danger);  }
.toast--warning { border-left-color: var(--color-warning); }
.toast--info    { border-left-color: var(--color-info);    }

.toast__icon { font-size: 1rem; flex-shrink: 0; }
.toast__message { flex: 1; color: var(--text-primary); }
.toast__close {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(1rem); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── 14. Модальные окна ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(.95);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: scale(1); }

.modal--lg  { max-width: 740px; }
.modal--xl  { max-width: 960px; }
.modal--sm  { max-width: 380px; }

.modal__header {
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__title { font-size: var(--text-lg); font-weight: 700; color: var(--text-primary); }
.modal__close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  padding: .25rem;
  border-radius: var(--radius);
  transition: var(--transition);
}
.modal__close:hover { background: var(--gray-100); color: var(--text-primary); }

.modal__body    { padding: 1.25rem; }
.modal__footer  {
  padding: .875rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

/* ── 15. Фильтры и поиск ─────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .875rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 200px;
  gap: .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: .4rem .75rem;
  transition: border-color .15s;
}
.search-box:focus-within { border-color: var(--border-focus); }
.search-box__icon { color: var(--text-muted); font-size: .95rem; flex-shrink: 0; }
.search-box input {
  border: none;
  background: none;
  outline: none;
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

/* ── 16. Пагинация ───────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: .75rem;
}

.pagination__info { font-size: var(--text-sm); color: var(--text-muted); }

.pagination__pages {
  display: flex;
  align-items: center;
  gap: .25rem;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-card);
  transition: var(--transition);
  text-decoration: none;
}
.page-link:hover { background: var(--color-primary-light); border-color: var(--color-primary); color: var(--color-primary); }
.page-link.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.page-link:disabled, .page-link.disabled { opacity: .4; pointer-events: none; }

/* ── 17. Таблица позиций документа ──────────────────────── */
.items-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.items-table thead th {
  background: var(--color-primary-light);
  color: var(--color-primary);
}
[data-theme="dark"] .items-table thead th {
  background: rgba(79,70,229,.2);
  color: var(--color-primary-muted);
}

.items-table td input,
.items-table td select {
  border: 1px solid transparent;
  background: transparent;
  padding: .3rem .4rem;
  width: 100%;
  font-size: var(--text-sm);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.items-table td input:focus,
.items-table td select:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--bg-input);
}

.items-table .col-desc    { min-width: 200px; }
.items-table .col-qty     { width: 80px;  }
.items-table .col-price   { width: 110px; }
.items-table .col-disc    { width: 80px;  }
.items-table .col-tax     { width: 90px;  }
.items-table .col-total   { width: 110px; text-align: right; font-weight: 600; }
.items-table .col-actions { width: 48px;  text-align: center; }

/* Итоговый блок документа */
.doc-totals {
  display: flex;
  justify-content: flex-end;
}
.doc-totals__table {
  min-width: 280px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.doc-totals__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .5rem .875rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}
.doc-totals__row:last-child { border-bottom: none; }
.doc-totals__row--total {
  background: var(--color-primary);
  color: #fff;
  font-size: var(--text-base);
  font-weight: 700;
  padding: .65rem .875rem;
}
.doc-totals__label { color: var(--text-muted); }
.doc-totals__value { font-weight: 600; }
.doc-totals__row--total .doc-totals__label,
.doc-totals__row--total .doc-totals__value { color: #fff; }

/* ── 18. Страница входа / регистрации ───────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  background: var(--bg);
}

.auth-left {
  flex: 1;
  background: var(--gray-900);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  position: relative;
  overflow: hidden;
}

.auth-left::before {
  content: '';
  position: absolute;
  top: -40%;
  left: -20%;
  width: 80%;
  height: 80%;
  background: radial-gradient(circle, rgba(79,70,229,.4) 0%, transparent 70%);
  pointer-events: none;
}
.auth-left::after {
  content: '';
  position: absolute;
  bottom: -40%;
  right: -20%;
  width: 70%;
  height: 70%;
  background: radial-gradient(circle, rgba(16,185,129,.3) 0%, transparent 70%);
  pointer-events: none;
}

.auth-left__content { position: relative; z-index: 1; max-width: 380px; }

.auth-left__logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 2.5rem;
}
.auth-left__logo-icon {
  width: 48px;
  height: 48px;
  background: var(--color-primary);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
  font-weight: 900;
}
.auth-left__logo-mark {
  width: 26px;
  height: 26px;
  display: block;
}
.auth-left__logo-text {
  font-size: var(--text-xl);
  font-weight: 800;
  color: #fff;
}
.auth-left__logo-text span {
  display: block;
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--gray-400);
}

.auth-left__tagline {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  margin-bottom: 1rem;
}
.auth-left__tagline span { color: var(--color-primary-muted); }

.auth-left__desc {
  font-size: var(--text-sm);
  color: var(--gray-400);
  line-height: 1.7;
  margin-bottom: 2rem;
}

.auth-features { display: flex; flex-direction: column; gap: .75rem; }
.auth-feature {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: var(--text-sm);
  color: var(--gray-300);
}
.auth-feature__icon {
  width: 32px;
  height: 32px;
  background: rgba(79,70,229,.25);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: .9rem;
}

.auth-right {
  width: 480px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 3rem;
  background: var(--bg-card);
}

.auth-form-wrap {
  width: 100%;
  max-width: 380px;
}

.auth-form-wrap h1 {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: .375rem;
}
.auth-form-wrap p {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1rem 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-footer {
  text-align: center;
  margin-top: 1.25rem;
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.auth-footer a { color: var(--color-primary); font-weight: 500; }

/* ── 19. Grid-утилиты ────────────────────────────────────── */
.grid { display: grid; gap: 1.25rem; }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* ── 20. Утилиты ─────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-primary-color { color: var(--color-primary); }
.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.text-sm  { font-size: var(--text-sm); }
.text-xs  { font-size: var(--text-xs); }
.text-lg  { font-size: var(--text-lg); }
.fw-600   { font-weight: 600; }
.fw-700   { font-weight: 700; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }

.d-flex  { display: flex; }
.d-none  { display: none; }
.d-block { display: block; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .25rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}
.empty-state__icon { font-size: 3rem; margin-bottom: .75rem; opacity: .4; }
.empty-state__title { font-size: var(--text-lg); font-weight: 600; color: var(--text-primary); margin-bottom: .375rem; }
.empty-state__desc  { font-size: var(--text-sm); margin-bottom: 1.25rem; }

/* Лоадер */
.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Скелетон-загрузка */
.skeleton {
  background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, var(--gray-700) 25%, var(--gray-600) 50%, var(--gray-700) 75%);
  background-size: 200% 100%;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── 21. Адаптивность ────────────────────────────────────── */

/* Планшет (≤ 1024px) */
@media (max-width: 1024px) {
  .sidebar { width: var(--sidebar-collapsed-w); }
  .sidebar .sidebar__label,
  .sidebar .sidebar__logo-text,
  .sidebar .sidebar__section-title,
  .sidebar .sidebar__badge,
  .sidebar .sidebar__user-info { display: none; }
  .sidebar .sidebar__item { justify-content: center; padding: .6rem 0; }
  .sidebar .sidebar__user { justify-content: center; }
  .app-content { margin-left: var(--sidebar-collapsed-w); }

  .grid--4 { grid-template-columns: repeat(2, 1fr); }
  .grid--3 { grid-template-columns: repeat(2, 1fr); }
  .form-row--4 { grid-template-columns: 1fr 1fr; }
}

/* Мобильный (≤ 768px) */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
    box-shadow: var(--shadow-xl);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .sidebar .sidebar__label,
  .sidebar .sidebar__logo-text,
  .sidebar .sidebar__section-title,
  .sidebar .sidebar__badge,
  .sidebar .sidebar__user-info { display: block !important; }
  .sidebar .sidebar__item { justify-content: flex-start !important; padding: .6rem 1.25rem !important; }
  .sidebar .sidebar__user { justify-content: flex-start !important; }

  .app-content { margin-left: 0 !important; }

  .page-main { padding: 1rem; }

  .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
  .form-row--2, .form-row--3, .form-row--4 { grid-template-columns: 1fr; }

  .auth-left { display: none; }
  .auth-right { width: 100%; padding: 1.5rem; }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-box { min-width: unset; }

  .modal { max-width: 100%; margin: 0 1rem; }

  .topbar { padding: 0 1rem; }
}

/* Очень маленький (≤ 480px) */
@media (max-width: 480px) {
  .pagination { flex-direction: column; text-align: center; }
  .doc-totals { justify-content: stretch; }
  .doc-totals__table { width: 100%; min-width: unset; }
}

/* Мобильный оверлей сайдбара */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
}
@media (max-width: 768px) {
  .sidebar-overlay.active { display: block; }
}

/* ── 22. Страница 404 / ошибки ───────────────────────────── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 70vh;
  padding: 2rem;
}
.error-page__code {
  font-size: 7rem;
  font-weight: 900;
  color: var(--color-primary);
  line-height: 1;
  opacity: .15;
  margin-bottom: -1rem;
}
.error-page__title { font-size: var(--text-2xl); font-weight: 700; margin-bottom: .5rem; }
.error-page__desc  { color: var(--text-muted); max-width: 380px; margin-bottom: 1.5rem; }

/* ── 23. Прокрутка ───────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--gray-600); }

/* ── 24. Печать ──────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .page-actions, .filter-bar,
  .pagination, .btn, .modal-overlay { display: none !important; }
  .app-content { margin-left: 0 !important; }
  .card { border: none !important; box-shadow: none !important; }
}
