:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1a2233; --muted: #6b7688;
  --line: #e3e8ef; --accent: #1f3864; --accent2: #2e75b6; --danger: #c00000;
}
* { box-sizing: border-box; margin: 0; }
body { font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
.hidden { display: none !important; }

/* Вход */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(150deg, #1f3864, #2e75b6); }
#login-form { background: #fff; padding: 40px 36px; border-radius: 14px; width: 340px; box-shadow: 0 18px 60px rgba(0,0,0,.35); }
#login-form h1 { font-size: 30px; color: var(--accent); letter-spacing: 1px; }
#login-form h1 span { color: var(--accent2); font-weight: 300; }
#login-form .sub { color: var(--muted); margin: 4px 0 22px; font-size: 13px; }
#login-form input { width: 100%; padding: 11px 12px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
#login-form button { width: 100%; padding: 11px; background: var(--accent); color: #fff; border: 0; border-radius: 8px; font-size: 15px; cursor: pointer; }
.err { color: var(--danger); margin-top: 10px; font-size: 13px; min-height: 18px; }

/* Каркас */
header { display: flex; align-items: center; gap: 22px; background: var(--accent); color: #fff; padding: 0 18px; height: 52px; position: sticky; top: 0; z-index: 500; }
.logo { font-weight: 700; font-size: 18px; letter-spacing: 1px; }
.logo span { font-weight: 300; opacity: .85; }
nav#tabs { display: flex; gap: 4px; flex: 1 1 0; min-width: 0; overflow-x: auto; scrollbar-width: none; }
nav#tabs::-webkit-scrollbar { display: none; }
nav#tabs button { flex-shrink: 0; white-space: nowrap; }
nav#tabs button { background: transparent; border: 0; color: #cdd8ea; padding: 16px 14px; cursor: pointer; font-size: 14px; border-bottom: 3px solid transparent; }
nav#tabs button.active { color: #fff; border-bottom-color: #7ea6d9; }
.badge { background: var(--danger); border-radius: 9px; padding: 1px 7px; font-size: 11px; color: #fff; }
.user-box { display: flex; gap: 14px; align-items: center; font-size: 13px; flex-shrink: 0; margin-left: auto; white-space: nowrap; }
.user-box a { color: #9db4d4; text-decoration: none; }

#filters { display: flex; gap: 10px; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#filters select, #filters input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 13px; }
button.primary { background: var(--accent2); color: #fff; border: 0; border-radius: 8px; padding: 8px 16px; cursor: pointer; font-size: 13px; }
main { padding: 16px 18px; }

/* Канбан */
#view-board { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; min-height: 70vh; }
.col { background: #eceff4; border-radius: 12px; min-width: 250px; width: 250px; flex-shrink: 0; }
.col-head { padding: 10px 12px; font-weight: 600; font-size: 13px; border-bottom: 3px solid; display: flex; justify-content: space-between; border-radius: 12px 12px 0 0; }
.col-sum { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 2px; }
.col-body { padding: 8px; min-height: 60px; max-height: calc(100vh - 240px); overflow-y: auto; }
.card { background: #fff; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: grab; box-shadow: 0 1px 3px rgba(20,30,60,.09); border-left: 4px solid #ccc; }
.card:active { cursor: grabbing; }
.card .t { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.card .m { color: var(--muted); font-size: 12px; }
.card .warn { color: var(--danger); font-size: 12px; font-weight: 600; }
.col-body.dragover { outline: 2px dashed var(--accent2); border-radius: 8px; }

/* Карта */
#map { height: calc(100vh - 190px); border-radius: 12px; }
#map-legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 10px 4px; font-size: 12px; color: var(--muted); }
#map-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

/* Клиники / списки */
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.toolbar input { flex: 1; max-width: 420px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; }
table.grid { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(20,30,60,.08); }
table.grid th { text-align: left; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 2px solid var(--line); background: #fafbfd; }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.grid tr:hover td { background: #f4f8fe; cursor: pointer; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 11.5px; color: #fff; white-space: nowrap; }

/* Модалка */
#modal-wrap { position: fixed; inset: 0; background: rgba(15,25,50,.45); z-index: 900; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 40px 16px; }
#modal { background: #fff; border-radius: 14px; width: 100%; max-width: 760px; padding: 24px 28px; box-shadow: 0 24px 80px rgba(0,0,0,.35); }
#modal h2 { font-size: 18px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
#modal h2 .x { cursor: pointer; color: var(--muted); font-size: 22px; font-weight: 400; }
.frow { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.frow label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.frow > div { flex: 1; min-width: 140px; }
.frow input, .frow select, .frow textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: inherit; }
.frow textarea { min-height: 60px; }
.hint { font-size: 12px; color: var(--accent2); margin: -4px 0 10px; min-height: 16px; }
.hint.bad { color: var(--danger); }
.acts { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; max-height: 300px; overflow-y: auto; }
.act { padding: 8px 10px; background: #f7f9fc; border-radius: 8px; margin-bottom: 6px; font-size: 12.5px; }
.act .who { color: var(--muted); font-size: 11px; margin-top: 3px; }
.btnrow { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; flex-wrap: wrap; }
button.ghost { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 16px; cursor: pointer; }

/* Напоминания */
.rem-item { background: #fff; border-left: 4px solid var(--danger); border-radius: 10px; padding: 12px 16px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(20,30,60,.08); cursor: pointer; }
.rem-item b { font-size: 14px; }
.rem-item .m { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

/* Дашборд */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.dash-card { background: #fff; border-radius: 12px; padding: 16px 18px; box-shadow: 0 1px 3px rgba(20,30,60,.08); }
.dash-card h3 { font-size: 14px; margin-bottom: 10px; color: var(--accent); }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12.5px; }
.bar-row .lbl { width: 165px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar { height: 14px; border-radius: 4px; min-width: 2px; }
.bar-row .val { color: var(--ink); font-size: 12px; white-space: nowrap; }
/* MiniMap */
.mm { position: relative; overflow: hidden; background: #dce8f2; user-select: none; touch-action: none; cursor: grab; }
.mm:active { cursor: grabbing; }
.mm-tiles img { position: absolute; pointer-events: none; }
.mm-tiles img.mm-tile-fail { visibility: hidden; }
.mm.mm-offline { background:
  linear-gradient(#c9d9e8 1px, transparent 1px), linear-gradient(90deg, #c9d9e8 1px, transparent 1px), #dce8f2;
  background-size: 48px 48px; }
.mm-markers { position: absolute; inset: 0; }
.mm-marker { position: absolute; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); transform: translate(-50%, -50%); cursor: pointer; }
.mm-marker:hover { width: 19px; height: 19px; z-index: 5; }
.mm-popup { position: absolute; background: #fff; border-radius: 10px; padding: 10px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.3); font-size: 12.5px; line-height: 1.5; z-index: 10; width: 230px; }
.mm-zoom { position: absolute; top: 12px; left: 12px; z-index: 20; display: flex; flex-direction: column; gap: 4px; }
.mm-zoom button { width: 32px; height: 32px; border: 0; border-radius: 8px; background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3); font-size: 18px; cursor: pointer; }
.mm-attr { position: absolute; bottom: 4px; right: 8px; font-size: 10px; color: #667; z-index: 20; }
.mm-base { position: absolute; inset: 0; pointer-events: none; }
.mm-pop-title { font-weight: 700; font-size: 13.5px; margin-bottom: 2px; }
.mm-pop-sub { color: #6b7688; font-size: 11.5px; margin-bottom: 7px; }
.mm-pop-row { margin-bottom: 5px; }
.mm-btn { display: block; width: 100%; margin-top: 8px; padding: 7px 0; background: #2e75b6;
  color: #fff; border: 0; border-radius: 8px; font-size: 13px; cursor: pointer; }
.mm-btn:hover { background: #1f3864; }
.new-badge { background: #2e75b6; color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 8px; vertical-align: 1px; }
.mm-marker.mm-comp { border-radius: 3px; transform: translate(-50%, -50%) rotate(45deg); border: 2px solid #ff7f0e; width: 13px; height: 13px; }
.mm-marker.mm-comp:hover { width: 17px; height: 17px; }
#map-legend label input { vertical-align: -2px; margin-right: 4px; }
.comp-mark { color: #1a1a1a; font-size: 11px; }
.comp-warn { background: #fff4e5; border: 1px solid #f0c188; border-radius: 8px; padding: 8px 12px;
  font-size: 12.5px; margin-bottom: 12px; }
.comp-warn a { color: #2e75b6; }
.comp-details { background: #f7f9fc; border-radius: 8px; padding: 10px 14px; font-size: 12px;
  white-space: pre-wrap; margin-bottom: 10px; color: #333; max-height: 220px; overflow-y: auto; }

/* v1.8: планирование следующего шага */
.plan-box{background:#f4f7fb;border:1px solid #dbe4f0;border-radius:10px;padding:10px 12px;margin-bottom:12px}
.plan-cur{background:#fff;border-radius:8px;padding:8px 10px;margin-top:6px;font-size:13px;display:flex;align-items:center;flex-wrap:wrap;gap:4px}
.plan-cur button{padding:4px 10px;font-size:12px}
.plan-due{border:1px solid var(--danger,#d62728);background:#fff5f5}
#contacts-list td{vertical-align:top}
/* v1.9: формирование КП */
.kp-items{max-height:320px;overflow-y:auto;margin-bottom:10px;border:1px solid var(--line,#e3e8ef);border-radius:8px}
.kp-items table{margin:0}
.kp-cat td{background:#eaf3f0;font-weight:600;font-size:12px}
#kp-result a{font-weight:600}
/* v2.0: календарь */
.cal-bar{align-items:center;flex-wrap:wrap;gap:8px}
.cal-title{font-size:16px;min-width:150px;text-align:center}
.cal-legend{margin-left:auto;display:flex;gap:10px;flex-wrap:wrap;font-size:11px;color:#555}
.cal-leg i{display:inline-block;width:10px;height:10px;border-radius:3px;margin-right:4px;vertical-align:-1px}
.cal-leg-task{background:#fff;border:1px solid #999;border-left:3px solid #666}
.cal-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:4px}
.cal-head-row{margin-bottom:4px}
.cal-head-row div{text-align:center;font-size:12px;color:#777;font-weight:600}
.cal-day{background:#fff;border:1px solid #e3e8ef;border-radius:8px;min-height:92px;padding:4px;overflow:hidden}
.cal-out{background:#f6f7f9;opacity:.6}
.cal-today{border:2px solid #2e75b6}
.cal-num{font-size:12px;font-weight:600;color:#555;display:flex;justify-content:space-between;margin-bottom:3px}
.cal-add{cursor:pointer;color:#bbb;font-weight:700;padding:0 3px;border-radius:4px;visibility:hidden}
.cal-day:hover .cal-add{visibility:visible}
.cal-add:hover{background:#e8f0fe;color:#2e75b6}
.cal-chip{font-size:11px;color:#fff;border-radius:4px;padding:2px 5px;margin-bottom:3px;cursor:pointer;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.cal-chip:hover{filter:brightness(1.1)}
.cal-cont{opacity:.75;text-align:center;letter-spacing:2px}
.cal-task{background:#fff;color:#333;border:1px solid #d5dbe3;border-left:3px solid #666}
.cal-task:hover{background:#f0f4fa;filter:none}
@media (max-width:800px){.cal-day{min-height:64px}.cal-chip{font-size:10px}}
/* v2.2: удаление элементов */
.del-x{color:#c8cfd8;margin-left:8px;text-decoration:none;font-weight:700;float:right}
.del-x:hover{color:#c00000}
.fhidden{display:none!important}

/* ── Мобильная версия ─────────────────────────────── */
#filters-toggle { display: none; }
#fab-add { display: none; }

@media (max-width: 768px) {
  body { font-size: 15px; }
  /* шапка: логотип + пользователь в одну строку, вкладки — скролл-лента ниже */
  header { flex-wrap: wrap; height: auto; padding: 8px 12px 0; gap: 8px; }
  .logo { font-size: 18px; }
  .user-box { margin-left: auto; font-size: 12px; gap: 8px; }
  nav#tabs { order: 3; flex: 0 0 100%; width: 100%; display: flex; overflow-x: auto; gap: 2px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; margin: 0 -12px; padding: 0 12px; }
  nav#tabs::-webkit-scrollbar { display: none; }
  nav#tabs button { flex-shrink: 0; padding: 11px 13px; font-size: 14px; }
  /* фильтры: свёрнуты за кнопкой */
  #filters-toggle { display: block; width: calc(100% - 24px); margin: 10px 12px 0; padding: 10px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
    font-size: 14px; color: var(--ink); text-align: left; cursor: pointer; }
  #filters { display: none; padding: 10px 12px; }
  #filters.open { display: flex; }
  #filters select, #filters input, #filters button { width: 100%; font-size: 16px; padding: 11px 12px; }
  main { padding: 12px; }
  /* канбан: колонка почти во весь экран, свайп со снапом */
  #view-board { scroll-snap-type: x mandatory; gap: 10px; padding-bottom: 70px; }
  .col { min-width: 86vw; width: 86vw; scroll-snap-align: center; }
  .col-body { max-height: calc(100vh - 300px); }
  .card { padding: 12px; }
  /* таблицы: горизонтальная прокрутка */
  #clinics-list, #contacts-list, #view-training, #view-users, #view-dashboard { overflow-x: auto; }
  #clinics-list .grid, #contacts-list .grid, #view-training .grid, #view-users .grid { min-width: 640px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input { width: 100%; font-size: 16px; }
  /* модалки: полноэкранные */
  #modal-wrap { padding: 0; align-items: stretch; }
  #modal { max-width: none; min-height: 100dvh; border-radius: 0; padding: 16px 14px
    calc(20px + env(safe-area-inset-bottom)); }
  #modal h2 { position: sticky; top: -16px; background: #fff; padding: 12px 0; margin-top: -12px; z-index: 5; }
  #modal h2 .x { font-size: 30px; padding: 0 6px; }
  .frow { flex-direction: column; gap: 10px; }
  .frow > div { max-width: none !important; width: 100%; flex: none !important; }
  #modal input, #modal select, #modal textarea { font-size: 16px; padding: 11px 12px; width: 100%; }
  .btnrow { flex-wrap: wrap; gap: 8px; }
  .btnrow button { flex: 1 1 45%; padding: 12px; font-size: 15px; }
  /* карта */
  #map { height: calc(100dvh - 250px); }
  /* календарь: ячейки-миниатюры, события — цветные полоски, тап по дню открывает список */
  .cal-bar { gap: 6px; }
  .cal-bar .cal-title { min-width: 0; flex: 1; font-size: 13px; line-height: 1.15; text-align: center; }
  .cal-legend { display: none; }
  .cal-grid { gap: 2px; }
  .cal-day { min-height: 52px; padding: 2px 3px; border-radius: 6px; cursor: pointer; }
  .cal-num { font-size: 11px; margin-bottom: 2px; }
  .cal-add { display: none; }
  .cal-chip { height: 6px; padding: 0; font-size: 0; border-radius: 3px; margin-bottom: 2px; }
  .cal-task { height: 6px; border: 0; border-left: 0; background: #9467bd; }
  .kp-items { overflow-x: auto; }
  .kp-items table { min-width: 560px; }
  /* плавающая кнопка добавления */
  #fab-add { display: flex; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
    width: 56px; height: 56px; border-radius: 50%; background: var(--accent2); color: #fff;
    font-size: 30px; border: 0; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px rgba(0,0,0,.35); z-index: 600; cursor: pointer; }
}

/* v2.4: приборы, лента, аналитика */
.cal-book{background:#17becf}
.cal-book-done{background:#548235}
#map-analytics table td{white-space:nowrap}
#map-analytics table td:last-child{white-space:normal}
/* v2.5: аналитика региона, лента по дням, поиск клиник */
#map-topbar{margin-bottom:10px}
.an-bar{display:flex;gap:10px;align-items:center;margin-bottom:10px;flex-wrap:wrap}
.an-bar select{padding:9px 12px;border:1px solid var(--line);border-radius:8px;background:#fff;min-width:290px}
.an-cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:10px;margin-bottom:12px}
.an-card{background:#fff;border-radius:12px;padding:14px 16px;box-shadow:0 1px 3px rgba(20,30,60,.08)}
.an-card .an-num{font-size:22px;font-weight:700;color:var(--accent)}
.an-card .an-lbl{font-size:11.5px;color:var(--muted);margin-top:3px;line-height:1.35}
.an-ours{background:#eef7ee}
.an-ours .an-num{color:#548235}
.an-cols{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.feed-day{position:sticky;top:0;z-index:5;background:var(--bg);padding:10px 2px 6px;
  font-weight:700;font-size:13px;color:var(--accent);border-bottom:1px solid var(--line);margin-bottom:8px}
@media (max-width:768px){
  .an-cols{grid-template-columns:1fr}
  .an-cards{grid-template-columns:repeat(2,1fr)}
  .an-bar select{min-width:0;width:100%;font-size:16px}
  #map-topbar button{width:100%;padding:12px}
  #map-analytics .an-table table{min-width:820px}
  #an-detail .dash-card{overflow-x:auto}
  .feed-day{top:-1px}
  #view-feed .toolbar select{width:100%;font-size:16px}
  #dv-clinic-q,#bk-clinic-q{font-size:16px}
}
/* v2.7: подвкладки и меню действий */
.subtabs{display:flex;gap:6px;margin-bottom:14px}
.subtabs button{background:#fff;border:1px solid var(--line);border-radius:20px;padding:7px 18px;
  cursor:pointer;font-size:13px;color:var(--muted)}
.subtabs button.active{background:var(--accent2);border-color:var(--accent2);color:#fff;font-weight:600}
.menu-wrap{position:relative;margin-right:auto}
.menu{position:absolute;bottom:calc(100% + 6px);left:0;background:#fff;border:1px solid var(--line);
  border-radius:10px;box-shadow:0 8px 30px rgba(15,25,50,.18);min-width:230px;z-index:40;
  display:flex;flex-direction:column;padding:4px}
.menu a{padding:10px 14px;border-radius:8px;cursor:pointer;color:var(--ink);text-decoration:none;font-size:13.5px}
.menu a:hover{background:#eef3fa}
@media (max-width:768px){
  .subtabs button{flex:1;padding:10px;font-size:14px}
  .menu{min-width:200px}
}
/* v2.9.1 */
#rem-mgr{padding:9px 12px;border:1px solid var(--line);border-radius:8px;background:#fff;min-width:260px}
.plan-cur .pill{margin-right:6px}
