/* ==========================================================================
   Family Health Agent — dashboard styles (этап 3)
   Минималистичный, без декораций, мобайл-first.
   ========================================================================== */

:root {
  --c-bg: #fafaf9;
  --c-surface: #ffffff;
  --c-border: #e6e4e1;
  --c-text: #1a1a1a;
  --c-muted: #757575;
  --c-link: #2c5fa8;
  --c-link-hover: #1d4585;
  --c-success: #2d8a4f;
  --c-danger: #b3261e;
  --c-warning: #a86200;
  --c-tag-bg: #f1efee;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04);
  --max: 980px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI",
               system-ui, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--c-link); text-decoration: none; }
a:hover { color: var(--c-link-hover); text-decoration: underline; }

code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: var(--c-tag-bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.9em;
}

.muted { color: var(--c-muted); }
.error { color: var(--c-danger); margin: 0.5rem 0; }

/* --- Topbar --- */
.topbar {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: 0.85rem 1.25rem;
}
.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand {
  font-weight: 500;
  font-size: 1.05rem;
  color: var(--c-text);
}
.nav { flex: 1; display: flex; gap: 1rem; margin-left: 0.5rem; }
.nav a {
  color: var(--c-muted);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
}
.nav a:hover { background: var(--c-tag-bg); color: var(--c-text); text-decoration: none; }
.nav a.active { color: var(--c-text); font-weight: 500; }

.logout-form { margin: 0; }
.logout {
  background: none;
  border: 1px solid var(--c-border);
  color: var(--c-muted);
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
}
.logout:hover { color: var(--c-text); border-color: var(--c-text); }

/* --- Main --- */
.main {
  flex: 1;
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  width: 100%;
}

.page-title { font-size: 1.55rem; font-weight: 500; margin: 0 0 0.25rem; }
.page-sub { margin: 0 0 1.5rem; font-size: 0.92rem; }

