/* ============================================================
   CRM мебельной фабрики — «Премиальная мастерская»
   Тёплый белый, графит, терракота, орех. Скругления 12–16px.
   ============================================================ */

/* Inter Variable (SIL OFL 1.1, см. fonts/Inter-OFL-LICENSE.txt).
   Переменное начертание 100–900: веса 550/650 из макета не синтезируются.
   Подмножества latin и cyrillic разделены unicode-range — браузер тянет
   только нужное. */
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("fonts/inter-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("fonts/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Метрически совместимый фолбэк: пока Inter грузится, строки не «прыгают».
   Arial × 1.07 по ширине и высоте строки совпадает с Inter. */
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial"), local("Helvetica"), local("Liberation Sans");
  size-adjust: 107%;
}

:root {
  /* Палитра */
  --warm-white: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --graphite: #2b2b30;
  --graphite-soft: #4a4a52;
  --ink-muted: #6a6a72;
  --line: #e6dfd4;
  --terracotta: #b85c3e;
  --terracotta-soft: #f6e3da;
  --oak: #8c5a38;
  --oak-soft: #efe2d2;
  --green: #4e6b4e;
  --green-soft: #e2ece0;
  --gold: #9a7a2a;
  --gold-soft: #f3e8c8;
  --red: #b23a3a;
  --red-soft: #f6dddd;

  /* Типографика: Inter Variable из репозитория → метрически совместимый
     фолбэк (без прыжка подмены) → системный стек. */
  --font: "Inter Variable", "Inter Fallback", system-ui, -apple-system,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;

  /* Радиусы и тени */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(43, 43, 48, 0.06), 0 1px 3px rgba(43, 43, 48, 0.08);
  --shadow-md: 0 4px 12px rgba(43, 43, 48, 0.08), 0 2px 4px rgba(43, 43, 48, 0.06);
  --shadow-lg: 0 12px 32px rgba(43, 43, 48, 0.14), 0 4px 10px rgba(43, 43, 48, 0.08);

  /* Каркас */
  --sidebar-w: 16rem;
  --topbar-h: 3.5rem;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: var(--topbar-h); }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--graphite);
  background: var(--warm-white);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--terracotta); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
p { margin: 0; }

:focus-visible {
  outline: 3px solid rgba(184, 92, 62, 0.55);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--graphite);
  color: #fff;
  padding: 10px 16px;
  z-index: 1000;
  border-radius: 0 0 var(--r-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---------- Каркас ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100dvh;
}
/* Фон-затемнение для мобильного ящика: вне потока на десктопе, иначе
   занимал бы колонку грида и сдвигал сайдбар с контентом. */
.sidebar-backdrop { display: none; }

