/* ------------------------------------------------------------------
   Первичка — оформление
   Тёплая «бумажная» тема: графит, дуб, латунь.
   ------------------------------------------------------------------ */

:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #171b21;
  --ink-2: #3f4650;
  --muted: #7c828a;
  --line: #e8e3db;
  --line-strong: #d9d2c7;
  --sidebar: #14181e;
  --sidebar-2: #1b2029;
  --sidebar-ink: #c7ccd4;
  --sidebar-muted: #8a919c;
  --accent: #a85f1a;
  --accent-hover: #924f12;
  --accent-soft: #fbf1e3;
  --accent-line: #eedcc4;
  --ok: #1f7a4d;
  --ok-soft: #e9f5ee;
  --danger: #b3362c;
  --danger-soft: #fbeceb;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(23, 27, 33, 0.05);
  --shadow-md: 0 10px 30px -12px rgba(23, 27, 33, 0.22);
  --font: "Segoe UI", "Segoe UI Variable Text", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.modal-open { overflow: hidden; }

h1, h2, h3, p { margin: 0; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a { color: inherit; text-decoration: none; }

.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Каркас ---------- */

.app {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 22px 16px 18px;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 22px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, #c47a2b, #96520f);
  color: #1a130a;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 16px -6px rgba(196, 122, 43, 0.7);
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--sidebar-muted);
  margin-top: 2px;
}

