:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --ink: #16201b;
  --muted: #6d7a73;
  --line: #e7ecea;
  --green: #2fa56a;
  --green-d: #248554;
  --green-soft: #e6f6ee;
  --navy: #13241c;
  --accent: #2f6fed;
  --warn: #e0593b;
  --yellow: #e0a017;
  --r: 16px;
  --r-sm: 12px;
  --shadow: 0 1px 2px rgba(20,30,25,.06), 0 8px 24px rgba(20,30,25,.06);
  --shadow-pop: 0 10px 40px rgba(20,30,25,.18);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --topbar-h: 54px;
  --bottomnav-h: 62px;
  --tap: 46px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { cursor: pointer; text-decoration: none; color: inherit; }

/* ---------- Иконки (минималистичные SVG) ---------- */
.ic, [data-icon] { display: inline-flex; align-items: center; justify-content: center; line-height: 0; flex-shrink: 0; }
.ic svg, [data-icon] svg { width: 20px; height: 20px; display: block; }
.brand .leaf { color: var(--green); }
.brand .leaf svg { width: 22px; height: 22px; }
.icon-btn svg { width: 22px; height: 22px; }
.acts { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.act { display: inline-flex; align-items: center; justify-content: center; color: var(--accent); padding: 7px; border-radius: 9px; }
.act:hover { background: #eef3fe; }
.act svg { width: 18px; height: 18px; }
.act.danger-act { color: var(--warn); }
.act.danger-act:hover { background: #fdeee9; }

button {
  font: inherit; font-weight: 600; cursor: pointer; border: none; border-radius: var(--r-sm);
  padding: 0 18px; min-height: var(--tap); background: var(--navy); color: #fff;
  transition: filter .15s, transform .05s; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:active { transform: scale(.97); }
button:hover { filter: brightness(1.07); }
button.ghost { background: #eef1f0; color: var(--ink); }
button.green { background: var(--green); }
button.danger { background: #fff; color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
button.sm { min-height: 38px; padding: 0 12px; font-size: 13px; }

input, select, textarea {
  font: inherit; font-size: 16px; width: 100%; padding: 12px 13px; min-height: var(--tap);
  border: 1.5px solid var(--line); border-radius: var(--r-sm); background: #fff; color: var(--ink);
  outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); }
textarea { min-height: 64px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #e8f5ee 0%, #eef2f5 60%); }
.login-card { background: var(--panel); padding: 30px 26px; border-radius: 22px;
  box-shadow: var(--shadow-pop); width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.brand { font-weight: 800; font-size: 20px; display: flex; align-items: center; gap: 8px; letter-spacing: -.02em; }
.brand .leaf { font-size: 22px; }
.login-sub { color: var(--muted); font-size: 13px; margin: -6px 0 8px; }
.error { color: var(--warn); font-size: 13px; min-height: 16px; text-align: center; }

/* ===================== MOBILE-FIRST LAYOUT ===================== */
.app { min-height: 100dvh; }
.sidebar { display: none; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--topbar-h) + var(--safe-t)); padding-top: var(--safe-t);
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between; padding-left: 16px; padding-right: 8px;
}
.topbar .brand { color: #fff; font-size: 17px; }
.topbar .icon-btn { color: #fff; font-size: 22px; min-width: var(--tap); min-height: var(--tap); }

.main {
  padding: calc(var(--topbar-h) + var(--safe-t) + 14px) 14px calc(var(--bottomnav-h) + var(--safe-b) + 20px);
  max-width: 1100px; margin: 0 auto;
}

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--bottomnav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: stretch;
}
.bottomnav .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 10.5px; font-weight: 600; padding-top: 6px;
}
.bottomnav .tab .i svg { width: 24px; height: 24px; }
.bottomnav .tab.active { color: var(--green-d); }
.bottomnav .tab.active .i { transform: translateY(-1px); }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar select, .toolbar input { flex: 1; min-width: 130px; }

/* ---------- Cards / KPI ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.card { background: var(--panel); border-radius: var(--r); padding: 15px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .value { font-size: 23px; font-weight: 800; margin-top: 5px; letter-spacing: -.02em; }
.kpi .sub { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.card.span2 { grid-column: 1 / -1; }
.progress { height: 9px; background: #eaefec; border-radius: 6px; overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--green-d)); border-radius: 6px; }

.section { background: var(--panel); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); margin-top: 14px; }
.section h3 { margin: 0 0 12px; font-size: 15px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }

/* bar list */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .track { background: #eef1f0; border-radius: 6px; height: 16px; overflow: hidden; }
.bar-row .track > i { display: block; height: 100%; background: var(--green); border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }

/* ---------- Tables → cards on mobile ---------- */
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; padding: 10px 12px; font-size: 12px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); }
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--line); }

@media (max-width: 768px) {
  table.resp thead { display: none; }
  table.resp tbody { display: flex; flex-direction: column; gap: 10px; }
  table.resp tbody tr {
    display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm);
    padding: 12px 14px; box-shadow: var(--shadow);
  }
  table.resp tbody td { border: none; padding: 2px 0; display: flex; align-items: center; justify-content: flex-end; gap: 8px; font-size: 14px; }
  table.resp tbody td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600;
    margin-right: auto; text-align: left;
  }
  /* первая ячейка — заголовок карточки на всю ширину */
  table.resp tbody td:first-child { grid-column: 1 / -1; justify-content: flex-start; font-weight: 700; font-size: 15px; }
  table.resp tbody td:first-child::before { display: none; }
}

/* badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.st-Контакт { background: #eef1f0; color: #6d7a73; }
.st-Переговоры { background: #fff2d6; color: #9a6a06; }
.st-Листинг { background: #e6effd; color: #2f6fed; }
.st-Первая, .st-Первая\.отгрузка { background: #ebe9fb; color: #5b53d6; }
.st-Активна { background: var(--green-soft); color: var(--green-d); }
.st-Пауза { background: #fdeae3; color: #c2562f; }
.st-Закрыта { background: #f0f1f0; color: #98a39c; }

/* ---------- Kanban ---------- */
.kanban { display: flex; align-items: flex-start; gap: 12px; overflow-x: auto; padding: 2px 2px 12px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.kan-col { min-height: 70px; }
.kan-col { background: #eef1f0; border-radius: 14px; min-width: 250px; width: 250px; padding: 10px; flex-shrink: 0; scroll-snap-align: start; }
.kan-col h4 { margin: 4px 6px 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.kan-col h4 span { color: var(--muted); font-weight: 700; background: #fff; border-radius: 20px; padding: 1px 8px; font-size: 12px; }
.kan-col.drag-over { outline: 2px dashed var(--green); outline-offset: -2px; }
.kan-card { background: #fff; border-radius: 11px; padding: 11px 12px; margin-bottom: 9px; box-shadow: var(--shadow); }
.kan-card .t { font-weight: 700; font-size: 14px; }
.kan-card .m { color: var(--muted); font-size: 12px; margin-top: 3px; }
.kan-card .mini-status { margin-top: 9px; min-height: 38px; padding: 7px 10px; font-size: 13px; background: #f6f8f7; border-color: transparent; }
.kan-card.dragging { opacity: .4; }

/* ---------- Modal → bottom sheet on mobile ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,22,18,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal-card {
  background: #fff; width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  border-radius: 22px 22px 0 0; box-shadow: var(--shadow-pop);
  padding-bottom: calc(16px + var(--safe-b)); animation: sheetUp .26s cubic-bezier(.22,1,.36,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-grip { width: 40px; height: 4px; border-radius: 4px; background: #d7ddda; margin: 9px auto 0; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px 12px; position: sticky; top: 0; background: #fff; }
.modal-head h3 { margin: 0; font-size: 18px; }
#modal-body { padding: 4px 20px 8px; }
.icon-btn { background: none; color: var(--muted); padding: 6px 10px; min-height: auto; }
.icon-btn:hover { color: var(--ink); filter: none; }
.modal-actions { display: flex; gap: 10px; justify-content: stretch; margin-top: 22px; position: sticky; bottom: 0; }
.modal-actions button { flex: 1; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.item-row { display: grid; grid-template-columns: 1fr 70px 92px auto; gap: 7px; align-items: center; margin-bottom: 9px; }
.item-row input, .item-row select { font-size: 14px; padding: 9px; min-height: 40px; }
.item-row button { min-height: 40px; padding: 0 10px; }

/* sheet list (Ещё) */
.sheet-list { display: flex; flex-direction: column; }
.sheet-list a { display: flex; align-items: center; gap: 12px; padding: 15px 4px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 16px; }
.sheet-list a .ic { color: var(--ink); }
.sheet-list a .ic svg { width: 22px; height: 22px; }
.sheet-list a:last-child { border-bottom: none; }

/* ---------- Карточка точки (детали) ---------- */
.dt-meta { background: #f6f8f7; border-radius: var(--r-sm); padding: 12px 14px; margin-bottom: 14px; }
.dt-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 14px; }
.dt-row .muted { font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-box { background: var(--green-soft); border-radius: var(--r-sm); padding: 12px; text-align: center; }
.stat-box .sv { font-size: 19px; font-weight: 800; color: var(--green-d); letter-spacing: -.02em; }
.stat-box .sl { font-size: 11px; color: var(--muted); margin-top: 2px; }
.hist { display: flex; flex-direction: column; }
.hist-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 4px; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: none; }
.hr-main { flex: 1; cursor: pointer; }

.link { color: var(--accent); font-weight: 600; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 44px 20px; }

/* FAB-like primary action in header on mobile */
.page-head .add-btn { white-space: nowrap; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottomnav-h) + var(--safe-b) + 16px);
  background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow-pop);
  z-index: 60; font-weight: 600; font-size: 14px; max-width: 90%; }
.toast.err { background: var(--warn); }

/* ===================== DESKTOP ===================== */
@media (min-width: 880px) {
  .topbar, .bottomnav { display: none; }
  .app { display: grid; grid-template-columns: 240px 1fr; }
  .sidebar { display: flex; flex-direction: column; gap: 5px; position: sticky; top: 0; height: 100dvh;
    background: var(--navy); color: #cdd6d1; padding: 22px 14px; }
  .sidebar .brand { color: #fff; margin-bottom: 18px; padding: 0 6px; }
  .nav-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: var(--r-sm);
    color: #c4cfc9; font-weight: 600; white-space: nowrap; }
  .nav-item .i svg { width: 19px; height: 19px; }
  .nav-item:hover { background: rgba(255,255,255,.07); }
  .nav-item.active { background: rgba(255,255,255,.14); color: #fff; }
  .sidebar-foot { margin-top: auto; padding: 12px 8px; font-size: 13px; display: flex; justify-content: space-between;
    align-items: center; color: #9aa6a0; border-top: 1px solid rgba(255,255,255,.1); }
  .sidebar-foot a:hover { color: #fff; }
  .main { padding: 28px 32px; max-width: none; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .card.span2 { grid-column: auto; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .modal { align-items: center; }
  .modal-card { border-radius: 18px; max-height: 90vh; padding-bottom: 8px; animation: popIn .2s ease; }
  .modal-grip { display: none; }
  @keyframes popIn { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
  tr:hover td { background: #fafbfb; }
}