/* ---------- Сайдбар ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  gap: 0.25rem;
  position: sticky;
  top: 0;
  height: 100dvh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0.5rem 1rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--graphite);
}
.brand .brand-mark {
  width: 34px; height: 34px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--oak), var(--terracotta));
  color: #fff; border-radius: var(--r-sm);
}
.brand .brand-mark svg { width: 20px; height: 20px; }
.brand small { display: block; font-weight: 500; color: var(--ink-muted); font-size: 0.72rem; }

.nav-group { margin-top: 0.5rem; }
.nav-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  padding: 0.5rem 0.75rem 0.25rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--r-md);
  color: var(--graphite-soft);
  font-weight: 500;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-size: 0.95rem;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; color: var(--graphite); }
.nav-item.active {
  background: var(--terracotta-soft);
  color: var(--terracotta);
  font-weight: 650;
}
.nav-item .icon { width: 22px; height: 22px; flex: 0 0 auto; display: grid; place-items: center; }
.nav-item .icon svg { width: 22px; height: 22px; }
.nav-item .count { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 0.75rem; color: var(--ink-muted); }
.nav-item.active .count { color: var(--terracotta); }

.sidebar-footer { margin-top: auto; padding-top: 0.75rem; border-top: 1px solid var(--line); }

/* ---------- Топбар ---------- */
.content-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  background: rgba(250, 247, 242, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.burger {
  display: none;
  width: 44px; height: 44px;
  border: none; background: transparent; border-radius: var(--r-md);
  cursor: pointer; color: var(--graphite);
}
.burger:hover { background: var(--surface-2); }

.page-title { font-size: 1.25rem; font-weight: 650; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.user-chip {
  display: flex; align-items: center; gap: 0.55rem; min-width: 0;
  padding: 0.3rem 0.75rem 0.3rem 0.4rem;
  border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line); font-weight: 550; color: var(--graphite);
  white-space: nowrap;
}
.user-chip .avatar { width: 30px; height: 30px; border-radius: 50%; }
.user-chip .role { font-size: 0.72rem; color: var(--ink-muted); font-weight: 500; }

/* ---------- Основной контент ---------- */
main {
  min-width: 0;
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 3rem;
}
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.page-head h1 { font-size: 1.5rem; }
.page-head .subtitle { color: var(--ink-muted); margin-top: 0.15rem; font-size: 0.9rem; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  min-height: 42px; padding: 0.55rem 1.1rem;
  border-radius: var(--r-md); border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--graphite); color: #fff; }
.btn-primary:hover { background: #151518; box-shadow: var(--shadow-md); }
.btn-accent { background: var(--terracotta); color: #fff; }
.btn-accent:hover { background: #a34f34; box-shadow: var(--shadow-md); }
.btn-ghost { background: transparent; color: var(--graphite); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--red-soft); }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { min-height: 34px; padding: 0.3rem 0.8rem; font-size: 0.85rem; border-radius: var(--r-sm); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-title { font-size: 1.05rem; font-weight: 650; margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.5rem; }

/* ---------- Сетка виджетов ---------- */
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

.stat { display: flex; flex-direction: column; gap: 0.3rem; }
.stat .label { font-size: 0.82rem; color: var(--ink-muted); }
.stat .value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 0.8rem; font-weight: 600; }
.delta-up { color: var(--green); }
.delta-bad { color: var(--terracotta); }

/* ---------- Бейджи ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600; white-space: nowrap;
}
.badge-new { background: var(--oak-soft); color: var(--oak); }
.badge-measure { background: var(--gold-soft); color: var(--gold); }
.badge-proposal { background: #e3e7f2; color: #4a5a8a; }
.badge-contract { background: var(--green-soft); color: var(--green); }
.badge-production { background: var(--terracotta-soft); color: var(--terracotta); }
.badge-delivered { background: var(--green-soft); color: var(--green); }
.badge-closed { background: var(--surface-2); color: var(--ink-muted); }
.badge-paid { background: var(--green-soft); color: var(--green); }
.badge-pending { background: var(--gold-soft); color: var(--gold); }
.badge-draft { background: var(--surface-2); color: var(--ink-muted); }
.badge-approved { background: var(--green-soft); color: var(--green); }
.badge-rejected { background: var(--red-soft); color: var(--red); }
.badge-done { background: var(--green-soft); color: var(--green); }
.badge-progress { background: var(--gold-soft); color: var(--gold); }
.badge-low { background: var(--red-soft); color: var(--red); }

/* ---------- Таблица ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  text-align: left; font-weight: 600; color: var(--ink-muted);
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.7rem 0.9rem;
  box-shadow: inset 0 -1px 0 var(--line);
}
tbody td { padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Канбан ---------- */
.kanban { display: flex; gap: 1rem; align-items: flex-start; overflow-x: auto; padding-bottom: 1rem; }
.kanban-col {
  flex: 0 0 260px; max-width: 260px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 0.75rem;
  display: flex; flex-direction: column; gap: 0.6rem;
}
.kanban-col-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.82rem; font-weight: 650; color: var(--graphite-soft);
  padding: 0.1rem 0.2rem 0.4rem;
}
.kanban-col-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-muted); }
.kanban-cards { display: flex; flex-direction: column; gap: 0.6rem; min-height: 40px; }
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: 0.7rem 0.8rem;
  cursor: grab;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  position: relative;
  overflow: hidden;
}
.kanban-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kanban-card.dragging { opacity: 0.5; cursor: grabbing; }
.kanban-card.urgent { border-left: 4px solid var(--terracotta); }
.kanban-card.vip { border-left: 4px solid var(--gold); }
.kanban-card .num { font-size: 0.78rem; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.kanban-card .title { font-weight: 650; margin: 0.15rem 0; }
.kanban-card .meta { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--ink-muted); }
.kanban-card .amount { font-weight: 650; font-variant-numeric: tabular-nums; }
.kanban-empty { color: var(--ink-muted); font-size: 0.82rem; text-align: center; padding: 0.8rem 0.4rem; }
.kanban-col.drop-target { border-color: var(--terracotta); background: var(--terracotta-soft); }

