/* ============================================================
   Modena CRM — дизайн-система
   Палитра: глубокий слейт-тил + аквамарин (вода/сантехника)
   ============================================================ */

:root {
  /* Основные цвета */
  --ink: #0b2027;
  --ink-2: #12313c;
  --ink-3: #1c4452;
  --bg: #f2f6f7;
  --card: #ffffff;
  --line: #e1ebee;
  --line-soft: #edf3f5;

  --text: #14282f;
  --text-2: #4c6670;
  --text-3: #8aa2ab;

  /* Акцент */
  --aqua: #14b8a6;
  --aqua-600: #0d9488;
  --aqua-700: #0f766e;
  --aqua-soft: #e0f5f2;
  --aqua-glow: rgba(20, 184, 166, 0.35);

  /* Семантика */
  --green: #16a34a;
  --green-soft: #e7f6ec;
  --red: #e2483d;
  --red-soft: #fdecea;
  --amber: #d9820c;
  --amber-soft: #fdf1dc;
  --blue: #2e72d2;
  --blue-soft: #e8f0fc;
  --violet: #7c5cd6;
  --violet-soft: #f0ebfc;

  /* Тени и формы */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(11, 32, 39, 0.05), 0 1px 6px rgba(11, 32, 39, 0.05);
  --shadow-md: 0 2px 4px rgba(11, 32, 39, 0.05), 0 12px 28px -12px rgba(11, 32, 39, 0.14);
  --shadow-lg: 0 24px 60px -18px rgba(11, 32, 39, 0.28);

  --font-head: "Manrope", "Inter", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --sidebar-w: 264px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

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

h1, h2, h3, h4 { font-family: var(--font-head); color: var(--text); letter-spacing: -0.015em; }

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 14.5px; color: var(--text); }
a { color: inherit; text-decoration: none; }

/* ============================== КНОПКИ ============================== */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 14px; line-height: 1;
  transition: all .18s ease; white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn-primary {
  background: linear-gradient(135deg, var(--aqua) 0%, var(--aqua-600) 100%);
  color: #fff; box-shadow: 0 6px 16px -6px var(--aqua-glow), inset 0 1px 0 rgba(255,255,255,.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px -6px var(--aqua-glow), inset 0 1px 0 rgba(255,255,255,.25); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: var(--card); color: var(--text-2); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.btn-ghost:hover { border-color: var(--aqua); color: var(--aqua-700); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-icon { padding: 9px; border-radius: 10px; }
.btn-icon svg { width: 16px; height: 16px; }

/* ============================== ЛОГИН ============================== */

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1000px 600px at 85% -10%, rgba(20,184,166,.22), transparent 60%),
    radial-gradient(800px 500px at -10% 110%, rgba(46,114,210,.18), transparent 60%),
    linear-gradient(160deg, var(--ink) 0%, var(--ink-2) 55%, #0e2b35 100%);
  padding: 24px; position: relative; overflow: hidden;
}
.login-page::before {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 26px 26px; mask-image: radial-gradient(70% 70% at 50% 40%, #000, transparent);
}
.login-card {
  position: relative; width: 100%; max-width: 440px;
  background: rgba(255,255,255,.97); border-radius: 24px;
  box-shadow: var(--shadow-lg); padding: 40px 36px 32px;
  animation: rise .4s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-logo .mark {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--aqua) 0%, var(--aqua-700) 100%);
  color: #fff; box-shadow: 0 8px 20px -8px var(--aqua-glow);
}
.login-logo .mark svg { width: 24px; height: 24px; }
.login-logo b { font-family: var(--font-head); font-size: 21px; font-weight: 800; }
.login-logo b i { font-style: normal; color: var(--aqua-600); }
.login-sub { color: var(--text-2); margin: 10px 0 26px; font-size: 14.5px; }