.banner {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.banner-info { background: #e8f0f8; color: #1d4585; }
.banner-success { background: #e3f5e9; color: #1f6b3a; }
.banner-warning { background: #fcf2e2; color: #80470c; }
.banner-error { background: #fbe6e4; color: #861f17; }

/* --- Login --- */
.login-card {
  max-width: 360px;
  margin: 4rem auto 0;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1.75rem 1.75rem 1.5rem;
  box-shadow: var(--shadow-card);
}
.login-card h1 { margin: 0 0 0.4rem; font-size: 1.35rem; font-weight: 500; }
.login-form { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.login-form input {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
}
.login-form input:focus { outline: 2px solid var(--c-link); outline-offset: -1px; }
.login-form button {
  padding: 0.65rem;
  background: var(--c-text);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
}
.login-form button:hover { background: #000; }
.footer-note {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--c-muted);
}

/* --- Cards grid (home) --- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.card-link { color: inherit; }
.card-link:hover { border-color: #c7c4c0; text-decoration: none; }

.card-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.4rem;
}
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  background: var(--c-tag-bg);
  border-radius: 50%;
  font-weight: 500;
  color: var(--c-muted);
}
.card-name { margin: 0; font-size: 1.05rem; font-weight: 500; }
.card-meta { margin: 0; font-size: 0.82rem; color: var(--c-muted); }

.card-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.88rem;
  padding: 0.18rem 0;
}
.row-label { color: var(--c-muted); flex-shrink: 0; }
.row-value { text-align: right; }

.aside-note {
  background: #fcf6e7;
  border: 1px solid #e8d99c;
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  color: #6f5410;
}

/* --- Profile page --- */
.profile-head { margin-bottom: 1.5rem; }
.back-link { font-size: 0.88rem; color: var(--c-muted); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.block {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.block-title { margin: 0 0 0.6rem; font-size: 1rem; font-weight: 500; }
.bullets { margin: 0.2rem 0; padding-left: 1.2rem; }
.bullets li { padding: 0.1rem 0; }

/* --- Tables --- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th, .table td {
  padding: 0.5rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid var(--c-border);
}
.table th { color: var(--c-muted); font-weight: 500; font-size: 0.82rem; }
.table tr.overdue td { color: var(--c-danger); }
.table tr.unknown td { color: var(--c-muted); }

/* --- Tags --- */
.tag {
  display: inline-block;
  padding: 1px 7px;
  font-size: 0.72rem;
  background: var(--c-tag-bg);
  border-radius: 10px;
  margin-left: 0.4rem;
  color: #555;
  text-transform: lowercase;
}
.tag-red { background: #fbe6e4; color: var(--c-danger); }
.tag-analysis { background: #e8f0f8; color: #1d4585; }
.tag-ultrasound { background: #efe8f8; color: #4f1d85; }
.tag-visit { background: #e3f5e9; color: #1f6b3a; }
.tag-epicrisis { background: #fcf6e7; color: #6f5410; }
.tag-other { background: var(--c-tag-bg); color: var(--c-muted); }

/* --- Timeline (раскрываемая хронология документов) --- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-row {
  border-bottom: 1px solid var(--c-border);
}
.timeline-row:last-child { border-bottom: none; }

.doc-details summary { list-style: none; cursor: pointer; }
.doc-details summary::-webkit-details-marker { display: none; }

.doc-summary {
  display: flex;
  gap: 1rem;
  padding: 0.65rem 0;
  align-items: baseline;
  user-select: none;
}
.doc-summary::before {
  content: "▸";
  display: inline-block;
  width: 12px;
  margin-right: 0.2rem;
  color: var(--c-muted);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.doc-details[open] > .doc-summary::before {
  transform: rotate(90deg);
}
.doc-summary:hover { background: rgba(0,0,0,0.02); }

.timeline-date {
  flex-shrink: 0;
  width: 90px;
  font-size: 0.83rem;
  color: var(--c-muted);
  font-family: "SF Mono", Menlo, monospace;
}
.timeline-title { font-size: 0.95rem; flex: 1; }

.doc-body {
  padding: 0.4rem 0 1rem 110px;
  font-size: 0.92rem;
}
.doc-section-h {
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-muted);
  margin: 0.9rem 0 0.3rem;
}
.doc-section-text { margin: 0.3rem 0; line-height: 1.6; }
.doc-meta { margin-top: 0.7rem; font-size: 0.82rem; }

@media (max-width: 640px) {
  .doc-body { padding-left: 0; }
  .timeline-date { width: 75px; font-size: 0.78rem; }
}

/* --- Pedigree (markdown rendered) --- */
.prose {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  line-height: 1.7;
}
.prose h2 { font-size: 1.1rem; font-weight: 500; margin-top: 1.5rem; }
.prose h3 { font-size: 1rem; font-weight: 500; margin-top: 1.2rem; }
.prose ul { padding-left: 1.5rem; }
.prose table { border-collapse: collapse; margin: 0.8rem 0; }
.prose table th, .prose table td {
  border: 1px solid var(--c-border);
  padding: 0.4rem 0.7rem;
  text-align: left;
}
.prose code { font-size: 0.92em; }

/* --- Calendar (people-grouped collapsible) --- */
.people-section {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.people-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 0.95rem;
}
.people-summary::-webkit-details-marker { display: none; }
.people-summary::before {
  content: "▸";
  display: inline-block;
  width: 12px;
  margin-right: 0.5rem;
  color: var(--c-muted);
  transition: transform 0.15s;
}
.people-section[open] > .people-summary::before {
  transform: rotate(90deg);
}
.people-section:hover { border-color: #c7c4c0; }
.people-name { font-weight: 500; flex: 1; }
.people-counts { display: flex; gap: 0.4rem; font-size: 0.85rem; color: var(--c-muted); }
.people-body { padding: 0.5rem 1.1rem 1rem; border-top: 1px solid var(--c-border); }

.block-subtitle {
  font-size: 0.85rem;
  font-weight: 500;
  margin: 1rem 0 0.4rem;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag-muted { background: var(--c-tag-bg); color: var(--c-muted); }

.card-row-warning .row-value { font-weight: 500; }

/* --- Timeline filters --- */
.timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.timeline-filters {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.7rem 0.85rem;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.filter-search {
  flex: 1;
  min-width: 200px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}
.filter-search:focus { outline: 2px solid var(--c-link); outline-offset: -1px; }
.filter-select {
  flex: 1;
  min-width: 150px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--c-surface);
}
.filter-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.filter-chip {
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  color: var(--c-muted);
  padding: 0.3rem 0.75rem;
  border-radius: 14px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: all 0.15s;
  font-weight: 400;
}
.filter-chip:hover { border-color: var(--c-text); color: var(--c-text); background: #f4f4f4; }
.filter-chip.active {
  background: var(--c-link);
  color: white;
  border-color: var(--c-link);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(44, 95, 168, 0.3);
}
.filter-chip.active::before {
  content: "✓ ";
  font-weight: 700;
  margin-right: 1px;
}
.filter-chip.active:hover {
  background: var(--c-link-hover);
  border-color: var(--c-link-hover);
}

/* --- Doc scans (PDF→PNG превью) --- */
.doc-scans {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0.4rem 0;
}
.doc-scan {
  display: block;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  overflow: hidden;
  background: #fafafa;
  transition: border-color 0.15s, transform 0.15s;
}
.doc-scan:hover {
  border-color: var(--c-link);
  transform: scale(1.02);
}
.doc-scan img {
  display: block;
  max-width: 180px;
  max-height: 240px;
  width: auto;
  height: auto;
}
@media (max-width: 640px) {
  .doc-scan img { max-width: 130px; max-height: 180px; }
}

/* --- Chat --- */
.chat-shell {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 500px;
}
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--c-border);
}
.chat-actions { display: flex; gap: 0.4rem; }
.chat-btn {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  color: var(--c-muted);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
}
.chat-btn:hover { color: var(--c-text); border-color: var(--c-text); }
.chat-btn-warn { color: var(--c-danger); border-color: #e9b8b3; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.chat-msg { display: flex; flex-direction: column; gap: 0.2rem; }
.chat-msg-user { align-items: flex-end; }
.chat-msg-assistant, .chat-msg-system { align-items: flex-start; }
.chat-bubble {
  max-width: 85%;
  padding: 0.65rem 0.95rem;
  border-radius: 14px;
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 0.95rem;
}
.chat-msg-user .chat-bubble { white-space: pre-wrap; }
.chat-bubble p { margin: 0 0 0.5rem; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { margin: 0.4rem 0; padding-left: 1.4rem; }
.chat-bubble li { margin: 0.15rem 0; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 {
  margin: 0.6rem 0 0.3rem;
  font-size: 1rem;
  font-weight: 500;
}
.chat-bubble code {
  font-size: 0.88em;
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 3px;
}
.chat-msg-user .chat-bubble code { background: rgba(255,255,255,0.18); }
.chat-bubble pre {
  background: rgba(0,0,0,0.05);
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85em;
}
.chat-bubble blockquote {
  border-left: 3px solid var(--c-border);
  margin: 0.4rem 0;
  padding: 0 0.8rem;
  color: var(--c-muted);
}
.chat-bubble a { text-decoration: underline; }
.chat-msg-user .chat-bubble {
  background: var(--c-text);
  color: white;
  border-bottom-right-radius: 4px;
}
.chat-msg-assistant .chat-bubble,
.chat-msg-system .chat-bubble {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-bottom-left-radius: 4px;
}
.chat-msg-system .chat-bubble { background: #fcf6e7; border-color: #e8d99c; color: #6f5410; }
.chat-streaming::after {
  content: " ▊";
  animation: blink 1s steps(2) infinite;
  color: var(--c-muted);
}
@keyframes blink { 50% { opacity: 0; } }
.chat-time {
  font-size: 0.72rem;
  color: var(--c-muted);
  padding: 0 0.5rem;
}

.chat-form {
  border-top: 1px solid var(--c-border);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#chat-input {
  width: 100%;
  resize: vertical;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  min-height: 50px;
}
#chat-input:focus { outline: 2px solid var(--c-link); outline-offset: -1px; }
#chat-input:disabled { background: #f8f8f8; color: var(--c-muted); }
.chat-form-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.chat-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 18px;
  background: var(--c-surface);
}
.chat-upload:hover { border-color: var(--c-text); }
.chat-send {
  padding: 0.6rem 1.5rem;
  background: var(--c-text);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
}
.chat-send:hover { background: #000; }
.chat-send:disabled { background: var(--c-muted); cursor: not-allowed; }

/* --- Footer --- */
.footer {
  background: transparent;
  padding: 1rem 1.25rem 1.5rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--c-muted);
  border-top: 1px solid var(--c-border);
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.footer-tip { font-size: 0.75rem; }
