:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7684;
  --line: #e1e6ec;
  --primary: #2a7de1;
  --primary-dark: #1f63b4;
  --danger: #d64545;
  --ok: #2e9e5b;
  --warn: #d9932c;
  --radius: 12px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 12px 0 0; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
code.pw { font-size: 16px; padding: 3px 8px; user-select: all; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; background: #fff; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px; gap: 16px;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.nav { display: flex; align-items: center; gap: 16px; }
.nav a { color: var(--text); padding: 4px 2px; border-bottom: 2px solid transparent; }
.nav a.active { border-color: var(--primary); }
.nav a:hover { text-decoration: none; color: var(--primary); }
.nav-user { color: var(--muted); }
.avatar-sm { width: 28px; height: 28px; font-size: 13px; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu-list { position: absolute; right: 0; top: 38px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 190px; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 10px 30px rgba(20,40,80,.12); z-index: 20; }
.user-menu-list .btn-link { padding: 0; }
.logout-row { margin-bottom: 20px; }
.tabbar, .fab { display: none; }
.inline { display: inline; }

.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.crumbs { color: var(--muted); margin-bottom: 12px; }
.notes { white-space: pre-wrap; margin-top: 8px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { padding: 7px 10px; }

/* buttons */
.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); cursor: pointer; font: inherit; line-height: 1.2;
}
.btn:hover { border-color: #c5ccd5; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f0c9c9; }
.btn-danger:hover { background: #fdf2f2; }
.btn-link { border: none; background: none; color: var(--primary); padding: 4px 2px; }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-x { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0 4px; }
.btn-x:hover { color: var(--danger); }

/* forms */
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form input, .form select, .form textarea {
  font: inherit; color: var(--text); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid #bcd6f7; border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form .actions { display: flex; gap: 8px; align-items: center; flex-direction: row; }
.form .check { flex-direction: row; align-items: center; }
.hint { font-size: 12px; color: var(--muted); }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert-error { background: #fdf2f2; border-color: #f0c9c9; color: #a33; }
.alert-ok { background: #eefaf2; border-color: #bfe6cd; color: #216b3d; }
.alert-warn { background: #fff7e8; border-color: #f2ddb0; color: #7a5410; }
.auth-card { max-width: 380px; margin: 60px auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.auth-card .form { display: flex; flex-direction: column; gap: 12px; }

/* members */
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.member-card {
  display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; color: var(--text); transition: box-shadow .15s, transform .15s;
}
.member-card:hover { text-decoration: none; box-shadow: 0 6px 20px rgba(20,40,80,.08); transform: translateY(-1px); }
.member-name { font-weight: 600; font-size: 16px; }
.avatar { border-radius: 50%; background: #dfe8f5; color: var(--primary-dark); display: grid; place-items: center; font-weight: 700; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.avatar-xl { width: 110px; height: 110px; font-size: 36px; }
.member-head { display: flex; gap: 20px; align-items: center; }
.member-head-info { flex: 1; }
.member-head-actions { display: flex; gap: 8px; align-items: flex-start; }
.photo-preview img { max-height: 160px; border-radius: 8px; border: 1px solid var(--line); }

/* upload */
.dropzone {
  border: 2px dashed #c9d3e0; border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer;
  background: #fafbfd; transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone:focus { border-color: var(--primary); outline: none; }
.dropzone.drag { background: #e9f2fd; border-color: var(--primary); }
.dropzone-compact { padding: 14px; }
.dz-text { margin-bottom: 6px; }
.dz-buttons { display: none; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.file-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.file-row input[type=file] { flex: 1; min-width: 0; }
.dz-camera { display: none; }
@media (pointer: coarse), (max-width: 720px) {
  .dz-desktop { display: none; }
  .dz-buttons { display: flex; }
  .dz-buttons .btn { flex: 1 1 auto; min-height: 44px; }
  .dz-camera { display: inline-block; }
  .dropzone { padding: 16px 12px; cursor: default; }
}
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.file-list:empty { display: none; }
.file-list li {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px 4px 4px; font-size: 13px; background: #fff;
}
.file-list li img, .file-list li .ph { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: #eef1f5; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.file-list li.err { border-color: #f0c9c9; color: var(--danger); }
.file-list li .prog { height: 3px; background: var(--primary); width: 0; border-radius: 2px; }
.upload-card { border-color: #bcd6f7; }
body.page-drag .dropzone { background: #e9f2fd; border-color: var(--primary); }

/* analyses */
.analysis-list { display: flex; flex-direction: column; }
.analysis-row {
  display: grid; grid-template-columns: 100px 1fr auto; gap: 14px; align-items: center;
  padding: 12px 8px; border-top: 1px solid var(--line); color: var(--text);
}
.analysis-row:first-child { border-top: none; }
.analysis-row:hover { background: #f7f9fc; text-decoration: none; }
.a-date { font-variant-numeric: tabular-nums; color: var(--muted); }
.a-title { font-weight: 600; }
.a-thumbs { display: flex; gap: 4px; align-items: center; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #eef1f5; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--muted); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-top: 12px; }
.gallery-item { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.gallery-item img, .pdf-tile { display: block; width: 100%; height: 160px; object-fit: cover; background: #eef1f5; }
.pdf-tile { display: grid; place-items: center; font-weight: 700; color: var(--danger); font-size: 22px; }
.pdf-tile:hover { text-decoration: none; }
.gallery-item figcaption { padding: 6px 8px; font-size: 13px; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.gallery-item .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.factions { display: flex; gap: 6px; align-items: center; grid-column: 2; grid-row: 1 / span 2; }
.pdf-frame { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
details summary { cursor: pointer; padding: 6px 0; }

/* admin */
.admin-layout { display: grid; grid-template-columns: 200px 1fr; gap: 20px; }
.admin-side { display: flex; flex-direction: column; gap: 4px; }
.admin-side a { padding: 8px 12px; border-radius: 8px; color: var(--text); }
.admin-side a.active { background: var(--card); border: 1px solid var(--line); font-weight: 600; }
.admin-side a:hover { text-decoration: none; background: #e9eef5; }
.admin-main { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.table { width: 100%; border-collapse: collapse; margin-bottom: 24px; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.table input, .table select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; }
.row-off { opacity: .55; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 10px; background: #eef1f5; color: var(--muted); }
.tag-ok { background: #eefaf2; color: var(--ok); }
.tag-off { background: #f4f4f4; color: #777; }
.tag-warn { background: #fff7e8; color: var(--warn); }
.table-audit td { font-size: 13px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; }

/* toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.err { background: var(--danger); }

@media (max-width: 720px) {
  .topbar { padding: 8px 12px; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .member-head { flex-direction: column; align-items: flex-start; }
  .analysis-row { grid-template-columns: 1fr; gap: 6px; }
  .admin-layout { grid-template-columns: 1fr; }
  .admin-side { flex-direction: row; flex-wrap: wrap; }
  .table-stack, .table-stack thead, .table-stack tbody, .table-stack tr, .table-stack td { display: block; }
  .table-stack th { display: none; }
  .table-stack td { border: none; padding: 3px 0; }
  .table-stack tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .table-stack td:empty { display: none; }
}

/* timeline */
.timeline { display: flex; flex-direction: column; gap: 6px; }
.tl-day { display: grid; grid-template-columns: 170px 1fr; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.tl-day:first-child { border-top: none; }
.tl-date { display: flex; flex-direction: column; gap: 2px; padding-top: 10px; position: relative; padding-left: 18px; }
.tl-dot { position: absolute; left: 0; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.tl-items .analysis-row { grid-template-columns: 1fr auto; border-top: none; padding: 8px; border-radius: 8px; }

/* tables */
.table-wrap { overflow-x: auto; }
.table-compact th, .table-compact td { padding: 6px 8px; font-size: 13.5px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.num { text-align: right; }
.row-group td { background: #f4f6f9; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.row-flag td { background: #fff9f2; }
.row-current td { background: #eefaf2; }
.cell-flag { font-weight: 600; }
.cell-H, .cell-L { color: #b5541c; }
.cell-A { color: #a33; }
.arrow { font-size: 11px; margin-left: 2px; }
.pivot .sticky { position: sticky; left: 0; background: var(--card); z-index: 1; min-width: 200px; }
.flag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.flag-N { background: #eefaf2; color: var(--ok); }
.flag-H, .flag-L { background: #fff4e5; color: #b5541c; }
.flag-A { background: #fdf2f2; color: var(--danger); }
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.inline-form input, .inline-form select { padding: 5px 8px; }
.w-90 { width: 90px; } .w-110 { width: 110px; } .w-140 { width: 140px; } .w-180 { width: 180px; }
.cat-title { margin-top: 20px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.explain p { margin: 6px 0; }
.extract-panel { border: 1px solid #bcd6f7; background: #f5f9ff; border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.extract-panel select { max-width: 260px; padding: 4px 6px; font: inherit; }
.extract-panel input { padding: 4px 6px; font: inherit; border: 1px solid var(--line); border-radius: 6px; }
.extract-panel tr.unmatched td { background: #fff7e8; }

/* chart */
.chart-wrap { position: relative; margin: 8px 0 16px; }
.chart { width: 100%; height: auto; display: block; font-family: inherit; }
.chart .ref-band { fill: #2a7de1; fill-opacity: .07; }
.chart .ref-label { font-size: 11px; fill: var(--muted); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { font-size: 11px; fill: var(--muted); }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--card); stroke: var(--primary); stroke-width: 2; }
.chart .pt-out { fill: #fff4e5; stroke: #b5541c; }
.chart .pt-mark { font-size: 12px; font-weight: 700; fill: #b5541c; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .ptg:hover .pt { r: 7; }
.chart .val-label { font-size: 12px; fill: var(--text); font-weight: 600; }
.chart-tip { position: absolute; pointer-events: none; background: #1c2430; color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -130%); }

@media (max-width: 720px) {
  .tl-day { grid-template-columns: 1fr; }
  .tl-date { flex-direction: row; gap: 8px; align-items: baseline; padding-top: 0; }
  .tl-dot { top: 5px; }
}

/* dialogs */
.dlg { border: none; border-radius: 14px; padding: 0; width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(20, 30, 50, .45); }
.dlg > div, .dlg > form { padding: 18px 22px 22px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px 0 !important; }
.dlg-head h2 { margin: 0; }
.dlg .form-grid { margin-top: 8px; }

/* treatment form rows */
.tx-rows { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.tx-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1.4fr 1fr 1fr .7fr auto; gap: 8px; align-items: end; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfd; }
.tx-row .tx-remove { align-self: center; }
.tx-common { margin-top: 12px; }
.tx-row input, .tx-row select { min-width: 0; width: 100%; }

/* treatment chips + lane */
.tx-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 7px; border-radius: 12px; background: #eef1f5; color: var(--text); font-size: 12.5px; line-height: 1.3; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.tx-chip:hover { text-decoration: none; filter: brightness(.97); }
.tx-chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #6b7684); flex-shrink: 0; }
.tx-chip.tx-start { font-weight: 600; }
.tx-chip.tx-end { opacity: .8; }
.tx-c0 { --c: #2a7de1; background: #e6f0fc; } .tx-c1 { --c: #d9932c; background: #fdf1de; } .tx-c2 { --c: #2e9e5b; background: #e4f5ea; }
.tx-c3 { --c: #8b5cf6; background: #efe9fd; } .tx-c4 { --c: #d64545; background: #fbe6e6; } .tx-c5 { --c: #0f8f9e; background: #dff4f6; }
.tx-c6 { --c: #b45f8c; background: #f7e6ef; } .tx-c7 { --c: #6b7684; background: #eceff3; }
.current-tx { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }

.timeline.has-tx .tl-day, .timeline.has-tx .tl-head { grid-template-columns: auto 190px 150px 1fr; }
.tl-head { display: grid; gap: 12px; padding: 0 0 6px; }
.tl-head-tx { grid-column: span 2; }
.tl-lane-head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.timeline.has-tx { gap: 0; }
.tx-tracks { display: flex; gap: 4px; align-items: stretch; margin: -9px 0 -8px; }
.tx-track { width: 12px; display: flex; justify-content: center; align-items: stretch; }
.tx-bar { display: block; width: 6px; background: var(--c); opacity: .85; min-height: 100%; }
.tx-bar:hover { opacity: 1; width: 8px; }
.tx-bar.is-start { border-radius: 0 0 4px 4px; margin-top: 0; }
.tx-bar.is-end { border-radius: 4px 4px 0 0; }
.tx-bar.is-start.is-end, .tx-bar.is-once { border-radius: 4px; min-height: 0; height: 22px; align-self: center; width: 10px; }
.tx-labels { display: flex; flex-direction: column; gap: 4px; justify-content: flex-start; padding: 18px 8px 10px 0; min-width: 0; border-right: 1px solid var(--line); margin: -9px 0 -8px; }
.tx-labels .tx-chip { max-width: 100%; }
.tl-empty { padding: 12px 8px; }

@media (max-width: 900px) {
  .tx-row { grid-template-columns: 1fr 1fr; }
}

/* AI panel *//* AI panel */
.ai-card { border-color: #d9c8f5; }
.tabs { display: flex; gap: 4px; background: #eef1f5; padding: 3px; border-radius: 10px; }
.tab { border: none; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; font: inherit; color: var(--muted); }
.tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.ai-messages { display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow-y: auto; padding: 4px 2px; }
.ai-msg { border-radius: 12px; padding: 10px 14px; max-width: 100%; }
.ai-user { background: #eef3fb; align-self: flex-end; max-width: 85%; }
.ai-assistant { background: #f7f5fc; border: 1px solid #e6dff5; }
.ai-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.ai-body h3, .ai-body h4, .ai-body h5 { margin: 12px 0 6px; font-size: 15px; }
.ai-body h3:first-child { margin-top: 0; }
.ai-body p { margin: 6px 0; }
.ai-body ul, .ai-body ol { margin: 6px 0 6px 20px; padding: 0; }
.ai-body li { margin: 3px 0; }
.ai-body .md-table { margin: 8px 0; font-size: 13px; }
.ai-body pre { background: #eef1f5; padding: 8px 10px; border-radius: 8px; overflow-x: auto; }
.ai-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-form textarea { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; resize: vertical; }
.ai-form textarea:focus { outline: 2px solid #bcd6f7; border-color: var(--primary); }
.ai-thinking { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; padding: 8px 0; }
.ai-thinking i { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-history { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.ai-history details { margin: 6px 0; }
.ai-history summary { cursor: pointer; color: var(--primary); }
.check.inline { display: inline-flex; gap: 4px; align-items: center; margin-left: 6px; }

.ai-row { background: #faf8ff; border-radius: 8px; }
.ai-row:hover { background: #f3effc; }
.thumb-ai { background: #efe9fd; color: #6d4fc4; }
.ai-msg.ai-flash { outline: 2px solid #8b5cf6; }

.cc-box { border: 1px solid #d9c8f5; background: #faf8ff; border-radius: 10px; padding: 12px 14px; }
.cc-box h3 { margin: 0 0 6px; }
.cc-step { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; }
.cc-link { word-break: break-all; font-size: 12px; }

/* ---------- телефон ---------- */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .container { margin: 12px auto; padding: 0 12px; }
  .card { padding: 14px; margin-bottom: 12px; border-radius: 12px; }
  h1 { font-size: 21px; }
  h2 { font-size: 17px; }
  .crumbs { margin-bottom: 8px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* без масштабирования полей в iOS */
  .form input, .form select, .form textarea, .filters input, .filters select, .ai-form textarea, .inline-form input, .inline-form select, .table input, .table select { font-size: 16px; }
  .btn { padding: 10px 14px; min-height: 42px; }
  .btn-sm { min-height: 34px; padding: 6px 10px; }
  .btn-x { min-width: 36px; min-height: 36px; font-size: 16px; }
  .form .actions { flex-wrap: wrap; }
  .form .actions .btn-primary { flex: 1 1 auto; }

  /* шапка + нижняя навигация */
  .topbar { padding: 8px 12px; }
  .nav { display: none; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); min-width: 0; }
  .tabbar a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .tabbar a.active { color: var(--primary); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  body.has-tabbar .container { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); text-align: center; }

  /* плавающая кнопка «снять анализ» */
  .fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%; background: var(--primary); color: #fff; border: none; box-shadow: 0 8px 22px rgba(42,125,225,.45); z-index: 15; cursor: pointer; }
  .fab svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
  .fab:active { transform: scale(.95); }

  /* карточка члена семьи */
  .member-head { flex-direction: row; flex-wrap: wrap; gap: 12px; align-items: center; }
  .avatar-xl { width: 68px; height: 68px; font-size: 24px; }
  .member-head-info { flex: 1; min-width: 0; }
  .member-head-info h1 { font-size: 20px; margin-bottom: 4px; }
  .member-head-actions { width: 100%; flex-wrap: wrap; }
  .member-head-actions .btn { flex: 1 1 40%; text-align: center; }
  .member-head-actions form { flex: 1 1 40%; display: flex; }
  .member-head-actions form .btn { width: 100%; }
  .page-head { flex-wrap: wrap; }

  /* диалоги — нижний лист во весь экран */
  .dlg { position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: 100%; max-height: 94dvh; border-radius: 16px 16px 0 0; overflow: auto; -webkit-overflow-scrolling: touch; }
  .dlg > div, .dlg > form { padding: 14px 14px calc(16px + env(safe-area-inset-bottom)); }
  .dlg-head { padding: 12px 14px 0 !important; position: sticky; top: 0; background: var(--card); z-index: 1; }
  .dlg-head h2 { font-size: 17px; }
  .dlg .form-grid { grid-template-columns: 1fr; }
  .dlg .form-grid .span-2 { grid-column: span 1; }
  .tx-row { grid-template-columns: 1fr 1fr; padding: 10px 10px 10px; position: relative; }
  .tx-row label:first-child { grid-column: span 2; }
  .tx-row .tx-remove { position: absolute; top: 6px; right: 6px; }

  /* фильтры хронологии */
  .list-head { gap: 8px; }
  .filters { width: 100%; }
  .filters input { flex: 1 1 100%; }
  .filters select { flex: 1 1 auto; }

  /* хронология: полосы лечения слева, справа дата → препараты → документы */
  .tl-head { display: none; }
  .timeline .tl-day { grid-template-columns: 1fr; gap: 6px; padding: 10px 0; }
  .timeline.has-tx .tl-day { grid-template-columns: auto 1fr; grid-template-areas: "tracks date" "tracks labels" "tracks items"; column-gap: 10px; row-gap: 4px; }
  .tx-tracks { grid-area: tracks; gap: 3px; margin: -11px 0 -10px; }
  .tx-track { width: 9px; }
  .tx-bar { width: 5px; }
  .tx-bar.is-start.is-end, .tx-bar.is-once { width: 9px; height: 18px; }
  .tx-labels { grid-area: labels; flex-direction: row; flex-wrap: wrap; padding: 0; margin: 0; border: none; gap: 4px; }
  .tx-labels.is-empty { display: none; }
  .tl-date { grid-area: date; flex-direction: row; gap: 8px; align-items: baseline; padding-top: 0; padding-left: 16px; }
  .tl-dot { top: 5px; width: 9px; height: 9px; }
  .tl-items { grid-area: items; min-width: 0; }
  .tl-items .analysis-row { grid-template-columns: 1fr; gap: 6px; padding: 8px 6px; }
  .analysis-row { grid-template-columns: 1fr; gap: 6px; }
  .a-main { min-width: 0; }
  .a-thumbs { flex-wrap: wrap; }
  .thumb { width: 52px; height: 52px; }
  .tl-empty { padding: 4px 6px; }
  .ai-row .a-thumbs { display: none; }
  .ai-row .a-title::before { content: "ИИ"; display: inline-block; font-size: 10px; font-weight: 700; color: #6d4fc4; background: #efe9fd; border-radius: 6px; padding: 1px 5px; margin-right: 6px; vertical-align: middle; }
  .current-tx { gap: 4px; }

  /* панель ИИ */
  .ai-card .list-head { flex-direction: column; align-items: stretch; }
  .tabs { width: 100%; }
  .tab { flex: 1; text-align: center; }
  .ai-messages { max-height: 55vh; }
  .ai-user { max-width: 95%; }
  .ai-form .actions .btn-link { padding: 6px 4px; }

  /* таблицы: прокрутка по горизонтали, компактнее */
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .table-compact th, .table-compact td { padding: 6px 6px; font-size: 13px; }
  .pivot .sticky { min-width: 140px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .gallery-item img, .pdf-tile { height: 130px; }
  .pdf-frame { height: 60vh; }
  .auth-card { margin: 24px auto; padding: 20px; }
  .admin-side { gap: 6px; }
  .admin-side a { padding: 8px 10px; font-size: 14px; background: var(--card); border: 1px solid var(--line); }
  .admin-main { padding: 14px; }
  .inline-form input, .inline-form select { flex: 1 1 45%; min-width: 0; }
  .w-90, .w-110, .w-140, .w-180 { width: auto; }
  .cc-step input[data-cc-code] { width: 100% !important; }
}

/* iOS standalone (добавлено на экран «Домой»): не даём случайного «pull-to-refresh» в диалогах */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
}

/* вход через мессенджеры, семьи */
.auth-wide { max-width: 460px; }
.auth-buttons { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 10px; }
.auth-buttons .btn { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 14px; font-size: 15px; font-weight: 600; }
.btn-tg { background: #2aabee; border-color: #2aabee; color: #fff; }
.btn-tg:hover { background: #1f98d6; text-decoration: none; }
.btn-tg svg { width: 22px; height: 22px; }
.btn-max { background: #6f2cff; border-color: #6f2cff; color: #fff; }
.btn-max:hover { background: #5b1fe0; text-decoration: none; }
.max-mark { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: #fff; color: #6f2cff; font-weight: 800; font-size: 14px; }
.auth-qr { margin: 8px 0 12px; }
.qr-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }
.qr-row figure { margin: 0; text-align: center; }
.qr-row figure svg { width: 150px; height: 150px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qr-row figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.auth-password { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 10px; }
.auth-password summary { color: var(--primary); cursor: pointer; margin-bottom: 8px; }
.err-text { color: var(--danger); }
.invite-list { list-style: none; margin: 10px 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.invite-list li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.invite-link input { width: 100%; font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fafbfd; }
.linked-list { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 720px) {
  .qr-row { display: none; }   /* на телефоне QR не нужен — кнопка открывает мессенджер */
  .auth-qr > .muted { display: none; }
}

/* карточки людей в семье */
.member-card-wide { flex-direction: column; align-items: stretch; gap: 8px; }
.member-card-wide:hover { transform: none; }
.member-card-main { display: flex; gap: 14px; align-items: center; color: var(--text); }
.member-card-main:hover { text-decoration: none; }
.member-card-tools { border-top: 1px dashed var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.member-card-tools .inline-form { margin: 0; }
.member-card-tools select { max-width: 100%; }
.member-card.is-focus { outline: 2px solid var(--primary); }
.link-box { border: 1px solid #bcd6f7; background: #f5f9ff; border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.qr-details summary { cursor: pointer; font-size: 13px; color: var(--primary); }
.qr-small svg { width: 140px; height: 140px; background: #fff; border: 1px solid var(--line); border-radius: 6px; margin-top: 6px; }

/* форма загрузки: режим авто/вручную */
.mode-tabs .tab { flex: 1; text-align: center; }
.mode-tabs .tab:disabled { opacity: .5; cursor: not-allowed; }
.mode-fields { border: none; padding: 0; margin: 0; min-width: 0; }

/* хронология: компактный / подробный вид */
.tl-view-tabs .tab { padding: 5px 12px; font-size: 13px; }
.ev { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ev, #6b7684); vertical-align: middle; }
.ev-doc { --ev: #2a7de1; } .ev-ai { --ev: #8b5cf6; } .ev-tx { --ev: #2e9e5b; border-radius: 2px; height: 4px; width: 12px; }
.ev-food { --ev: #e0872a; } .ev-sport { --ev: #2e9e5b; } .ev-med { --ev: #d64545; } .ev-water { --ev: #0f8f9e; }
.tl-legend { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tl-legend .ev { margin-right: 4px; }
.tl-compact { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.tl-strip-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.tl-strip { display: flex; gap: 3px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: thin; }
.tl-cell, .tl-mcell { position: relative; border: 1px solid transparent; border-radius: 7px; background: #f4f6f9; font: inherit; color: var(--text); cursor: pointer; padding: 4px 0 7px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.tl-cell { flex: 1 0 27px; min-width: 27px; font-size: 12px; }
.tl-cell:disabled, .tl-mcell:disabled { cursor: default; color: var(--muted); }
.tl-cell.has-events, .tl-mcell.has-events { background: #fff; border-color: #dfe5ec; }
.tl-cell.is-today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); font-weight: 700; }
.tl-cell.is-future, .tl-mcell.is-future { opacity: .4; }
.tl-cell.is-open, .tl-mcell.is-open { background: #e6f0fc; border-color: var(--primary); }
.tl-cell:not(:disabled):hover, .tl-mcell:not(:disabled):hover { border-color: var(--primary); }
.tl-dots { display: flex; gap: 2px; height: 7px; align-items: center; justify-content: center; }
.tl-dots .ev { width: 6px; height: 6px; }
.tl-tx { position: absolute; left: 4px; right: 4px; bottom: 2px; height: 3px; display: flex; gap: 1px; }
.tl-tx i { flex: 1; border-radius: 2px; background: var(--c, #6b7684); }
.tl-calendar { display: flex; flex-direction: column; gap: 6px; }
.tl-year { display: grid; grid-template-columns: 48px 1fr; gap: 6px; align-items: center; }
.tl-year-label { font-weight: 600; color: var(--muted); font-size: 13px; }
.tl-year-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; }
.tl-mcell { font-size: 11.5px; padding: 4px 2px 8px; min-height: 46px; }
.tl-mcell b { font-weight: 500; }
.tl-mcell .tl-count { font-size: 11px; color: var(--muted); line-height: 1; }
.tl-mcell.is-current { border-color: var(--primary); }
.tl-compact-hint { margin: 0; }
.tl-month { display: flex; flex-direction: column; }
.tl-month-head { display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: #f4f6f9; border-radius: 8px; padding: 7px 12px; margin: 8px 0 4px; font: inherit; font-weight: 600; color: var(--text); cursor: pointer; text-align: left; }
.tl-month-head:hover { background: #eef1f5; }
.tl-month-badges { flex: 1; font-weight: 400; }
.tl-month-arrow { color: var(--muted); transition: transform .15s; }
.tl-month.is-collapsed .tl-month-arrow, .timeline[data-view=compact] .tl-month:not(.is-open) .tl-month-arrow { transform: rotate(-90deg); }
.tl-month.is-collapsed .tl-month-body { display: none; }
.tl-month-body .tl-day:first-child { border-top: none; }
/* компактно: строка дней и календарь вместо ленты; месяцы раскрываются по нажатию */
.timeline[data-view=compact] .tl-head { display: none; }
.timeline[data-view=compact] .tl-month:not(.is-open) { display: none; }
.timeline[data-view=compact] .tl-month.is-open .tl-month-arrow { transform: none; }
.timeline[data-view=full] .tl-compact { display: none; }
@media (max-width: 720px) {
  .tl-year { grid-template-columns: 1fr; gap: 3px; }
  .tl-year-grid { grid-template-columns: repeat(6, 1fr); }
  .tl-cell { flex: 0 0 30px; min-width: 30px; }
  .tl-month-head { flex-wrap: wrap; padding: 7px 10px; }
  .tl-month-badges { flex-basis: 100%; order: 3; }
}

/* дневник */
.journal-card { border-color: #d5e6d9; }
.j-summary { margin-top: 2px; }
.j-quick { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }
.j-qbtn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 9px 14px; font: inherit; font-weight: 600; color: var(--text); cursor: pointer; flex: 1 1 120px; justify-content: center; }
.j-qbtn:hover { border-color: var(--primary); background: #f5f9ff; }
.j-ico { font-size: 18px; }
.j-food { --jc: #e0872a; } .j-water { --jc: #0f8f9e; } .j-sport { --jc: #2e9e5b; } .j-med { --jc: #d64545; } .j-note { --jc: #6b7684; }
.j-qbtn { border-left: 4px solid var(--jc, var(--line)); }
.j-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.j-item { display: grid; grid-template-columns: 48px 1fr auto auto; gap: 10px; align-items: center; padding: 7px 8px; border-top: 1px solid var(--line); border-left: 3px solid var(--jc, var(--line)); }
.j-item:first-child { border-top: none; }
.j-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.j-line { min-width: 0; overflow-wrap: anywhere; }
.j-photo img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.j-empty { padding: 12px 0; }
.dlg-journal .form { display: flex; flex-direction: column; gap: 12px; }
.j-kind-tabs { flex-wrap: wrap; }
.j-kind-tabs .tab { flex: 1 1 auto; padding: 6px 8px; font-size: 13px; }
.j-pane { display: flex; flex-direction: column; gap: 10px; }
.j-presets { display: flex; gap: 8px; flex-wrap: wrap; }
.j-presets .btn { flex: 1 1 auto; }
.j-medbtn { font-size: 14px; padding: 8px 12px; border: 1px solid transparent; cursor: pointer; }
.j-photo-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.j-kbju { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.j-time-row { max-width: 260px; }
.j-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.j-nav-form input { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; }
.tl-items .j-row .a-main { min-width: 0; }
.ai-head-right { display: flex; gap: 10px; align-items: center; }
.ai-close { font-size: 18px; }
.ai-reopen { margin-bottom: 14px; }
@media (max-width: 720px) {
  .j-qbtn { flex: 1 1 calc(50% - 8px); padding: 10px 8px; }
  .j-item { grid-template-columns: 44px 1fr auto; }
  .j-item .j-photo { grid-column: 2; }
  .j-kbju { grid-template-columns: repeat(2, 1fr); }
  .j-time-row { max-width: none; }
}

/* курсы лечения внутри дневника */
.j-courses { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.j-courses > summary { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px 12px; cursor: pointer; list-style: none; font-weight: 600; }
.j-courses > summary::-webkit-details-marker { display: none; }
.j-courses-title::before { content: "▸ "; color: var(--muted); font-weight: 400; }
.j-courses[open] .j-courses-title::before { content: "▾ "; }
.j-courses-now { display: flex; gap: 6px; flex-wrap: wrap; font-weight: 400; }
@media (max-width: 720px) {
  .j-courses > summary { grid-template-columns: 1fr auto; }
  .j-courses-title { grid-row: 1; grid-column: 1; }
  .j-courses > summary > .btn { grid-row: 1; grid-column: 2; }
  .j-courses-now { grid-row: 2; grid-column: 1 / -1; }
}
.j-courses .table-wrap { margin-top: 10px; }
