/* ИИ-закупщик travma.kg */

:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --line: #e5ebef;
  --text: #16242e;
  --muted: #5f7180;
  --faint: #8ea0ad;
  --primary: #0f766e;
  --primary-dark: #0d5f59;
  --primary-soft: #e6f4f2;
  --amber: #b45309;
  --amber-soft: #fdf1e3;
  --slate: #64748b;
  --slate-soft: #eef2f6;
  --green: #15803d;
  --green-soft: #e9f6ee;
  --red: #b91c1c;
  --red-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 2px 8px rgba(16,24,40,.06);
  --shadow-lg: 0 8px 30px rgba(16,24,40,.14);
  --radius: 14px;
}

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

html, body { height: 100%; }

body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
.hidden { display: none !important; }

/* ---------- Вход ---------- */
#loginView {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(15,118,110,.18), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(15,118,110,.14), transparent 60%),
    var(--bg);
  padding: 24px;
}
.login-card {
  width: 380px; max-width: 100%;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px 32px;
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.login-sub { color: var(--muted); margin-bottom: 26px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input-wrap { position: relative; }
.input-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--faint); }
.input-wrap input {
  width: 100%; padding: 11px 12px 11px 40px;
  border: 1.5px solid var(--line); border-radius: 10px; outline: none;
  background: #fbfcfd; transition: border-color .15s, box-shadow .15s;
}
.input-wrap input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); background: #fff; }
.login-error {
  display: none; margin: 4px 0 12px; padding: 9px 12px;
  background: var(--red-soft); color: var(--red);
  border-radius: 8px; font-size: 13px;
}
.login-error.show { display: block; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; font-weight: 600;
  transition: background .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(13,95,89,.4); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #9db9b6; cursor: default; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--slate-soft); color: var(--text); }
.btn-outline { background: #fff; border: 1.5px solid var(--line); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-block { width: 100%; }

/* ---------- Каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 20px;
  height: 60px; display: flex; align-items: center; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.brand small { display: block; font-weight: 600; font-size: 10.5px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, #14b8a6, #0f766e);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(15,118,110,.35);
}
.logo-mark svg { width: 19px; height: 19px; color: #fff; }

.tabs { display: flex; gap: 2px; margin-left: 10px; }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 9px;
  color: var(--muted); font-weight: 600; font-size: 13.5px;
}
.tab svg { width: 18px; height: 18px; }
.tab:hover { background: var(--slate-soft); color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary); }
.tab .soon {
  font-size: 9.5px; font-weight: 700; letter-spacing: .04em;
  background: var(--slate-soft); color: var(--faint);
  padding: 2px 6px; border-radius: 20px;
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.sync-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  padding: 6px 10px; border-radius: 8px; background: var(--slate-soft);
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sync-chip svg { width: 15px; height: 15px; flex: none; }
.sync-chip.spin svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.user-chip { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.user-chip svg { width: 20px; height: 20px; color: var(--primary); }

.page { max-width: 1280px; margin: 0 auto; padding: 26px 20px 80px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { font-size: 21px; font-weight: 800; letter-spacing: -.02em; }
.page-title small { display: block; font-size: 13px; color: var(--muted); font-weight: 500; margin-top: 2px; }

/* ---------- Карточки/KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; display: flex; gap: 14px; align-items: center;
}
.kpi-ic {
  width: 42px; height: 42px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.kpi-ic svg { width: 22px; height: 22px; }
.kpi-val { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.kpi-lbl { font-size: 12px; color: var(--muted); font-weight: 600; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-title { font-weight: 700; font-size: 15px; }

/* сегменты ABC */
.abc-strip { display: flex; height: 12px; border-radius: 8px; overflow: hidden; margin: 6px 0 10px; }
.abc-strip div { height: 100%; }
.abc-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.abc-legend b { color: var(--text); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--faint); font-weight: 700; padding: 8px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid #eef2f5; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-name { max-width: 420px; }
.cell-name .nm { font-weight: 600; }
.cell-name .art { font-size: 12px; color: var(--faint); }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 22px; padding: 0 7px;
  border-radius: 7px; font-size: 12px; font-weight: 800;
}
.badge.A { background: var(--primary-soft); color: var(--primary); }
.badge.B { background: var(--amber-soft); color: var(--amber); }
.badge.C { background: var(--slate-soft); color: var(--slate); }

.share-bar { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.share-bar .bar { flex: 1; height: 6px; border-radius: 4px; background: var(--slate-soft); overflow: hidden; }
.share-bar .bar i { display: block; height: 100%; border-radius: 4px; background: var(--primary); }
.share-bar span { font-size: 12px; color: var(--muted); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

/* строка товара-группы в заказе */
tr.group-row td {
  background: #f7fafb; font-weight: 700; font-size: 13px;
  border-top: 1px solid var(--line);
}
tr.group-row:hover td { background: #f3f7f9; }

.spark { color: var(--primary); }
.qty-input {
  width: 74px; padding: 6px 8px; text-align: right;
  border: 1.5px solid var(--line); border-radius: 8px; outline: none;
  background: #fbfcfd; font-variant-numeric: tabular-nums;
}
.qty-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.qty-input.zero { color: var(--faint); }

.pill { font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.pill.low { background: var(--red-soft); color: var(--red); }
.pill.mid { background: var(--amber-soft); color: var(--amber); }
.pill.ok { background: var(--green-soft); color: var(--green); }

/* ---------- Панель управления заказом ---------- */
.controls { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.ctrl { display: flex; flex-direction: column; gap: 5px; }
.ctrl label { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ctrl select, .ctrl input[type="number"], .ctrl input[type="search"] {
  padding: 9px 11px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; outline: none; min-width: 90px;
}
.ctrl select:focus, .ctrl input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.ctrl input[type="search"] { min-width: 220px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; padding: 9px 0; }
.switch input { display: none; }
.switch .track {
  width: 36px; height: 21px; border-radius: 20px; background: #cfdbe2; position: relative; transition: background .15s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2.5px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .15s;
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { left: 17px; }
.switch span.lbl { font-weight: 600; font-size: 13px; }

/* плавающий футер выбора */
.orderbar {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #10221f; color: #fff; border-radius: 16px;
  box-shadow: 0 12px 32px rgba(6,24,21,.4);
  padding: 12px 16px 12px 20px;
  display: flex; align-items: center; gap: 18px; z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.orderbar.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.orderbar .sum { font-weight: 800; font-size: 15px; }
.orderbar .cnt { color: #9fc4be; font-size: 13px; }

/* ---------- Модалки ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10,24,30,.5); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg);
  width: 560px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 20px 22px 0; }
.modal-title { font-size: 17px; font-weight: 800; }
.modal-close { margin-left: auto; color: var(--faint); }
.modal-close svg { width: 24px; height: 24px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 14px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px 20px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--line); }

.order-pos { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed #e8eef2; font-size: 13.5px; }
.order-pos:last-child { border-bottom: none; }
.order-pos .q { color: var(--muted); white-space: nowrap; }

textarea {
  width: 100%; min-height: 64px; padding: 10px 12px; resize: vertical;
  border: 1.5px solid var(--line); border-radius: 10px; outline: none; background: #fbfcfd;
}
textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }

/* success */
.result-ok { text-align: center; padding: 18px 0 6px; }
.result-ok svg { width: 52px; height: 52px; color: var(--green); margin: 0 auto 10px; }
.result-ok .nm { font-size: 16px; font-weight: 800; }
.result-ok .desc { color: var(--muted); margin: 4px 0 16px; }

/* ---------- Тосты ---------- */
#toasts { position: fixed; right: 20px; top: 74px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #10221f; color: #fff; border-radius: 12px; padding: 12px 16px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 340px;
  animation: toast-in .2s ease-out;
}
.toast.err { background: #7f1d1d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- Пустые состояния ---------- */
.empty {
  text-align: center; padding: 60px 20px; color: var(--muted);
}
.empty svg { width: 54px; height: 54px; color: #b9c7d1; margin: 0 auto 14px; }
.empty .t { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty p { max-width: 460px; margin: 0 auto; font-size: 13.5px; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 60px 0; color: var(--muted); }
.loading svg { width: 20px; height: 20px; animation: spin 1.2s linear infinite; color: var(--primary); }

.footnote { color: var(--faint); font-size: 12px; margin-top: 10px; }

.show-more { text-align: center; padding: 14px 0 2px; }

/* ---------- Настройки ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px dashed #e8eef2; }
.setting-row:last-child { border-bottom: none; }
.setting-row .lbl { font-weight: 600; }
.setting-row .hint { font-size: 12px; color: var(--muted); margin-top: 2px; max-width: 380px; }
.setting-row input[type="number"] {
  width: 84px; padding: 8px 10px; text-align: right;
  border: 1.5px solid var(--line); border-radius: 9px; outline: none;
}

@media (max-width: 860px) {
  .topbar-inner { height: auto; flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .sync-chip { display: none; }
  .page { padding: 18px 12px 90px; }
}
