/* ---------- Каркас ---------- */
.app-body { background: var(--atmosphere); background-attachment: fixed; }
.app-body::before {   /* лёгкое зерно для атмосферы */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.app { position: relative; z-index: 1; display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 26px; padding: 22px 14px;
  background: rgba(10, 13, 30, .55); backdrop-filter: blur(18px); border-right: 1px solid var(--glass-border);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.02em; padding: 0 10px; }
.side-nav { display: grid; gap: 4px; }
.side-foot { margin-top: auto; display: grid; gap: 4px; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.side-link {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; border: 0;
  background: none; color: var(--text-dim); font-weight: 550; font-size: 15px; cursor: pointer; text-align: left; width: 100%;
  transition: background .15s, color .15s;
}
.side-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.side-link:hover { background: var(--bg-elev); color: var(--text); }
.side-link.active { background: var(--bg-elev-2); color: var(--text); }
.side-link.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--gradient); }
.side-link.active svg { color: var(--accent); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; min-height: 68px; padding: 0 32px;
  background: rgba(10, 13, 30, .6); backdrop-filter: blur(16px); border-bottom: 1px solid var(--glass-border);
}
.topbar h1 { font-size: 22px; font-weight: 750; }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.menu-btn { display: none; border: 0; background: none; padding: 6px; cursor: pointer; color: var(--text); }
.menu-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.content { padding: 28px 32px 64px; outline: none; display: grid; gap: 22px; align-content: start; }
.loader { display: grid; place-items: center; min-height: 40vh; color: var(--text-faint); }
.scrim { display: none; }

/* ---------- Общие блоки ---------- */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card h2, .card h3 { font-size: 17px; font-weight: 700; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head p { font-size: 14px; }
.app-body .card, .stat {
  background: linear-gradient(180deg, var(--glass-hi), transparent 40%), var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 18px 40px rgba(3, 5, 20, .35);
}
.stat { padding: 18px 20px; border-radius: var(--radius); }
.stat span { font-size: 13px; color: var(--text-faint); }
.stat b { display: block; font: 700 28px/1.15 var(--mono); margin-top: 6px; letter-spacing: -.02em; }
.stat small { color: var(--text-dim); font-size: 13px; }
.stat.accent b { color: var(--accent); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.toolbar .field { min-width: 150px; }
.segmented { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--bg-elev); border: 1px solid var(--line-soft); }
.segmented button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; color: var(--text-dim); font-weight: 600; cursor: pointer; font-size: 14px; }
.segmented button.active { background: var(--bg-elev-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.empty { text-align: center; padding: 56px 20px; border: 1px dashed var(--line); border-radius: var(--radius); display: grid; gap: 10px; justify-items: center; }
.empty h3 { font-size: 19px; }
.empty .btn { margin-top: 8px; }
.empty-icon { width: 54px; height: 54px; border-radius: 16px; background: var(--gradient); opacity: .9; mask: radial-gradient(circle at 50% 50%, transparent 9px, #000 10px); }
.error-card { border-color: rgba(255, 93, 108, .4); }
.notice-card { border-color: rgba(47, 212, 196, .35); background: rgba(47, 212, 196, .05); }

/* Таблицы */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line-soft); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th { color: var(--text-faint); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--bg-elev); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg-elev); }
td.num, th.num { text-align: right; font-family: var(--mono); }
table input.input { min-height: 36px; padding: 6px 10px; width: 100%; min-width: 80px; }

/* Список тренировок */
.activity-list { display: grid; gap: 10px; }
.activity {
  display: grid; grid-template-columns: 46px minmax(0, 1.6fr) repeat(4, minmax(0, 1fr)); align-items: center; gap: 14px;
  padding: 14px 18px; border-radius: var(--radius); background: var(--bg-elev); border: 1px solid var(--line-soft);
  cursor: pointer; transition: border-color .15s, transform .15s var(--ease);
}
.activity:hover { border-color: var(--line); transform: translateX(2px); }
.sport-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--bg-elev-2); font-size: 20px; }
.sport-icon.run { color: var(--accent); } .sport-icon.bike { color: var(--accent-2); } .sport-icon.swim { color: var(--z1); }
.sport-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.activity .title b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity .title small { color: var(--text-faint); font-size: 13px; }
.metric { display: grid; }
.metric b { font: 650 16px/1.2 var(--mono); }
.metric small { color: var(--text-faint); font-size: 12px; }
.pager { display: flex; justify-content: center; gap: 10px; align-items: center; color: var(--text-dim); font-size: 14px; }

/* Зоны */
.zone-table td:first-child { display: flex; align-items: center; gap: 10px; }
.zone-row-bar { height: 6px; border-radius: 3px; background: var(--zc); }
.zone-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--bg); background: var(--zc); }
.threshold-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.threshold { padding: 18px; border-radius: var(--radius); border: 1px solid var(--line-soft); background: var(--bg-elev-2); }
.threshold span { font-size: 13px; color: var(--text-faint); }
.threshold b { display: block; font: 700 30px/1.1 var(--mono); margin: 6px 0 4px; }
.threshold.aer b { color: var(--z2); } .threshold.an b { color: var(--z4); }
.stages-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.warnings { display: grid; gap: 6px; margin-top: 12px; }
.warnings p { color: var(--warning); font-size: 14px; }
.zones-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; gap: 2px; }
.zones-bar span { background: var(--zc); min-width: 2px; }