/* ---------- Прогресс-бар (сегментированный) ---------- */
.segmented { display: flex; gap: 3px; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.segmented .seg { flex: 1; background: #e0d8cc; transition: background 0.2s; }
.segmented .seg.done { background: var(--green); }
.segmented .seg.active { background: var(--gold); }
.segmented .seg.blocked { background: var(--red); }

/* ---------- Формы ---------- */
.form-grid { display: grid; gap: 0.9rem; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) {
  .form-grid.cols-2 { grid-template-columns: 1fr; }
  /* На узком экране имя и роль пользователя теснят топбар — оставляем только аватар. */
  .user-chip span:not(.avatar) { display: none; }
  .user-chip { padding: 0.2rem; }
}
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.82rem; font-weight: 600; color: var(--graphite-soft); }
.field input, .field select, .field textarea {
  font: inherit; padding: 0.6rem 0.8rem; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface); color: var(--graphite);
  min-height: 42px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--terracotta); box-shadow: 0 0 0 3px rgba(184, 92, 62, 0.15);
}
.field textarea { min-height: 88px; resize: vertical; }
.field-error { color: var(--red); font-size: 0.8rem; }
.field input[aria-invalid="true"] { border-color: var(--red); }
.form-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1rem; }

/* ---------- Диалог ---------- */
dialog {
  border: none; border-radius: var(--r-lg); padding: 0;
  box-shadow: var(--shadow-lg); max-width: 560px; width: calc(100% - 2rem);
}
dialog::backdrop { background: rgba(43, 43, 48, 0.4); }
.dialog-body { padding: 1.5rem; }
.dialog-title { font-size: 1.15rem; font-weight: 650; margin-bottom: 1rem; }
dialog[open] { animation: pop 0.15s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Пустые состояния ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.6rem; padding: 2.5rem 1.5rem; color: var(--ink-muted); }
.empty .empty-art { width: 220px; max-width: 100%; }
.empty h3 { color: var(--graphite); font-size: 1.1rem; }
.empty p { max-width: 34ch; }

/* ---------- Вкладки ---------- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tab {
  padding: 0.6rem 1rem; border: none; background: transparent;
  font: inherit; font-weight: 550; color: var(--ink-muted);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--graphite); }
.tab.active { color: var(--terracotta); border-bottom-color: var(--terracotta); }

/* ---------- Уведомления/тост ---------- */
.toast {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 200;
  background: var(--graphite); color: #fff; border-radius: var(--r-md);
  padding: 0.8rem 1.2rem; box-shadow: var(--shadow-lg);
  animation: slide 0.2s ease; max-width: 360px;
}
.toast.error { background: var(--red); }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Скелетон ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, #ece5da 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--r-md); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Аватары-инициалы ---------- */
.avatar { display: grid; place-items: center; border-radius: 50%; font-weight: 700; color: #fff; flex: 0 0 auto; overflow: hidden; }
.avatar.av1 { background: linear-gradient(135deg, #c98a5a, #b85c3e); }
.avatar.av2 { background: linear-gradient(135deg, #7a9a7a, #4e6b4e); }
.avatar.av3 { background: linear-gradient(135deg, #a58a5a, #8c5a38); }
.avatar.av4 { background: linear-gradient(135deg, #8a8a9a, #5a5a6a); }
.avatar.av5 { background: linear-gradient(135deg, #c9a24b, #9a7a2a); }

/* ---------- Мобильный ---------- */
@media (max-width: 1023px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 100;
    transform: translateX(-100%); transition: transform 0.2s ease;
    height: 100dvh;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: none; }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(43,43,48,0.4); z-index: 90; }
  .burger { display: grid; place-items: center; }
  main { padding: 1rem; }
  .kanban-col { flex: 0 0 240px; max-width: 240px; }
}

/* ---------- Вход ---------- */
.login-page { display: grid; grid-template-columns: 1fr 1fr; min-height: 100dvh; }
.login-art {
  position: relative; overflow: hidden;
  background: linear-gradient(160deg, #2b2b30, #3a342d);
  display: grid; place-items: center;
}
.login-art svg { width: 100%; height: 100%; object-fit: cover; }
.login-panel { display: flex; flex-direction: column; justify-content: center; padding: clamp(1.5rem, 6vw, 4rem); }
.login-card { max-width: 420px; width: 100%; margin: 0 auto; }
.login-card h1 { font-size: 1.6rem; margin-bottom: 0.4rem; }
.login-card .sub { color: var(--ink-muted); margin-bottom: 1.5rem; }
@media (max-width: 900px) { .login-page { grid-template-columns: 1fr; } .login-art { display: none; } }

/* Утилиты */
.muted { color: var(--ink-muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.flex { display: flex; }
.between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