.role-grid { display: grid; gap: 12px; margin-bottom: 18px; }
.role-card {
  display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 15px 16px; border-radius: var(--r-md);
  border: 1.5px solid var(--line); background: var(--card);
  transition: all .16s ease;
}
.role-card:hover { border-color: var(--aqua); box-shadow: 0 8px 20px -10px var(--aqua-glow); transform: translateY(-1px); }
.role-card.selected { border-color: var(--aqua-600); background: var(--aqua-soft); box-shadow: 0 8px 20px -10px var(--aqua-glow); }
.role-card .role-ico {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--aqua-soft); color: var(--aqua-700); flex-shrink: 0;
}
.role-card.selected .role-ico { background: var(--aqua-600); color: #fff; }
.role-card .role-ico svg { width: 21px; height: 21px; }
.role-card b { display: block; font-size: 14.5px; }
.role-card span { color: var(--text-3); font-size: 12.5px; }

.login-note {
  display: flex; gap: 9px; align-items: flex-start;
  background: var(--blue-soft); color: var(--blue); border-radius: var(--r-sm);
  padding: 11px 13px; font-size: 12.5px; line-height: 1.5; margin-top: 16px;
}
.login-note svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 2px; }

/* ============================== КАРКАС ============================== */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: linear-gradient(175deg, var(--ink) 0%, var(--ink-2) 60%, #123642 100%);
  color: #cfe3e8; display: flex; flex-direction: column;
  padding: 22px 16px 18px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 2px 10px 22px; }
