/* ==========================================================================
   KRUTI ERP — дизайн-система
   Токени → база → layout → компоненти → сторінки → адаптив
   ========================================================================== */

:root {
  --bg: #eef0fb;
  --surface: #ffffff;
  --surface-2: #f5f6fd;
  --surface-3: #eaecfa;
  --line: #e5e7f3;
  --line-2: #d4d8ee;
  --text: #191b2e;
  --text-2: #4a4e6a;
  --muted: #8a8fab;
  --primary: #4f54e0;
  --primary-600: #4045c8;
  --primary-50: #eef0ff;
  --primary-100: #dfe2ff;
  --on-primary: #ffffff;
  --accent: #f0476b;
  --success: #15a05a;
  --success-50: #e4f6eb;
  --warning: #b86e05;
  --warning-50: #fdf1dc;
  --danger: #dc2750;
  --danger-50: #fde7ec;
  --radius: 18px;
  --radius-md: 13px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(35, 40, 110, .05), 0 10px 30px -14px rgba(35, 40, 110, .18);
  --shadow-lg: 0 24px 60px -20px rgba(25, 30, 90, .38);
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Consolas, 'Liberation Mono', monospace;
  --sidebar: 256px;
  --tabbar: 64px;
  --gap: 22px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0e1022;
  --surface: #171a33;
  --surface-2: #1f2343;
  --surface-3: #282d55;
  --line: #292e53;
  --line-2: #3a4070;
  --text: #eceefe;
  --text-2: #b8bce0;
  --muted: #8287b1;
  --primary: #767bff;
  --primary-600: #8c90ff;
  --primary-50: #23275f;
  --primary-100: #30357c;
  --success: #3bc983;
  --success-50: #12321f;
  --warning: #f0a534;
  --warning-50: #352812;
  --danger: #ff5f7f;
  --danger-50: #3d1623;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px -14px rgba(0, 0, 0, .65);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

/* ---------- база ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 500 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.02em; }
p { margin: 0 0 10px; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
code, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
pre.code { background: var(--surface-2); border-radius: 12px; padding: 14px 16px; overflow-x: auto; font: 13px/1.55 var(--mono); margin: 0; white-space: pre; }
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 800; }
.nowrap { white-space: nowrap; }
.ml-auto { margin-left: auto; }
.mt { margin-top: 16px; }
.mt-s { margin-top: 8px; }
.mb { margin-bottom: 16px; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.center { text-align: center; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  background: var(--surface);
  padding: 26px 18px 18px;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto; z-index: 70;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 26px; color: var(--text); font-weight: 800; font-size: 22px; letter-spacing: -.02em; line-height: 1.1; }
.brand small { display: block; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; margin-top: 3px; }
.logo { position: relative; width: 34px; height: 34px; flex: none; }
.logo::before, .logo::after { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; }
.logo::before { left: 0; top: 0; background: var(--primary); }
.logo::after { right: 0; bottom: 0; background: var(--accent); opacity: .92; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav button {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 11px 12px; border: 0; border-radius: 12px;
  background: none; color: var(--text-2); font-weight: 600; text-align: left; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { color: var(--primary); background: var(--primary-50); }
.nav .count { margin-left: auto; font-size: 12px; font-weight: 800; min-width: 22px; height: 22px; border-radius: 99px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; padding: 0 6px; }
.nav-sep { height: 1px; background: var(--line); margin: 14px 10px; }
.sidebar-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 10px 0; border-top: 1px solid var(--line); }
.sidebar-user b { display: block; font-size: 14px; }
.sidebar-user span { font-size: 12px; color: var(--muted); }

.toggle { position: relative; width: 38px; height: 22px; flex: none; border-radius: 99px; box-shadow: inset 0 0 0 2px var(--primary); margin-left: auto; transition: background .2s; }
.toggle::after { content: ""; position: absolute; top: 4px; left: 4px; width: 14px; height: 14px; border-radius: 50%; background: var(--primary); transition: left .2s, background .2s; }
:root[data-theme="dark"] .toggle { background: var(--primary); }
:root[data-theme="dark"] .toggle::after { left: 20px; background: #fff; }

.drawer-backdrop { display: none; }

.main { padding: 28px 36px 56px; min-width: 0; }

.topbar { display: flex; align-items: center; gap: 18px; margin-bottom: 26px; }
.topbar-title { min-width: 0; }
.topbar .hello { font-size: 13px; font-weight: 600; color: var(--muted); }
.topbar h1 { font-size: 30px; font-weight: 800; line-height: 1.15; margin-top: 2px; overflow-wrap: anywhere; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.search {
  display: flex; align-items: center; gap: 10px;
  height: 48px; width: min(420px, 34vw); padding: 0 6px 0 16px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); color: var(--muted);
  margin-left: auto;
}
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: 0; color: var(--text); }
.search + .topbar-actions { margin-left: 0; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-weight: 800; font-size: 15px;
}
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.menu-btn { display: none !important; }

/* ---------- сітка ---------- */
.grid { display: grid; gap: var(--gap); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); align-items: start; }
.stack { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-nw { display: flex; align-items: center; gap: 10px; min-width: 0; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- картки ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-title { font-size: 18px; font-weight: 800; color: var(--primary); }
.card-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.card-flat { background: var(--surface-2); border-radius: var(--radius-md); padding: 16px; }
.big-num { font-size: 34px; font-weight: 800; color: var(--primary); letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface-2); border-radius: var(--radius-md); padding: 14px 16px; min-width: 0; }
.kpi span { display: block; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kpi b { display: block; font-size: 21px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi.accent { background: var(--primary-50); }
.kpi.accent b { color: var(--primary); }

.card-gradient {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #7075f5 0%, #4f54e0 55%, #3a3fc2 100%);
  color: #fff; border-radius: 18px; padding: 22px;
  box-shadow: 0 18px 40px -18px #4f54e0;
}
.card-gradient::after { content: ""; position: absolute; right: -50px; top: -60px; width: 200px; height: 200px; border-radius: 50%; background: rgba(255, 255, 255, .08); }
.card-gradient .cg-top { display: flex; align-items: center; justify-content: space-between; font-weight: 700; }
.card-gradient .cg-num { font-size: 32px; font-weight: 800; letter-spacing: .04em; margin: 22px 0 16px; font-variant-numeric: tabular-nums; }
.card-gradient .cg-foot { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; opacity: .9; }
.dots { display: flex; }
.dots i { width: 26px; height: 26px; border-radius: 50%; background: rgba(255, 255, 255, .5); }
.dots i + i { margin-left: -10px; background: rgba(255, 255, 255, .8); }

/* ---------- кнопки ---------- */
.btn {
  --h: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h); padding: 0 18px;
  border: 0; border-radius: 11px;
  background: var(--surface-2); color: var(--text);
  font-weight: 700; font-size: 15px; line-height: 1;
  cursor: pointer; white-space: nowrap; user-select: none; text-decoration: none;
  transition: background .15s, box-shadow .15s, transform .1s, color .15s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 8px 18px -10px var(--primary); }
.btn-primary:hover { background: var(--primary-600); }
.btn-outline { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-2); }
.btn-outline:hover { background: transparent; box-shadow: inset 0 0 0 1.5px var(--primary); color: var(--primary); }
.btn-soft { background: var(--primary-50); color: var(--primary); }
.btn-soft:hover { background: var(--primary-100); }
.btn-danger { background: var(--danger-50); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: none; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-lg { --h: 56px; font-size: 17px; border-radius: 14px; padding: 0 24px; }
.btn-sm { --h: 34px; font-size: 13px; padding: 0 12px; border-radius: 9px; }
.btn-icon { width: var(--h); padding: 0; }
.btn-block { width: 100%; }
.btn .i { width: 19px; height: 19px; }

/* ---------- форми ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 700; color: var(--text-2); }
.hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; height: 46px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--text); outline: 0;
  transition: border-color .15s, box-shadow .15s;
}
.select { padding-right: 34px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.textarea { height: auto; min-height: 90px; padding: 12px 14px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }
.input.sm { height: 38px; border-radius: 9px; padding: 0 10px; }
.input-group { display: flex; gap: 8px; }
.input-group > .input, .input-group > .field { flex: 1; min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; min-height: 32px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); flex: none; margin: 0; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
fieldset.card { border: 0; margin: 0; }
.section-title { font-size: 15px; font-weight: 800; margin: 4px 0 12px; display: flex; align-items: center; gap: 8px; }

/* ---------- списки ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.li {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
  color: inherit; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
a.li:hover { border-color: var(--primary-100); box-shadow: var(--shadow); }
.li-body { flex: 1; min-width: 0; }
.li-title { font-weight: 700; color: var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-title.plain { color: var(--text); }
.li-title.wrap { white-space: normal; }
.li-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-end { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.li-end b { font-variant-numeric: tabular-nums; }
.thumb { width: 48px; height: 48px; border-radius: 12px; background: var(--surface-2); color: var(--primary); display: grid; place-items: center; flex: none; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.lg { width: 96px; height: 96px; border-radius: 16px; }
.thumb.lg .i { width: 36px; height: 36px; }
.ico-round { width: 42px; height: 42px; border-radius: 50%; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; flex: none; }
.ico-round.success { background: var(--success-50); color: var(--success); }
.ico-round.danger { background: var(--danger-50); color: var(--danger); }
.ico-round.warning { background: var(--warning-50); color: var(--warning); }

/* ---------- бейджі, чіпи ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge .i { width: 14px; height: 14px; }
.badge-success { background: var(--success-50); color: var(--success); }
.badge-warning { background: var(--warning-50); color: var(--warning); }
.badge-danger { background: var(--danger-50); color: var(--danger); }
.badge-primary { background: var(--primary-50); color: var(--primary); }
.badge-solid { background: var(--primary); color: var(--on-primary); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: -2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 10px; background: var(--surface); color: var(--text-2); font-weight: 700; font-size: 14px; white-space: nowrap; box-shadow: inset 0 0 0 1.5px var(--line); flex: none; }
.chip:hover { color: var(--primary); }
.chip.active { background: var(--primary); color: var(--on-primary); box-shadow: none; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: var(--gap); flex-wrap: wrap; }
.toolbar .chips { flex: 1; min-width: 0; }
.toolbar .cat-filter { flex: 0 1 280px; min-width: 0; }
.field-search { position: relative; display: block; flex: 1 1 320px; min-width: 0; }
.field-search .i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.field-search .input { padding-left: 42px; }
.live-loading { opacity: .55; transition: opacity .15s; pointer-events: none; }
.search { position: relative; }
.global-suggest { top: calc(100% + 8px); max-height: min(70vh, 560px); z-index: 80; }
.sg-title { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 10px 10px 4px; }
.sg-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; color: var(--text); min-width: 0; }
.sg-item:hover, .sg-item.sel { background: var(--surface-2); }
.thumb.sm { width: 38px; height: 38px; border-radius: 10px; }
.thumb.sm .i { width: 18px; height: 18px; }
@media (max-width: 860px) {
  .toolbar .chips { flex: 1 1 100%; }
  .toolbar .field-search, .toolbar .cat-filter { flex: 1 1 calc(100% - 60px); }
}

/* ---------- таблиці ---------- */
.table-wrap { overflow-x: auto; margin: 0 -6px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- сповіщення ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px; border-radius: 14px; font-weight: 600; margin-bottom: 18px; background: var(--primary-50); color: var(--primary); overflow-wrap: anywhere; }
.alert-error { background: var(--danger-50); color: var(--danger); }
.alert-success { background: var(--success-50); color: var(--success); }
.alert-warning { background: var(--warning-50); color: var(--warning); }
.toasts { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 13px 16px; border-radius: 14px; background: var(--text); color: var(--surface); font-weight: 700; box-shadow: var(--shadow-lg); animation: toast-in .25s ease; pointer-events: auto; }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }

/* ---------- модальні вікна (bottom sheet на телефоні) ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 150; background: rgba(15, 17, 40, .45); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .2s; }
.sheet { width: min(520px, 100%); max-height: min(88vh, 780px); overflow: auto; background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg); padding: 22px; animation: pop .22s ease; }
.sheet.wide { width: min(720px, 100%); }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.sheet-title { font-size: 19px; font-weight: 800; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }

.dropdown { position: relative; }
.dropdown > summary { list-style: none; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 60; }
.dropdown-menu form { margin: 0; }
.dropdown-menu button, .dropdown-menu a { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border: 0; background: none; border-radius: 10px; font-weight: 600; color: var(--text); cursor: pointer; text-align: left; }
.dropdown-menu button:hover, .dropdown-menu a:hover { background: var(--surface-2); color: var(--primary); }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--primary-100); border-top-color: var(--primary); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .ico-round { width: 60px; height: 60px; margin: 0 auto 12px; }
.empty .ico-round .i { width: 28px; height: 28px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.pager { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; background: var(--surface); color: var(--text-2); padding: 0 10px; box-shadow: var(--shadow); }
.pager .cur { background: var(--primary); color: var(--on-primary); }

/* ---------- графік, кільце ---------- */
.chart { width: 100%; height: auto; display: block; margin-top: 8px; overflow: visible; }
.chart-labels { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text-2); font-weight: 700; margin-top: 10px; }
.chart-labels .badge-solid { border-radius: 7px; }
.ring { --p: 0; width: 132px; height: 132px; border-radius: 50%; flex: none; background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--primary-50) 0); display: grid; place-items: center; }
.ring > div { width: 110px; height: 110px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; line-height: 1.1; }
.ring small { display: block; font-size: 13px; color: var(--text-2); font-weight: 600; }
.ring b { font-size: 28px; font-weight: 800; }