.nav-label {
  padding: 0 10px;
  margin: 6px 0 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #6d7480;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--sidebar-ink);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: 0.85; }

.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

.nav-item.active {
  background: linear-gradient(90deg, rgba(196, 122, 43, 0.22), rgba(196, 122, 43, 0.07));
  border-color: rgba(196, 122, 43, 0.28);
  color: #f4d9b4;
}

.nav-item.active svg { opacity: 1; color: #d9932f; }

.nav-item.disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #c9a06a;
  background: rgba(201, 160, 106, 0.12);
  border: 1px solid rgba(201, 160, 106, 0.22);
  border-radius: 99px;
  padding: 1px 7px;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px 12px;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #343c48, #232a34);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #f0d6b3;
  font-size: 13px;
  font-weight: 700;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: #eef0f3;
  line-height: 1.25;
}

.user-role { font-size: 11.5px; color: var(--sidebar-muted); }

.nav-logout { color: #9aa1ac; font-size: 13px; }
.nav-logout:hover { color: #f0b8b2; background: rgba(179, 54, 44, 0.14); }

/* ---------- Основная область ---------- */

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 36px 16px;
  background: rgba(245, 243, 239, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.topbar .page-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-2);
  padding: 5px 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 99px;
}

.status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2f9e63;
  box-shadow: 0 0 0 3px rgba(47, 158, 99, 0.14);
}

.today { font-size: 12.5px; color: var(--muted); }

/* ---------- Вкладки ---------- */

.tabbar {
  position: sticky;
  top: var(--topbar-h, 69px);
  z-index: 19;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  padding: 8px 18px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.tabbar::-webkit-scrollbar { height: 5px; }
.tabbar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }

.tab {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  max-width: 250px;
  height: 35px;
  padding: 0 5px 0 11px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  color: var(--muted);
  background: transparent;
  transition: background 0.15s, color 0.15s;
}

.tab:hover { background: #ece8e1; color: var(--ink-2); }

.tab.active {
  position: relative;
  top: 1px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.75);
}

.tab-main {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

.tab-icon { display: grid; place-items: center; flex: 0 0 auto; opacity: 0.65; }
.tab-icon svg { width: 14px; height: 14px; }
.tab.active .tab-icon { opacity: 0.95; color: var(--accent); }

.tab-title {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-close {
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  margin-left: 4px;
  flex: 0 0 21px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: #9aa0a7;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.tab:hover .tab-close,
.tab.active .tab-close,
.tab-close:focus-visible { opacity: 1; }

.tab-close:hover { background: var(--danger-soft); color: var(--danger); }
.tab-close svg { width: 12px; height: 12px; }

.view {
  padding: 28px 36px 64px;
  width: 100%;
  max-width: 1240px;
  animation: rise 0.24s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Заголовки разделов ---------- */

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.section-head h2 { font-size: 26px; font-weight: 700; letter-spacing: -0.025em; }
.section-head .lead { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

/* ---------- Карточки статистики ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
}

.stat-value {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 6px;
  line-height: 1.1;
}

.stat-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: 0 0 38px;
}

.stat-icon svg { width: 19px; height: 19px; }
.stat-icon.amber { background: var(--accent-soft); color: var(--accent); }
.stat-icon.blue { background: #edf2fb; color: #3b5b9a; }
.stat-icon.green { background: var(--ok-soft); color: var(--ok); }
.stat-icon.gray { background: #f1efec; color: #6b6f76; }

/* ---------- Панели ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 18px;
}

.panel-flush { padding: 0; overflow: hidden; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-head h3 { font-size: 15.5px; font-weight: 700; }
.panel-head p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.panel-body { padding: 20px; }

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title-row h3 { font-size: 15px; font-weight: 700; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn svg { width: 17px; height: 17px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, #bb6f27, #a85f1a);
  color: #fff;
  border-color: #96520f;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 2px 6px -2px rgba(168, 95, 26, 0.55);
}

.btn-primary:hover { background: linear-gradient(180deg, #ad6522, #924f12); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover { background: var(--surface-2); border-color: #c9c0b3; }

.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: #efece6; }

.btn-danger { background: var(--danger); color: #fff; border-color: #9c2c23; }
.btn-danger:hover { background: #a02c24; }

.btn-block { width: 100%; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: #efece6; color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Инструменты над таблицей ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
}

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 42px;
  padding: 0 14px 0 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search input::placeholder { color: #a3a8ae; }

.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(168, 95, 26, 0.13);
}

.toolbar .spacer { flex: 1; }

.toolbar-count {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- Таблицы ---------- */

.table-wrap { overflow-x: auto; }

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

.table thead th {
  text-align: left;
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: #fcf9f4; }

.table .right { text-align: right; }
.table .strong { font-weight: 600; }
.table .cell-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .icon-btn { vertical-align: middle; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: #f1efec;
  color: #5f646c;
  border: 1px solid #e4e0da;
  white-space: nowrap;
}

.tag.company { background: #eef2f9; color: #40598c; border-color: #dde5f3; }
.tag.ip { background: #f3f0fa; color: #5c4a8a; border-color: #e5def5; }
.tag.person { background: #eef7f1; color: #33714f; border-color: #dcefe3; }

.tag-soon {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  color: #a85f1a;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
}

/* ---------- Пустые состояния ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 52px 24px;
  color: var(--muted);
}

.empty .empty-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 4px;
}

.empty .empty-icon svg { width: 24px; height: 24px; }
.empty h3 { font-size: 15px; color: var(--ink); font-weight: 600; }
.empty p { font-size: 13px; max-width: 380px; }
.empty .btn { margin-top: 10px; }

/* ---------- Быстрые действия ---------- */

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.quick {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.quick:hover { border-color: var(--accent-line); background: #fdfaf6; transform: translateY(-1px); }

.quick .quick-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}

.quick .quick-icon svg { width: 17px; height: 17px; }
.quick .quick-title { font-size: 13px; font-weight: 600; }
.quick .quick-sub { font-size: 11.5px; color: var(--muted); }
.quick-text { display: flex; flex-direction: column; gap: 1px; text-align: left; min-width: 0; }

/* ---------- Воронка продаж ---------- */

.stage-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stage-stat {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  box-shadow: var(--shadow-sm);
}

.stage-name {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage-value { font-size: 14.5px; font-weight: 700; margin-top: 1px; }

.stage-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; }
.stage-dot.work { background: #c07a22; box-shadow: 0 0 0 3px rgba(192, 122, 34, 0.14); }
.stage-dot.done { background: #1f7a4d; box-shadow: 0 0 0 3px rgba(31, 122, 77, 0.14); }
.stage-dot.lost { background: #b3362c; box-shadow: 0 0 0 3px rgba(179, 54, 44, 0.14); }
.stage-dot.not_done { background: #8b9099; box-shadow: 0 0 0 3px rgba(139, 144, 153, 0.16); }

.kanban {
  display: grid;
  grid-template-columns: repeat(4, minmax(240px, 1fr));
  gap: 14px;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 6px;
}

.kanban-col {
  background: #f1eee8;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  min-height: 220px;
}

.kanban-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 10px;
}

.kanban-title { font-size: 12.5px; font-weight: 700; letter-spacing: -0.01em; }

.kanban-count {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  background: #e6e1d8;
  border-radius: 99px;
  padding: 1px 7px;
}

.kanban-sum { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--muted); }

.kanban-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 96px;
  padding: 2px;
  border-radius: 10px;
  outline: 2px dashed transparent;
  outline-offset: -2px;
  transition: background 0.15s, outline-color 0.15s;
}

.kanban-list.drag-over {
  background: var(--accent-soft);
  outline-color: var(--accent-line);
}

.kanban-list:empty::before {
  content: "Перетащите сделку сюда";
  display: block;
  padding: 24px 10px;
  text-align: center;
  font-size: 11.5px;
  color: #a39a8c;
  border: 1px dashed var(--line-strong);
  border-radius: 9px;
}

.deal-card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 11px;
  box-shadow: 0 1px 2px rgba(23, 27, 33, 0.05);
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.deal-card:hover { border-color: var(--accent-line); box-shadow: 0 8px 18px -12px rgba(23, 27, 33, 0.35); }
.deal-card:active { cursor: grabbing; }
.deal-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.deal-card.dragging { opacity: 0.45; transform: rotate(1.5deg); }

.deal-card-top { display: flex; align-items: flex-start; gap: 5px; }

.deal-title {
  flex: 1;
  min-width: 0;
  font-size: 12.8px;
  font-weight: 600;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.deal-del {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  display: grid;
  place-items: center;
  border: none;
  background: none;
  border-radius: 6px;
  color: #a9aeb5;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.deal-card:hover .deal-del, .deal-del:focus-visible { opacity: 1; }
.deal-del:hover { background: var(--danger-soft); color: var(--danger); }
.deal-del svg { width: 13px; height: 13px; }

.deal-client {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deal-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 7px; }
.deal-amount { font-size: 12.5px; font-weight: 700; }

.deal-user {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eee9e1;
  border: 1px solid #e2dbd0;
  color: #6d6355;
  font-size: 9.5px;
  font-weight: 700;
}

.deal-due { margin-top: 7px; font-size: 10.5px; color: #8a7f70; }
.deal-due.overdue { color: var(--danger); font-weight: 600; }

/* ---------- Список состояния ---------- */

.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--ink-2);
}

.checklist li:last-child { border-bottom: none; }
.checklist li svg { width: 17px; height: 17px; flex: 0 0 17px; margin-top: 1px; }
.checklist li b { color: var(--ink); font-weight: 600; }
.checklist li.done svg { color: var(--ok); }
.checklist li.next { color: var(--muted); }
.checklist li.next svg { color: #b8a68f; }

/* ---------- Формы ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--muted); }

.input, .select, .textarea {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 76px; }

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(168, 95, 26, 0.13);
}

.input.invalid, .select.invalid { border-color: var(--danger); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }

.form-error {
  display: none;
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--danger-soft);
  border: 1px solid #f0cbc8;
  color: #8e2a22;
  font-size: 12.5px;
}

.form-error.visible { display: block; }

.sync-server {
  font-size: 15px;
  font-weight: 700;
  word-break: break-all;
  margin-top: 4px;
}

.sync-hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

/* ---------- Модальные окна ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 20px 20px;
  background: rgba(17, 21, 27, 0.46);
  backdrop-filter: blur(3px);
  animation: fade 0.16s ease both;
  overflow-y: auto;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 30px 70px -20px rgba(10, 13, 18, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.4);
  animation: pop 0.18s ease both;
  margin-bottom: 20px;
}

.modal form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.modal-body {
  padding: 20px 24px 4px;
  overflow-y: auto;
  min-height: 0;
}

.modal.narrow { max-width: 480px; }

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.modal-head p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 22px;
  border-top: 1px solid var(--line);
  margin-top: 10px;
}

.modal-note {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 13px;
  margin-bottom: 12px;
}

/* ---------- Уведомления ---------- */

.toasts {
  position: fixed;
  top: 74px;
  right: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
  padding: 11px 14px;
  border-radius: 11px;
  background: #171b21;
  color: #f2f4f7;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  animation: toast-in 0.22s ease both;
}

.toast svg { width: 17px; height: 17px; flex: 0 0 17px; }
.toast.ok svg { color: #6bd39a; }
.toast.err svg { color: #f08d82; }
.toast.out { animation: toast-out 0.2s ease both; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateX(14px); }
}

/* ---------- Вход ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 520px at 12% 8%, rgba(196, 122, 43, 0.2), transparent 62%),
    radial-gradient(760px 460px at 88% 92%, rgba(70, 110, 86, 0.14), transparent 60%),
    linear-gradient(160deg, #171c23, #10141a 70%);
}

.login-card {
  width: 100%;
  max-width: 398px;
  background: var(--surface);
  border-radius: 20px;
  padding: 30px 30px 26px;
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.65);
  animation: pop 0.25s ease both;
}

.login-card .brand { padding: 0 0 20px; }
.login-card .brand-title { color: var(--ink); }
.login-card .brand-sub { color: var(--muted); }

.login-card h1 { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; }
.login-card .lead { color: var(--muted); font-size: 13px; margin: 3px 0 20px; }

.login-card .field { margin-bottom: 13px; }
.login-card .btn { height: 44px; margin-top: 6px; }

.login-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

.login-error {
  display: none;
  margin: 2px 0 12px;
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--danger-soft);
  border: 1px solid #f0cbc8;
  color: #8e2a22;
  font-size: 12.5px;
}

.login-error.visible { display: block; }

/* ---------- Ошибка загрузки ---------- */

.fatal {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 10px;
  padding: 24px;
}

.fatal h2 { font-size: 18px; }
.fatal p { color: var(--muted); max-width: 460px; font-size: 13px; }

/* ---------- Мобильная версия ---------- */

.mobile-only { display: none; }
.overlay { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 264px;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: 20px 0 50px -20px rgba(0, 0, 0, 0.5);
  }

  .app.menu-open .sidebar { transform: none; }

  .overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(17, 21, 27, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .app.menu-open .overlay { opacity: 1; pointer-events: auto; }

  .mobile-only { display: inline-grid; }

  .topbar { padding: 14px 18px; }
  .topbar h1 { font-size: 18px; }
  .today { display: none; }
  .tabbar { padding: 6px 12px 0; }
  .tab { max-width: 190px; height: 33px; }
  .view { padding: 20px 18px 60px; }

  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stage-summary { grid-template-columns: 1fr 1fr; }
  .quick-grid { grid-template-columns: 1fr; }
  .section-head { flex-direction: column; align-items: stretch; }
  .section-head h2 { font-size: 22px; }
  .toolbar { flex-wrap: wrap; }
  .search { max-width: none; flex-basis: 100%; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
  .stage-summary { grid-template-columns: 1fr; }
  .modal-overlay { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; max-width: none; margin: 0; }
  .login-card { padding: 24px 20px; }
}

@media print {
  .sidebar, .topbar, .toasts, .modal-overlay { display: none !important; }
  .app { display: block; }
  .view { padding: 0; max-width: none; }
}