/* Графики */
.chart { width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-faint); font: 11px var(--mono); }
.chart .grid-line { stroke: var(--line-soft); }
.chart .axis { stroke: var(--line); }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-dim); margin-top: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 3px; border-radius: 2px; background: var(--c); }
.chart-tip {
  position: fixed; pointer-events: none; z-index: 100; padding: 8px 10px; border-radius: 8px; background: var(--bg-elev-2);
  border: 1px solid var(--line); font: 12px/1.5 var(--mono); box-shadow: var(--shadow); white-space: nowrap;
}

/* План */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.week-head { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 10px; }
.day-col { min-height: 150px; padding: 10px; border-radius: var(--radius); background: var(--bg-elev); border: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 8px; }
.day-col.today { border-color: var(--accent); }
.day-col header { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-faint); }
.day-col header b { color: var(--text); }
.workout {
  padding: 9px 10px; border-radius: 10px; background: var(--bg-elev-2); border-left: 3px solid var(--zc, var(--line));
  font-size: 13px; cursor: pointer; display: grid; gap: 3px; transition: transform .15s var(--ease);
}
.workout:hover { transform: translateY(-1px); }
.workout b { font-size: 13px; line-height: 1.3; }
.workout small { color: var(--text-faint); }
.workout.done { opacity: .6; } .workout.done b { text-decoration: line-through; }
.add-workout { margin-top: auto; border: 1px dashed var(--line); background: none; border-radius: 8px; color: var(--text-faint); padding: 6px; cursor: pointer; font-size: 13px; }
.add-workout:hover { color: var(--text); border-color: var(--text-faint); }
.days-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.days-picker label { cursor: pointer; }
.days-picker input { position: absolute; opacity: 0; pointer-events: none; }
.days-picker span { display: inline-grid; place-items: center; width: 42px; height: 38px; border-radius: 10px; border: 1px solid var(--line); color: var(--text-dim); font-weight: 600; font-size: 14px; }
.days-picker input:checked + span { background: var(--gradient); color: var(--accent-ink); border-color: transparent; }
.days-picker input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Модальное окно */
.modal-backdrop { position: fixed; inset: 0; z-index: 200; background: rgba(4, 7, 10, .7); display: grid; place-items: center; padding: 20px; animation: fade .15s; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 26px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.modal h2 { font-size: 21px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }

/* Markdown (ответы ИИ) */
.md { display: grid; gap: 10px; line-height: 1.6; }
.md h3, .md h4, .md h5 { font-size: 16px; margin-top: 6px; }
.md ul, .md ol { margin: 0; padding-left: 22px; display: grid; gap: 4px; }
.md code { font-family: var(--mono); background: var(--bg-elev-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md-table { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 10px; }

/* Чат */
.chat { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: calc(100vh - 68px - 56px); min-height: 420px; border-radius: var(--radius-lg); border: 1px solid var(--line-soft); background: var(--bg-elev); overflow: hidden; }
.chat-log { overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.bubble { max-width: min(760px, 88%); padding: 12px 16px; border-radius: 16px; font-size: 15px; }
.bubble.user { align-self: flex-end; background: #1f3a54; border-bottom-right-radius: 5px; white-space: pre-wrap; }
.bubble.assistant { align-self: flex-start; background: var(--bg-elev-2); border-bottom-left-radius: 5px; }
.bubble .tool-note { font-size: 12px; color: var(--text-faint); font-family: var(--mono); margin-bottom: 6px; }
.chat-form { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line-soft); background: var(--bg); }
.chat-form textarea { flex: 1; min-height: 46px; max-height: 160px; resize: none; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; }
.suggestions button { border: 1px solid var(--line); background: var(--bg-elev-2); color: var(--text-dim); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: 14px; }
.suggestions button:hover { color: var(--text); border-color: var(--text-faint); }
.coach-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 18px; }
.conv-list { display: grid; gap: 4px; align-content: start; }
.conv-list button { text-align: left; border: 0; background: none; color: var(--text-dim); padding: 9px 12px; border-radius: 10px; cursor: pointer; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list button:hover, .conv-list button.active { background: var(--bg-elev); color: var(--text); }

/* Устройства */
.device-card { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 18px; align-items: start; }
.device-card .mark { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-weight: 800; font-size: 22px; background: var(--bg-elev-2); border: 1px solid var(--line); }
.device-card .mark.garmin { color: var(--accent-2); } .device-card .mark.coros { color: var(--z5); }
.device-body { display: grid; gap: 10px; }
.steps-list { margin: 0; padding-left: 20px; color: var(--text-dim); font-size: 14px; display: grid; gap: 4px; }
.connect-form { display: flex; gap: 10px; flex-wrap: wrap; }
.connect-form .input { flex: 1; min-width: 220px; }
.token-box { font-family: var(--mono); padding: 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); word-break: break-all; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .coach-layout { grid-template-columns: 1fr; }
  .conv-list { display: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; inset: 0 auto 0 0; width: 270px; transform: translateX(-100%); transition: transform .25s var(--ease); }
  .menu-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .5); }
  .menu-btn { display: block; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 48px; }
  .grid-2, .grid-3, .threshold-cards { grid-template-columns: 1fr; }
  .activity { grid-template-columns: 42px minmax(0, 1fr) auto; }
  .activity .metric.optional { display: none; }
  .device-card { grid-template-columns: 1fr; }
  .chat { height: calc(100vh - 68px - 40px); }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .week { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 18px; }
}

/* Таблица ступеней лактатного теста */
.lt-layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.stage-table th, .stage-table td { padding: 6px 8px; }
.stage-table input.input { min-width: 56px; padding: 6px 8px; }
@media (max-width: 1100px) { .lt-layout { grid-template-columns: 1fr; } }