.sidebar .brand .mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--aqua) 0%, var(--aqua-700) 100%);
  color: #fff; box-shadow: 0 8px 18px -8px var(--aqua-glow);
}
.sidebar .brand .mark svg { width: 21px; height: 21px; }
.sidebar .brand b { font-family: var(--font-head); font-size: 18px; font-weight: 800; color: #fff; display: block; line-height: 1.15; }
.sidebar .brand span { font-size: 11px; color: #7fa5b0; letter-spacing: .06em; text-transform: uppercase; }

.nav-group-label { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: #6d949f; padding: 14px 12px 8px; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 11px; color: #b7d2d9;
  font-weight: 500; font-size: 14px; transition: all .15s ease; position: relative;
}
.nav-item svg { width: 19px; height: 19px; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active {
  background: linear-gradient(135deg, rgba(20,184,166,.22), rgba(20,184,166,.10));
  color: #fff; box-shadow: inset 0 0 0 1px rgba(20,184,166,.35);
}
.nav-item.active svg { opacity: 1; color: var(--aqua); }
.nav-item .pill {
  margin-left: auto; background: rgba(20,184,166,.25); color: #7fe8da;
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
}

.sidebar-foot { margin-top: auto; padding-top: 16px; }
.user-card {
  display: flex; align-items: center; gap: 11px; padding: 11px 12px;
  background: rgba(255,255,255,.06); border-radius: var(--r-md);
  border: 1px solid rgba(255,255,255,.07);
}
.user-card .avatar {
  width: 37px; height: 37px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--aqua) 0%, var(--blue) 100%);
  color: #fff; font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-card b { display: block; font-size: 13px; color: #fff; line-height: 1.25; }
.user-card span { font-size: 11.5px; color: #8db3bc; }
.user-card .logout { margin-left: auto; color: #8db3bc; padding: 7px; border-radius: 8px; }
.user-card .logout:hover { background: rgba(255,255,255,.1); color: #fff; }
.user-card .logout svg { width: 16px; height: 16px; }

/* ============================== ГЛАВНАЯ ОБЛАСТЬ ============================== */

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

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 20px 32px 0;
}
.topbar .page-title h1 { font-size: 23px; font-weight: 800; }
.topbar .page-title p { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.topbar .spacer { flex: 1; }

.search-box {
  display: flex; align-items: center; gap: 9px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 11px; padding: 9px 14px; width: 260px;
  box-shadow: var(--shadow-sm); transition: border-color .15s;
}
.search-box:focus-within { border-color: var(--aqua); box-shadow: 0 0 0 3px rgba(20,184,166,.15); }
.search-box svg { width: 16px; height: 16px; color: var(--text-3); flex-shrink: 0; }
.search-box input { border: none; outline: none; background: none; width: 100%; }
.search-box input::placeholder { color: var(--text-3); }

.content { padding: 24px 32px 40px; }

/* ============================== КАРТОЧКИ ============================== */

.card {
  background: var(--card); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 22px 24px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.card-head h3 { font-size: 16px; font-weight: 700; }
.card-head .sub { color: var(--text-3); font-size: 12.5px; margin-top: 1px; }
.card-head .spacer { flex: 1; }

/* ============================== ДАШБОРД ============================== */

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.kpi {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  padding: 20px 22px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; top: 0; right: 0; width: 110px; height: 110px;
  background: radial-gradient(circle at top right, var(--kpi-glow, rgba(20,184,166,.12)), transparent 70%);
}
.kpi .kpi-top { display: flex; align-items: center; gap: 11px; margin-bottom: 12px; }
.kpi .kpi-ico {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0;
}
.kpi .kpi-ico svg { width: 20px; height: 20px; }
.kpi .kpi-label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.kpi .kpi-value { font-family: var(--font-head); font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.kpi .kpi-delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; margin-top: 7px; padding: 3px 9px; border-radius: 999px; }
.kpi .kpi-delta.up { background: var(--green-soft); color: var(--green); }
.kpi .kpi-delta.down { background: var(--red-soft); color: var(--red); }
.kpi .kpi-delta svg { width: 12px; height: 12px; }

.tint-aqua .kpi-ico { background: var(--aqua-soft); color: var(--aqua-700); }
.tint-blue .kpi-ico { background: var(--blue-soft); color: var(--blue); } .tint-blue { --kpi-glow: rgba(46,114,210,.12); }
.tint-violet .kpi-ico { background: var(--violet-soft); color: var(--violet); } .tint-violet { --kpi-glow: rgba(124,92,214,.12); }
.tint-amber .kpi-ico { background: var(--amber-soft); color: var(--amber); } .tint-amber { --kpi-glow: rgba(217,130,12,.12); }

.dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
.dash-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* График выручки */
.chart-wrap { padding-top: 6px; }
.chart-bars { display: flex; align-items: flex-end; gap: 14px; height: 190px; padding: 0 4px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; min-width: 0; }
.chart-bar-track { width: 100%; max-width: 46px; flex: 1; display: flex; align-items: flex-end; border-radius: 8px 8px 4px 4px; background: var(--line-soft); overflow: hidden; }
.chart-bar {
  width: 100%; border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, var(--aqua) 0%, var(--aqua-600) 100%);
  box-shadow: 0 4px 10px -4px var(--aqua-glow);
  transition: height .5s cubic-bezier(.2,.8,.2,1); min-height: 6px;
}
.chart-col.current .chart-bar { background: linear-gradient(180deg, var(--blue) 0%, #1d5bbf 100%); box-shadow: 0 4px 10px -4px rgba(46,114,210,.4); }
.chart-label { font-size: 11.5px; color: var(--text-3); font-weight: 500; }
.chart-value { font-size: 11px; color: var(--text-2); font-weight: 600; }

/* Воронка */
.funnel { display: flex; flex-direction: column; gap: 13px; }
.funnel-row { display: flex; flex-direction: column; gap: 5px; }
.funnel-meta { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; }
.funnel-meta b { font-size: 13px; }
.funnel-meta .sum { margin-left: auto; color: var(--text-2); font-weight: 600; font-size: 12.5px; }
.funnel-track { height: 9px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 999px; transition: width .5s ease; }

/* Списки */
.list-rows { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 4px; border-bottom: 1px solid var(--line-soft);
}
.list-row:last-child { border-bottom: none; }
.list-row .avatar {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0;
}
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-main b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .lr-main span { color: var(--text-3); font-size: 12px; }
.list-row .lr-sum { font-weight: 700; font-family: var(--font-head); font-size: 14px; white-space: nowrap; }

.rank-row { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line-soft); }
.rank-row:last-child { border-bottom: none; }
.rank-num {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--aqua-soft); color: var(--aqua-700); flex-shrink: 0;
}
.rank-row:nth-child(1) .rank-num { background: linear-gradient(135deg, #f5b942, #e29a1c); color: #fff; }
.rank-row:nth-child(2) .rank-num { background: linear-gradient(135deg, #c3cfd6, #9fb2bc); color: #fff; }
.rank-row:nth-child(3) .rank-num { background: linear-gradient(135deg, #d99b6c, #b97a4a); color: #fff; }
.rank-row .rank-main { flex: 1; min-width: 0; }
.rank-row .rank-main b { font-size: 13.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-row .rank-main span { color: var(--text-3); font-size: 12px; }
.rank-row .rank-sum { font-weight: 700; font-family: var(--font-head); white-space: nowrap; }

/* ============================== БЕЙДЖИ ============================== */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-aqua { background: var(--aqua-soft); color: var(--aqua-700); }
.badge-violet { background: var(--violet-soft); color: var(--violet); }
.badge-gray { background: var(--line-soft); color: var(--text-2); }

/* ============================== ТАБЛИЦЫ ============================== */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 13px 14px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #f7fbfc; }
.table .num { font-family: var(--font-head); font-weight: 700; white-space: nowrap; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }

.cell-main { display: flex; align-items: center; gap: 11px; min-width: 0; }
.cell-main .avatar {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.cell-main b { display: block; font-size: 13.5px; }
.cell-main span { color: var(--text-3); font-size: 12px; }

/* ============================== ФИЛЬТРЫ / ЧИПЫ ============================== */

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--card); border: 1px solid var(--line); color: var(--text-2);
  transition: all .15s ease;
}
.chip:hover { border-color: var(--aqua); color: var(--aqua-700); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }

/* ============================== КАНБАН ============================== */

.kanban-wrap { overflow-x: auto; padding-bottom: 12px; }
.kanban { display: flex; gap: 16px; min-width: 1080px; align-items: flex-start; }
.kb-col {
  flex: 1; min-width: 208px; background: #e9f0f2; border-radius: var(--r-lg);
  padding: 14px 12px; border: 1.5px solid transparent; transition: all .18s ease;
}
.kb-col.drag-over { border-color: var(--aqua); background: var(--aqua-soft); box-shadow: 0 10px 28px -12px var(--aqua-glow); }
.kb-col-head { display: flex; align-items: center; gap: 8px; padding: 2px 6px 12px; }
.kb-col-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.kb-col-head b { font-size: 13px; font-family: var(--font-head); }
.kb-col-head .count {
  margin-left: auto; background: rgba(11,32,39,.08); color: var(--text-2);
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
}
.kb-cards { display: flex; flex-direction: column; gap: 10px; min-height: 60px; }

.deal-card {
  background: var(--card); border-radius: var(--r-md); padding: 13px 14px;
  box-shadow: var(--shadow-sm); cursor: grab; border: 1px solid rgba(11,32,39,.05);
  transition: all .16s ease;
}
.deal-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.deal-card.dragging { opacity: .45; transform: rotate(2.5deg); cursor: grabbing; }
.deal-card .dc-title { font-weight: 600; font-size: 13px; line-height: 1.4; margin-bottom: 8px; }
.deal-card .dc-client { display: flex; align-items: center; gap: 7px; color: var(--text-2); font-size: 12px; margin-bottom: 10px; }
.deal-card .dc-client .avatar { width: 21px; height: 21px; border-radius: 7px; font-size: 9.5px; display: grid; place-items: center; color: #fff; font-weight: 700; }
.deal-card .dc-foot { display: flex; align-items: center; gap: 8px; }
.deal-card .dc-sum { font-family: var(--font-head); font-weight: 800; font-size: 14px; }
.deal-card .dc-date { margin-left: auto; color: var(--text-3); font-size: 11px; display: flex; align-items: center; gap: 4px; }
.deal-card .dc-date svg { width: 12px; height: 12px; }

/* ============================== МОДАЛКИ ============================== */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,32,39,.5);
  backdrop-filter: blur(3px); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade .18s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: pop .22s cubic-bezier(.2,.9,.3,1.2) both;
}
.modal.modal-lg { max-width: 760px; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(10px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--line-soft);
}
.modal-head h3 { font-size: 17px; font-weight: 800; }
.modal-head .close { margin-left: auto; color: var(--text-3); padding: 7px; border-radius: 9px; }
.modal-head .close:hover { background: var(--line-soft); color: var(--text); }
.modal-head .close svg { width: 18px; height: 18px; }
.modal-body { padding: 22px 24px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px 20px; border-top: 1px solid var(--line-soft);
}

/* ============================== ФОРМЫ ============================== */

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line); background: var(--card); outline: none;
  transition: all .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--aqua); box-shadow: 0 0 0 3px rgba(20,184,166,.15);
}
.field textarea { resize: vertical; min-height: 80px; }
.field .hint { color: var(--text-3); font-size: 11.5px; margin-top: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.kv-row { display: flex; gap: 8px; margin-bottom: 8px; }
.kv-row input { flex: 1; }
.kv-row .btn-icon { flex-shrink: 0; border: 1px solid var(--line); }

/* ============================== ТОСТЫ ============================== */

#toast-root { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 11px;
  background: var(--ink); color: #fff; padding: 13px 18px;
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  font-size: 13.5px; font-weight: 500; animation: slidein .25s ease both;
  max-width: 360px;
}
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success svg { color: #4ade80; }
.toast.error svg { color: #f87171; }
.toast.info svg { color: #60a5fa; }
@keyframes slidein { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
.toast.hide { opacity: 0; transform: translateX(18px); transition: all .25s ease; }

/* ============================== ПУСТЫЕ СОСТОЯНИЯ ============================== */

.empty {
  text-align: center; padding: 44px 20px; color: var(--text-3);
}
.empty .empty-ico {
  width: 62px; height: 62px; border-radius: 18px; margin: 0 auto 15px;
  background: var(--aqua-soft); color: var(--aqua-600); display: grid; place-items: center;
}
.empty .empty-ico svg { width: 28px; height: 28px; }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 5px; }
.empty p { font-size: 13px; max-width: 320px; margin: 0 auto; }

/* ============================== КП / ПЕЧАТЬ ============================== */

.quote-editor { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.quote-lines .line-row {
  display: grid; grid-template-columns: 42px 2fr 64px 96px 60px 104px 34px; gap: 9px;
  align-items: center; margin-bottom: 9px;
}
.quote-lines .line-row .btn-icon { color: var(--text-3); }
.quote-lines .line-row .btn-icon:hover { color: var(--red); background: var(--red-soft); }
.line-photo {
  width: 42px; height: 42px; border-radius: 10px; border: 1.5px dashed var(--line);
  background: var(--bg); color: var(--text-3); display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: pointer; padding: 0;
}
.line-photo img { width: 100%; height: 100%; object-fit: cover; }
.line-photo.empty:hover, .line-photo:hover { border-color: var(--aqua); color: var(--aqua); border-style: solid; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px; }
.photo-tile {
  aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 2px solid var(--line);
  padding: 0; cursor: pointer; background: var(--bg); display: block;
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile:hover { border-color: var(--aqua-600); }
.photo-tile.selected { border-color: var(--aqua); box-shadow: 0 0 0 3px var(--aqua-soft); }
.quote-totals { background: var(--bg); border-radius: var(--r-md); padding: 16px 18px; margin-top: 14px; }
.quote-totals .qt-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; color: var(--text-2); }
.quote-totals .qt-row.total {
  border-top: 1.5px dashed var(--line); margin-top: 8px; padding-top: 12px;
  font-family: var(--font-head); font-size: 18px; font-weight: 800; color: var(--text);
}
.quote-totals .qt-disc-row { align-items: center; gap: 12px; }
.quote-totals .qt-disc-row input {
  width: 76px; text-align: right; font-weight: 700;
  padding: 5px 9px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text); font-size: 13.5px;
}

.print-sheet {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 36px 40px; font-size: 13px;
}
.print-sheet .ps-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 20px;
  flex-wrap: wrap; min-width: 0;
  border-bottom: 2.5px solid var(--ink); padding-bottom: 16px; margin-bottom: 20px;
}
.print-sheet .ps-company { flex: 1 1 300px; min-width: 0; overflow-wrap: anywhere; }
.print-sheet .ps-company b { font-family: var(--font-head); font-size: 19px; display: block; }
.print-sheet .ps-company span { color: var(--text-2); font-size: 11.5px; display: block; line-height: 1.7; }
.print-sheet .ps-num { text-align: right; flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }
.print-sheet .ps-num b { font-family: var(--font-head); font-size: 17px; display: block; }
.print-sheet .ps-num span { color: var(--text-2); font-size: 11.5px; }
.print-sheet h4 { font-size: 13px; margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.print-sheet table { width: 100%; border-collapse: collapse; }
.print-sheet table th {
  background: var(--ink); color: #fff; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .05em; padding: 9px 11px; text-align: left;
}
.print-sheet table td { padding: 9px 11px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.print-sheet table tr:nth-child(even) td { background: #f7fafb; }
.print-sheet table td.ps-ph { width: 58px; }
.print-sheet table td.ps-ph img {
  width: 50px; height: 50px; object-fit: contain; border-radius: 6px;
  border: 1px solid var(--line); print-color-adjust: exact; -webkit-print-color-adjust: exact;
}
.print-sheet table td.ps-disc { width: 62px; white-space: nowrap; }
.print-sheet .ps-totals { margin: 16px 0 0 auto; width: min(320px, 100%); }
.print-sheet .ps-tot-row { display: flex; justify-content: space-between; gap: 14px; padding: 4px 0; font-size: 13px; color: var(--text-2); }
.print-sheet .ps-tot-row b { white-space: nowrap; }
.print-sheet .ps-tot-row.total {
  border-top: 1.5px dashed var(--line); margin-top: 6px; padding-top: 9px;
  font-family: var(--font-head); font-size: 16px; font-weight: 800; color: var(--text);
}
.print-sheet .ps-sign { display: flex; justify-content: space-between; gap: 30px; margin-top: 34px; }
.print-sheet .ps-sign > div { flex: 1; }
.print-sheet .ps-sign .sig-line { border-bottom: 1px solid var(--ink); height: 34px; }
.print-sheet .ps-sign small { color: var(--text-3); font-size: 10.5px; }
.print-sheet .ps-stamp {
  margin-top: 18px; text-align: center; color: var(--text-3); font-size: 10.5px;
  border-top: 1px dashed var(--line); padding-top: 12px;
}

@media print {
  body * { visibility: hidden; }
  .print-sheet, .print-sheet * { visibility: visible; }

  /* Модалка больше не влияет на печать: никаких fixed/absolute/scroll-контейнеров.
     Раньше .print-sheet позиционировался absolute внутри fixed-оверлея с
     overflow-y:auto — из-за этого шапка с реквизитами «съезжала» и обрезалась. */
  .modal-overlay, .modal, .modal form, .modal-body {
    position: static !important; inset: auto !important; float: none !important;
    display: block !important; overflow: visible !important;
    max-height: none !important; height: auto !important; width: auto !important;
    background: none !important; box-shadow: none !important; backdrop-filter: none !important;
    padding: 0 !important; margin: 0 !important; border: none !important;
    border-radius: 0 !important; animation: none !important; transform: none !important;
  }
  .modal-head, .modal-foot, .toast-root { display: none !important; }

  body { margin: 0; background: #fff; }
  .print-sheet {
    position: static; width: 100%; border: none; border-radius: 0; padding: 0;
  }

  /* Многостраничность: шапка/итоги не рвутся, шапка таблицы повторяется */
  .print-sheet .ps-head, .print-sheet .ps-totals, .print-sheet .ps-sign { page-break-inside: avoid; break-inside: avoid; }
  .print-sheet tr { page-break-inside: avoid; break-inside: avoid; }
  .print-sheet thead { display: table-header-group; }

  @page { margin: 12mm; }
}

/* ============================== АДАПТИВНОСТЬ ============================== */

.mobile-nav { display: none; }
.mobile-user { display: none; }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .quote-editor { grid-template-columns: 1fr; }
}

@media (max-width: 920px) {
  .sidebar { display: none; }
  .topbar { padding: 14px 16px 0; flex-wrap: wrap; gap: 12px; }
  .topbar .page-title h1 { font-size: 20px; }
  .topbar .page-title p { font-size: 12px; }
  .topbar .search-box { width: 100%; order: 3; }
  .content { padding: 16px 14px 96px; }

  /* Пользователь и выход — в шапке (сайдбар скрыт) */
  .mobile-user { display: flex; align-items: center; gap: 8px; order: 4; }
  .mu-avatar {
    width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--aqua) 0%, var(--blue) 100%);
    color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0;
  }
  .mu-logout {
    color: var(--text-2); padding: 9px; border-radius: 10px;
    background: var(--card); border: 1px solid var(--line);
  }
  .mu-logout:active { background: var(--line-soft); }
  .mu-logout svg { width: 17px; height: 17px; }

  /* Нижняя навигация */
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 90;
    background: var(--ink); padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    justify-content: center; flex-wrap: wrap; gap: 2px 0;
  }
  .mobile-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: #8db3bc; font-size: 10px; font-weight: 600; padding: 5px 8px; border-radius: 10px;
    flex: 1 1 28%; min-width: 60px;
  }
  .mobile-nav a svg { width: 20px; height: 20px; }
  .mobile-nav a.active { color: var(--aqua); }

  /* Формы и карточки */
  .form-row { grid-template-columns: 1fr; }
  .card-pad { padding: 16px; }
  .kpi .kpi-value { font-size: 22px; }
  .toolbar { gap: 8px; }
  /* iOS не зумит страницу при фокусе в поле */
  input, select, textarea { font-size: 16px; }

  /* Таблицы — горизонтальная прокрутка */
  table.table { min-width: 640px; }
  .table td { padding: 11px 12px; }

  /* Модальные окна — почти на весь экран */
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal { max-width: none; max-height: calc(100vh - 24px); border-radius: 16px; }
  .modal.modal-lg { max-width: none; }
  .modal-head { padding: 16px 16px 12px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px 16px; flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; min-height: 42px; }

  /* Выбор фото */
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }

  /* КП: печать и просмотр */
  .print-sheet .ps-head { flex-direction: column; gap: 10px; }
  .print-sheet .ps-num { text-align: left; }

  /* Вход */
  .login-card { padding: 28px 20px 24px; border-radius: 18px; }
}

@media (max-width: 640px) {
  .topbar .page-title h1 { font-size: 18px; }

  /* Строки КП: фото + название, затем количество / цена / сумма */
  .quote-lines .line-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 10px; border-bottom: 1px dashed var(--line-soft); }
  .quote-lines .line-photo { order: 0; flex: 0 0 42px; }
  .quote-lines .line-row input[data-field="name"] { order: 1; flex: 1 1 calc(100% - 100px); }
  .quote-lines .line-row .btn-icon { order: 2; }
  .quote-lines .line-row input[data-field="qty"] { order: 3; flex: 0 0 88px; margin-left: 50px; }
  .quote-lines .line-row input[data-field="price"] { order: 4; flex: 1 1 110px; }
  .quote-lines .line-row input[data-field="disc"] { order: 5; flex: 0 0 88px; }
  .quote-lines .line-row > div { order: 6; flex: 0 0 96px; }

  .kpi-grid { gap: 12px; }
  .kpi { padding: 15px 16px; }
  .kpi .kpi-value { font-size: 19px; }
  .chart-bars { gap: 8px; height: 160px; }
  .chart-value { font-size: 9.5px; }
  .chart-label { font-size: 10px; }
  .quote-totals .qt-row { font-size: 12.5px; }
}