/* ---------- дії (як "Tasks" з макета) ---------- */
.actions-list { display: flex; flex-direction: column; gap: 10px; }
.actions-list form { margin: 0; }
.action {
  display: flex; align-items: center; gap: 12px; width: 100%;
  height: 48px; padding: 0 14px; border-radius: 10px;
  border: 1.5px solid var(--line-2); background: var(--surface); color: var(--text-2);
  font-weight: 600; cursor: pointer; text-align: left;
  transition: border-color .15s, color .15s, background .15s;
}
.action:hover, .action.primary { border-color: var(--primary); color: var(--primary); }
.action.primary { background: var(--primary-50); }
.action .i { color: var(--primary); }
.action .ml-auto { color: var(--muted); }

/* ---------- сканер ---------- */
.scanner { position: fixed; inset: 0; z-index: 300; background: #000; color: #fff; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-top { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 14px 14px; background: linear-gradient(rgba(0, 0, 0, .65), transparent); }
.scan-title { flex: 1; font-weight: 700; text-align: center; font-size: 15px; }
.scan-btn { width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .18); color: #fff; display: grid; place-items: center; backdrop-filter: blur(6px); cursor: pointer; }
.scan-btn.on { background: #fff; color: #111; }
.scan-btn[hidden] + * , .scan-top .spacer { width: 46px; }
.scan-frame {
  position: absolute; left: 50%; top: 42%; z-index: 1;
  width: min(80vw, 360px); aspect-ratio: 1.55; transform: translate(-50%, -50%);
  border-radius: 20px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
  background:
    linear-gradient(#fff, #fff) left top / 34px 4px, linear-gradient(#fff, #fff) left top / 4px 34px,
    linear-gradient(#fff, #fff) right top / 34px 4px, linear-gradient(#fff, #fff) right top / 4px 34px,
    linear-gradient(#fff, #fff) left bottom / 34px 4px, linear-gradient(#fff, #fff) left bottom / 4px 34px,
    linear-gradient(#fff, #fff) right bottom / 34px 4px, linear-gradient(#fff, #fff) right bottom / 4px 34px;
  background-repeat: no-repeat;
  transition: box-shadow .2s;
}
.scan-frame.hit { box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45), inset 0 0 0 4px var(--success); }
.scan-laser { position: absolute; left: 7%; right: 7%; top: 50%; height: 2px; background: var(--accent); box-shadow: 0 0 14px 2px var(--accent); animation: laser 1.8s ease-in-out infinite; border-radius: 2px; }
@keyframes laser { 0%, 100% { top: 16%; } 50% { top: 84%; } }
.scan-msg { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; text-align: center; padding: 24px; font-weight: 600; font-size: 16px; line-height: 1.5; }
.scan-msg > div { max-width: 360px; background: rgba(0, 0, 0, .6); border-radius: 16px; padding: 18px; }
.scan-bottom { position: relative; z-index: 2; margin-top: auto; padding: 14px 14px calc(16px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0, 0, 0, .8)); display: flex; flex-direction: column; gap: 10px; }
.scan-last { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 40px; }
.scan-pill { max-width: 100%; background: rgba(255, 255, 255, .95); color: #111; border-radius: 12px; padding: 8px 14px; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; animation: toast-in .2s; }
.scan-pill:not(:first-child) { opacity: .6; transform: scale(.94); }
.scan-pill.err { background: var(--danger); color: #fff; }
.scan-manual { display: flex; gap: 8px; }
.scan-manual input { flex: 1; min-width: 0; height: 50px; border-radius: 12px; border: 0; padding: 0 14px; background: rgba(255, 255, 255, .95); color: #111; font-size: 16px; }
.scan-manual .btn { --h: 50px; }

/* ---------- мобільне меню знизу ---------- */
.tabbar { display: none; }

/* ---------- редактор документа / каса ---------- */
.doc-number { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.scanbar { position: relative; display: flex; gap: 10px; }
.scan-input { position: relative; flex: 1; min-width: 0; }
.scan-input .i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.scan-input .input { height: 56px; padding-left: 46px; font-size: 16px; border-radius: 14px; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 40; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); max-height: 380px; overflow: auto; padding: 6px; }
.suggest button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: 0; border-radius: 10px; background: none; text-align: left; cursor: pointer; color: var(--text); }
.suggest button:hover, .suggest button.sel { background: var(--surface-2); }
.suggest .thumb { width: 40px; height: 40px; border-radius: 10px; }

.lines { display: flex; flex-direction: column; gap: 10px; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); }
.line.flash { animation: line-flash 1.2s ease; }
@keyframes line-flash { from { background: var(--primary-50); border-color: var(--primary); } }
.line-name { font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.line-meta { font-size: 12px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.line-ctrl { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.line-ctrl .line-sum { margin-left: auto; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }
.line-ctrl .x { color: var(--muted); font-weight: 700; }
.stepper { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.stepper button { width: 40px; height: 40px; border: 0; border-radius: 10px; background: none; color: var(--primary); display: grid; place-items: center; cursor: pointer; }
.stepper button:hover { background: var(--surface); }
.stepper input { width: 62px; height: 40px; border: 0; background: none; text-align: center; font-weight: 800; font-size: 16px; outline: 0; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.price-in { width: 120px !important; height: 44px !important; text-align: right; font-weight: 700; }
.inv-grid { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 14px; }
.inv-grid b { font-size: 16px; }
.serials { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sn { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 4px 0 10px; border-radius: 8px; background: var(--primary-50); color: var(--primary); font: 700 13px var(--mono); }
.sn button { width: 24px; height: 24px; border: 0; border-radius: 6px; background: none; color: inherit; display: grid; place-items: center; cursor: pointer; }
.sn button:hover { background: var(--primary-100); }
.sn .i { width: 14px; height: 14px; }
.sn.lost { background: var(--danger-50); color: var(--danger); padding-right: 10px; }
.sn.warn { background: var(--warning-50); color: var(--warning); }
.diff-plus { color: var(--success); font-weight: 800; }
.diff-minus { color: var(--danger); font-weight: 800; }

.footbar {
  position: sticky; bottom: 16px; z-index: 30;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 14px 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.footbar .total-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.total-big { font-size: 26px; font-weight: 800; color: var(--primary); line-height: 1.1; font-variant-numeric: tabular-nums; }
.footbar .fb-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }

.pay-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pay-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 16px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 700; text-align: left; min-height: 96px; transition: border-color .15s, background .15s, color .15s; }
.pay-opt .i { width: 26px; height: 26px; color: var(--primary); }
.pay-opt:hover, .pay-opt.sel { border-color: var(--primary); background: var(--primary-50); color: var(--primary); }
.qr-box { display: grid; place-items: center; padding: 18px; background: #fff; border-radius: 16px; margin: 0 auto; width: max-content; max-width: 100%; }
.qr-box img, .qr-box canvas { width: 220px !important; height: 220px !important; }
.success-mark { width: 84px; height: 84px; border-radius: 50%; background: var(--success-50); color: var(--success); display: grid; place-items: center; margin: 0 auto 14px; animation: pop .3s ease; }
.success-mark .i { width: 44px; height: 44px; stroke-width: 2.4; }
.shift-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.cu-label { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.fb-actions .btn-icon { flex: none !important; }

/* ---------- сторінка входу ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(900px 500px at 85% -10%, rgba(91, 97, 255, .22), transparent), radial-gradient(700px 400px at -10% 110%, rgba(240, 71, 107, .14), transparent), var(--bg); }
.auth .card { width: min(420px, 100%); padding: 32px; }
.auth .brand { padding: 0 0 24px; }

/* ---------- адаптив ---------- */
@media (max-width: 1240px) {
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  :root { --gap: 14px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); transform: translateX(-104%); transition: transform .25s ease; box-shadow: var(--shadow-lg); }
  .app.drawer .sidebar { transform: none; }
  .app.drawer .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(15, 17, 40, .4); }
  .main { padding: 12px 16px calc(var(--tabbar) + 32px + env(safe-area-inset-bottom)); }
  .topbar { flex-wrap: wrap; gap: 10px 12px; margin-bottom: 16px; }
  .topbar-title { flex: 1; }
  .topbar h1 { font-size: 21px; }
  .topbar .hello { font-size: 12px; }
  .search { order: 3; width: 100%; height: 48px; margin-left: 0; }
  .menu-btn { display: inline-flex !important; }
  .avatar { width: 40px; height: 40px; }
  .g-3, .g-2 { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; border-radius: 16px; }
  .input, .select, .textarea { font-size: 16px; }
  .big-num { font-size: 28px; }
  .hide-m { display: none !important; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .toolbar { gap: 10px; }
  .toolbar > .btn, .toolbar > .dropdown { flex: none; }
  .footbar { bottom: calc(var(--tabbar) + 10px + env(safe-area-inset-bottom)); padding: 12px; border-radius: 16px; }
  .footbar .fb-actions { margin-left: 0; width: 100%; }
  .footbar .fb-actions .btn { flex: 1; }
  .total-big { font-size: 24px; }
  .line { padding: 12px; }
  .price-in { width: 104px !important; }
  .kpi b { font-size: 18px; }

  .sheet-backdrop { align-items: flex-end; padding: 0; }
  .sheet { width: 100%; border-radius: 22px 22px 0 0; max-height: 92dvh; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .25s ease; }
  .dropdown-menu { position: fixed; left: 12px; right: 12px; top: auto; bottom: calc(var(--tabbar) + 12px + env(safe-area-inset-bottom)); min-width: 0; }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
    height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); box-shadow: 0 -8px 24px -12px rgba(35, 40, 110, .25);
  }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--tabbar); border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; padding: 0; }
  .tabbar .i { width: 22px; height: 22px; }
  .tabbar .active { color: var(--primary); }
  .tabbar .fab { width: 60px; height: 60px; margin-top: -30px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; box-shadow: 0 10px 24px -8px var(--primary); border: 4px solid var(--bg); }
  .tabbar .fab .i { width: 26px; height: 26px; }
}

@media (min-width: 861px) {
  .show-m { display: none !important; }
}

@media print {
  .sidebar, .tabbar, .topbar, .footbar, .no-print { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .card { box-shadow: none; }
}
