/* CoachOS – application styles.
   Neutral palette with brand tokens (--primary/--accent) that the admin can
   override in Settings > Branding. Responsive, keyboard friendly. */

:root {
    --primary: #2563eb;
    --accent: #16a34a;
    --bg: #f4f6fa;
    --surface: #ffffff;
    --border: #e5e9f0;
    --text: #1a2233;
    --muted: #6b7486;
    --red: #dc2626;
    --orange: #ea881c;
    --yellow: #d4a11a;
    --green: #16a34a;
    --blue: #2563eb;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .2rem; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.small { font-size: .82rem; }
.muted { color: var(--muted); }
.mt { margin-top: 1rem; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.grow { flex: 1; }
.link { color: var(--primary); font-weight: 500; }

/* ---- Shell layout ------------------------------------------------------ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1rem .75rem;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem; }
.brand-logo {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--primary); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1.05rem; flex-shrink: 0;
}
.brand-logo-img { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; }
.sidebar-nav { display: flex; flex-direction: column; gap: .15rem; }
.nav-item {
    display: flex; align-items: center; gap: .65rem;
    padding: .55rem .7rem; border-radius: 9px;
    color: var(--text); font-size: .92rem; font-weight: 500;
}
.nav-item:hover { background: var(--bg); text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { width: 1.35rem; display: inline-flex; align-items: center; justify-content: center; }
.nav-icon .icon { width: 18px; height: 18px; }
.nav-disabled { color: var(--muted); cursor: not-allowed; opacity: .7; }
.sidebar-section-title {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); padding: .4rem .7rem .2rem;
}
.sidebar-backdrop { display: none; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---- Topbar ------------------------------------------------------------- */
.topbar {
    display: flex; align-items: center; gap: 1rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: .6rem 1.25rem; position: sticky; top: 0; z-index: 40;
}
.icon-btn.sidebar-toggle { display: none; }
.global-search { position: relative; flex: 1; max-width: 420px; }
.global-search input {
    width: 100%; padding: .5rem .9rem; border: 1px solid var(--border);
    border-radius: 999px; background: var(--bg); font-size: .9rem;
}
.search-results {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; z-index: 60;
}
.search-results a {
    display: block; padding: .55rem .9rem; color: var(--text); font-size: .88rem;
}
.search-results a:hover, .search-results a:focus { background: var(--bg); text-decoration: none; }
.search-results .sub { color: var(--muted); font-size: .78rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.icon-btn {
    background: none; border: none; cursor: pointer; font-size: 1.05rem;
    padding: .45rem .55rem; border-radius: 9px; color: var(--text); position: relative;
    display: inline-flex; align-items: center;
}
.icon-btn:hover { background: var(--bg); text-decoration: none; }
.notification-btn .icon { width: 20px; height: 20px; display: block; }
.notification-dot {
    position: absolute; top: 2px; right: 0;
    background: var(--red); color: #fff; font-size: .62rem;
    border-radius: 999px; padding: 0 4px; line-height: 1.4;
}
.profile-btn {
    display: flex; align-items: center; gap: .5rem; cursor: pointer;
    background: none; border: none; padding: .3rem .5rem; border-radius: 9px;
    font-size: .9rem; color: var(--text);
}
.profile-btn:hover { background: var(--bg); }
.dropdown { position: relative; }
.dropdown-menu {
    display: none; position: absolute; right: 0; top: calc(100% + 6px);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    min-width: 180px; padding: .35rem; z-index: 60;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-link-btn {
    display: block; width: 100%; text-align: left; padding: .5rem .7rem;
    border-radius: 7px; color: var(--text); font-size: .88rem;
    background: none; border: none; cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-link-btn:hover { background: var(--bg); text-decoration: none; }
.dropdown-divider { border-top: 1px solid var(--border); margin: .3rem 0; }

/* ---- Content ------------------------------------------------------------ */
.content { padding: 1.5rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.page-head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.client-head { display: flex; align-items: center; gap: 1rem; }

/* ---- Cards --------------------------------------------------------------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1.1rem 1.25rem; margin-bottom: 1.25rem;
}
.card-inner { box-shadow: none; }
.card-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; margin-bottom: .75rem;
}
.card-head h2 { margin-bottom: .1rem; }
.danger-zone {
    border: 1px solid #fecaca;
    background: #fff1f2;
    box-shadow: 0 1px 2px rgba(185, 28, 28, .04);
    margin-top: 2.5rem;
    padding: 1.5rem 1.75rem;
}
.danger-zone h2 { color: #b91c1c; margin-bottom: .5rem; }
.danger-zone p { margin: 0 0 1.25rem; font-size: .9rem; color: #7f1d1d; max-width: 60ch; }

/* ---- Stat widgets --------------------------------------------------------- */
.stat-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 1rem; margin-bottom: 1.25rem;
}
.stat-card { margin-bottom: 0; }
.stat-head { display: flex; justify-content: space-between; align-items: center; }
.stat-period-switch { display: inline-flex; gap: .2rem; font-size: .72rem; }
.stat-period-switch a { padding: .1rem .4rem; border-radius: 6px; color: var(--muted); }
.stat-period-switch a.active { background: var(--primary); color: #fff; }
.stat-value a { color: inherit; }
.stat-value a:hover { text-decoration: underline; }
.stat-label {
    font-size: .72rem; font-weight: 600; letter-spacing: .05em;
    text-transform: uppercase; color: var(--muted);
}
.stat-icon {
    width: 34px; height: 34px; border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1rem;
}
.stat-icon-blue { background: #e4edff; color: var(--blue); }
.stat-icon-green { background: #e2f6e9; color: var(--green); }
.stat-icon-teal { background: #dff4f2; color: #0f9488; }
.stat-icon-red { background: #fde8e8; color: var(--red); }
.stat-value { font-size: 1.7rem; font-weight: 700; margin: .35rem 0 .1rem; }
.stat-value-sm { font-size: 1.25rem; font-weight: 700; }
.stat-sub { font-size: .8rem; }
.stat-grid-secondary .stat-card-mini {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .8rem 1.1rem;
}

.dashboard-columns { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; align-items: start; }
.dashboard-main, .dashboard-side { min-width: 0; }

/* ---- Client rows (dashboard lists) --------------------------------------- */
.client-list { display: flex; flex-direction: column; gap: .5rem; }
.client-row {
    display: grid;
    grid-template-columns: auto minmax(160px, 1.4fr) minmax(90px, .8fr) minmax(130px, 1fr) minmax(120px, 1fr);
    gap: .9rem; align-items: center;
    border: 1px solid var(--border); border-radius: 10px;
    padding: .65rem .9rem; color: var(--text);
}
.client-row:hover { background: var(--bg); text-decoration: none; }
.client-row-name { display: flex; align-items: center; gap: .45rem; font-weight: 600; flex-wrap: wrap; }
.client-row-main { min-width: 0; }
.client-row-metric { display: flex; flex-direction: column; gap: .1rem; }
.metric-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.metric-value { font-weight: 600; font-size: .9rem; }

.bar { display: block; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; max-width: 110px; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--green); }
.bar-orange { background: var(--orange); }
.bar-red { background: var(--red); }
.bar-green { background: var(--green); }

/* ---- Avatars --------------------------------------------------------------- */
.avatar {
    width: 38px; height: 38px; border-radius: 999px; flex-shrink: 0;
    background: #e4edff; color: var(--primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem;
}
.avatar-sm { width: 30px; height: 30px; font-size: .72rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.15rem; }
.avatar-xl { width: 84px; height: 84px; font-size: 1.6rem; }
.avatar-img { object-fit: cover; }

/* ---- Badges ------------------------------------------------------------------ */
.badge {
    display: inline-block; padding: .12rem .55rem; border-radius: 999px;
    font-size: .72rem; font-weight: 600; white-space: nowrap;
}
.badge-green { background: #e2f6e9; color: #157347; }
.badge-red { background: #fde8e8; color: #b91c1c; }
.badge-red-soft { background: #fdf0ef; color: #c2410c; }
.badge-orange { background: #fdefdd; color: #b45309; }
.badge-orange-soft { background: #fdf4e5; color: #b45309; }
.badge-yellow { background: #fbf3d7; color: #92700c; }
.badge-blue { background: #e4edff; color: #1d4ed8; }
.badge-gray { background: #eef1f5; color: #5b6472; }
.badge-btn { border: none; cursor: pointer; }

/* ---- Buttons -------------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1rem; border-radius: 9px; border: 1px solid transparent;
    font-size: .9rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger-soft { background: #fde8e8; color: #b91c1c; }
.btn-danger { background: #b91c1c; color: #fff; }
.btn-danger:hover { filter: brightness(1.05); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }
.inline-form { display: inline; }

/* ---- Forms ------------------------------------------------------------------------- */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .9rem; }
input, select, textarea {
    display: block; width: 100%; margin-top: .3rem;
    padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 9px;
    font-size: .92rem; font-family: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus, .btn:focus, .tab:focus, a:focus {
    outline: 2px solid var(--primary); outline-offset: 1px;
}
input[type="color"] { padding: .2rem; height: 42px; }
input[type="file"] { padding: .4rem; }
input[type="checkbox"], input[type="radio"] {
    display: inline-block; width: auto; margin: 0 .45rem 0 0;
    accent-color: var(--primary);
}
.checkbox { display: flex; align-items: flex-start; gap: .35rem; font-weight: 400; }
.checkbox input { margin-top: .2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 1.25rem; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: .6rem; margin-top: .5rem; }
.filter-bar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filter-bar input, .filter-bar select { width: auto; margin-top: 0; }
.filter-bar .checkbox { margin-bottom: 0; }
.filter-inline { display: flex; align-items: center; gap: .4rem; margin-bottom: 0; font-weight: 500; font-size: .82rem; color: var(--muted); }
.filter-inline input { margin-top: 0; }

/* ---- Tables ------------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th {
    text-align: left; padding: .55rem .7rem;
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); border-bottom: 1px solid var(--border);
}
.table td { padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-hover tbody tr:hover { background: var(--bg); }
.table-client { display: flex; align-items: center; gap: .6rem; color: var(--text); }
.th-actions, .td-actions { text-align: right; white-space: nowrap; }
.td-actions form { margin-left: .3rem; }

/* ---- Tabs --------------------------------------------------------------------------- */
.tabs {
    display: flex; gap: .25rem; flex-wrap: wrap;
    border-bottom: 1px solid var(--border); margin-bottom: 1.25rem;
}
.tab {
    padding: .5rem .8rem; font-size: .88rem; font-weight: 500; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---- Lists -------------------------------------------------------------------------- */
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1.25rem; margin: 0; font-size: .9rem; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; font-weight: 500; }
.detail-list-inline { display: flex; flex-wrap: wrap; gap: .35rem 1rem; }
.detail-list-inline dt { margin-left: 1.25rem; }
.detail-list-inline dt:first-of-type { margin-left: 0; }
.list-item { display: flex; align-items: center; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list-item:last-of-type { border-bottom: none; }

.activity-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .7rem; }
.activity-list li { display: flex; gap: .7rem; align-items: flex-start; }
.activity-dot { width: 9px; height: 9px; border-radius: 999px; background: var(--border); margin-top: .45rem; flex-shrink: 0; }
.activity-dot.unread { background: var(--primary); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: .8rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: none; }
.timeline-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--primary); margin-top: .45rem; flex-shrink: 0; }
.timeline-note { background: var(--yellow); }
.timeline-upload { background: var(--orange); }
.timeline-status { background: var(--muted); }
.timeline-created, .timeline-onboarding { background: var(--green); }

.task-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .45rem; }
.task-item {
    display: flex; align-items: center; gap: .7rem;
    border: 1px solid var(--border); border-radius: 10px; padding: .55rem .75rem;
}
.task-check-form { display: flex; }
.task-check {
    width: 21px; height: 21px; border-radius: 999px; border: 2px solid var(--border);
    background: var(--surface); cursor: pointer; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center; font-size: .7rem; color: #fff;
}
.task-check:hover { border-color: var(--primary); }
.task-check.checked { background: var(--green); border-color: var(--green); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; font-size: .9rem; }
.task-title.done { text-decoration: line-through; color: var(--muted); }

.checklist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .55rem; }
.checklist li { display: flex; align-items: center; gap: .6rem; font-weight: 500; }
.checklist li.done { color: var(--muted); }
.check-icon {
    width: 24px; height: 24px; border-radius: 999px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--border); color: var(--muted); font-size: .8rem;
}
.checklist li.done .check-icon { background: var(--green); color: #fff; }

/* ---- Misc boxes --------------------------------------------------------------------- */
.alert { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: .9rem; }
.alert-success { background: #e2f6e9; color: #157347; }
.alert-error { background: #fde8e8; color: #b91c1c; }
.alert-info { background: #e3edfd; color: #1d4ed8; }
.entry-type-toggle { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.empty-state { color: var(--muted); padding: 1rem 0; text-align: center; font-size: .9rem; }
.placeholder-box {
    border: 1px dashed var(--border); border-radius: 10px;
    padding: .8rem 1rem; margin-top: .8rem;
    color: var(--muted); font-size: .84rem; background: var(--bg);
}
.ai-box {
    border: 1px solid #dbe7ff; background: #f4f8ff;
    border-radius: 10px; padding: .8rem 1rem; margin-bottom: .8rem;
}
.ai-box-empty { border-style: dashed; background: var(--bg); border-color: var(--border); }
.ai-box-head { font-weight: 600; font-size: .85rem; margin-bottom: .35rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.invite-link { word-break: break-all; font-size: .82rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
.two-col .card { margin-bottom: 0; }

/* ---- Auth / setup pages --------------------------------------------------------------- */
.auth-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1.5rem; background: var(--bg);
}
.auth-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; box-shadow: var(--shadow);
    padding: 2rem; width: 100%; max-width: 420px;
}
.auth-card-wide { max-width: 640px; }
.auth-brand { display: flex; align-items: center; gap: .7rem; margin-bottom: 1.4rem; }
.auth-links { text-align: center; font-size: .86rem; margin-top: 1rem; }
.lang-switch { margin-left: auto; display: flex; gap: .3rem; font-size: .8rem; }
.lang-switch a { padding: .2rem .45rem; border-radius: 6px; color: var(--muted); }
.lang-switch a.active { background: var(--primary); color: #fff; }

.setup-steps { display: flex; gap: .5rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.setup-step {
    display: flex; align-items: center; gap: .45rem;
    font-size: .82rem; color: var(--muted);
    padding: .35rem .7rem; border-radius: 999px; background: var(--bg);
}
.setup-step.current { background: var(--primary); color: #fff; }
.setup-step.done { background: #e2f6e9; color: #157347; }
.step-num {
    width: 18px; height: 18px; border-radius: 999px; background: rgba(0,0,0,.12);
    display: inline-flex; align-items: center; justify-content: center; font-size: .7rem;
}

/* ---- Anamnesis builder ------------------------------------------------------------------ */
.b-section {
    border: 1px solid var(--border); border-radius: 12px;
    padding: .9rem 1rem; margin-bottom: 1rem; background: var(--bg);
}
.b-section.dragging, .b-field.dragging { opacity: .5; }
.b-section-head { display: flex; align-items: flex-start; gap: .6rem; margin-bottom: .7rem; }
.b-section-meta { flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.b-section-title { font-weight: 700; font-size: 1rem; }
.b-section-desc { font-size: .85rem; }
.b-section-title, .b-section-desc, .b-field-label, .b-field-help,
.b-field-options, .b-num, .b-scale-label { margin-top: 0; }
.b-handle {
    cursor: grab; color: var(--muted); user-select: none;
    padding: .35rem .15rem; font-size: .9rem; letter-spacing: -2px; flex-shrink: 0;
}
.b-handle:active { cursor: grabbing; }
.b-fields { display: flex; flex-direction: column; gap: .5rem; }
.b-empty { text-align: center; padding: .6rem; border: 1px dashed var(--border); border-radius: 9px; }
.b-field {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: .55rem .7rem;
}
.b-field.drop-hint { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37, 99, 235, .18); }
.b-field-head { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.b-type-badge { flex-shrink: 0; }
.b-field-label { flex: 1; min-width: 180px; font-weight: 600; }
.b-req { margin: 0; white-space: nowrap; align-items: center; }
.b-field-detail { display: flex; flex-direction: column; gap: .4rem; margin-top: .45rem; padding-left: 1.6rem; }
.b-field-help { font-size: .82rem; }
.b-field-options { font-size: .85rem; }
.b-minmax { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.b-num { width: 90px; }
.b-scale-label { width: 150px; }
.b-actions { display: flex; align-items: center; gap: .1rem; margin-left: auto; }
.b-move { display: inline-flex; }
.b-move .icon-btn:disabled { opacity: .3; cursor: default; }
.b-add-field { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: .8rem; }
.b-type-btn {
    background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
    padding: .28rem .7rem; font-size: .78rem; cursor: pointer; color: var(--text);
}
.b-type-btn:hover { border-color: var(--primary); color: var(--primary); }
.b-add-crm { margin-top: .4rem; }
.b-crm-btn { background: #e2f6e9; border-color: #bce5cb; color: #157347; }
.b-crm-btn:hover { border-color: #157347; color: #106038; }
.b-crm-btn:disabled { opacity: .45; cursor: default; }
.b-crm-btn:disabled:hover { border-color: #bce5cb; color: #157347; }

/* ---- Anamnesis form (preview / client / admin edit) ------------------------------------ */
.anamnesis-section { padding: 1.5rem 1.75rem; }
.anamnesis-section h2 {
    font-size: 1.15rem; margin-bottom: .25rem;
    padding-bottom: .8rem; border-bottom: 1px solid var(--border);
}
.anamnesis-section > .muted.small { margin: .5rem 0 0; }
.anamnesis-section .af-field { margin: 1.5rem 0 0; }
.anamnesis-section .af-field:first-of-type { margin-top: 1.25rem; }
.af-field > label { margin-bottom: 0; }
.af-group { border: none; padding: 0; margin: 0; min-width: 0; }
.af-group legend { padding: 0; }
.af-label { display: block; font-size: .92rem; font-weight: 600; margin-bottom: .15rem; }
.af-help { display: block; font-weight: 400; margin-bottom: .35rem; line-height: 1.4; }
.req { color: var(--red); }

/* Text-like inputs: comfortable size, subtle focus ring */
.af-field input[type="text"],
.af-field input[type="number"],
.af-field input[type="date"],
.af-field textarea {
    margin-top: .4rem; padding: .65rem .85rem; border-radius: 10px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.af-field input[type="text"]:hover,
.af-field input[type="number"]:hover,
.af-field input[type="date"]:hover,
.af-field textarea:hover { border-color: #c7cfdd; }
.af-field input[type="text"]:focus,
.af-field input[type="number"]:focus,
.af-field input[type="date"]:focus,
.af-field textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}
.af-field input[type="number"],
.af-field input[type="date"] { max-width: 260px; }

/* Choice options as selectable cards */
.af-choices { display: flex; flex-direction: column; gap: .5rem; margin-top: .5rem; max-width: 560px; }
.af-type-yes_no .af-choices { flex-direction: row; flex-wrap: wrap; }
.af-type-yes_no .af-inline { min-width: 130px; }
.af-inline {
    display: flex; align-items: center; gap: .65rem; margin: 0;
    border: 1px solid var(--border); border-radius: 10px;
    padding: .65rem .85rem; cursor: pointer; background: var(--surface);
    font-weight: 500; font-size: .92rem;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.af-inline:hover { border-color: var(--primary); }
.af-inline input { margin: 0; width: 18px; height: 18px; flex-shrink: 0; cursor: pointer; }
.af-inline:has(input:checked) {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 6%, var(--surface));
    box-shadow: 0 0 0 1px var(--primary) inset;
}
.af-inline:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Scale: segmented buttons with end labels */
.af-scale {
    display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; margin-top: .5rem;
}
.af-scale > .muted.small { padding: 0 .35rem; white-space: nowrap; }
.af-scale-item { position: relative; margin: 0; cursor: pointer; }
.af-scale-item input {
    position: absolute; opacity: 0; inset: 0;
    width: 100%; height: 100%; margin: 0; cursor: pointer;
}
.af-scale-item span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 40px; height: 40px; padding: 0 .3rem;
    border: 1px solid var(--border); border-radius: 10px;
    font-size: .9rem; font-weight: 600; background: var(--surface);
    transition: border-color .15s ease, background .15s ease, transform .1s ease;
}
.af-scale-item:hover span { border-color: var(--primary); color: var(--primary); }
.af-scale-item input:checked + span {
    background: var(--primary); border-color: var(--primary); color: #fff;
    transform: scale(1.05);
}
.af-scale-item input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* File upload: friendly dashed drop area look */
.af-field .af-file-input {
    margin-top: .4rem; max-width: 560px;
    border: 1px dashed var(--border); border-radius: 10px;
    padding: .8rem .9rem; background: var(--bg);
    cursor: pointer; font-size: .88rem; color: var(--muted);
    transition: border-color .15s ease, background .15s ease;
}
.af-field .af-file-input:hover { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 4%, var(--bg)); }
.af-field .af-file-input::file-selector-button {
    background: var(--primary); color: #fff; border: none; border-radius: 8px;
    padding: .45rem .9rem; margin-right: .8rem; font-weight: 600; font-size: .85rem;
    cursor: pointer; font-family: inherit;
}
.af-file-current {
    margin: .4rem 0 .2rem; padding: .5rem .75rem; max-width: 560px;
    background: color-mix(in srgb, var(--green) 8%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--green) 30%, var(--border));
    border-radius: 10px;
}
.af-file-status { display: block; margin-top: .3rem; }

@media (max-width: 600px) {
    .anamnesis-section { padding: 1.1rem 1rem; }
    .af-scale-item span { min-width: 34px; height: 36px; }
    .af-type-yes_no .af-choices { flex-direction: column; }
    .af-type-yes_no .af-inline { min-width: 0; }
    .af-field input[type="number"], .af-field input[type="date"] { max-width: 100%; }
}

/* ---- Responsive ----------------------------------------------------------------------- */
@media (max-width: 1080px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-columns { grid-template-columns: 1fr; }
    .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
        transform: translateX(-100%); transition: transform .2s ease;
        height: 100vh;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.visible {
        display: block; position: fixed; inset: 0;
        background: rgba(16, 24, 40, .45); z-index: 90;
    }
    .icon-btn.sidebar-toggle { display: inline-flex; }
    .profile-name { display: none; }
    .content { padding: 1rem; }
    .client-row { grid-template-columns: auto 1fr; }
    .client-row-metric { display: none; }
    .client-row .client-row-adherence { display: flex; grid-column: 2; }
    .stat-grid { grid-template-columns: 1fr 1fr; gap: .7rem; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: span 1; }
    .detail-list { grid-template-columns: 1fr; gap: .05rem; }
    .detail-list dd { margin-bottom: .5rem; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .page-head { flex-direction: column; }
    .auth-card { padding: 1.4rem; }
}

/* ---- Module 7: plans + recipe/training library ------------------------------------ */
.btn-xs { padding: .15rem .45rem; font-size: .75rem; border-radius: 6px; }
.tabs-spacer { flex: 1; }

/* Library grid */
.library-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 1rem; margin-top: 1rem;
}
.library-card {
    border: 1px solid var(--border, #e5e7eb); border-radius: 12px; overflow: hidden;
    background: #fff; display: flex; flex-direction: column;
}
.library-card-img {
    width: 100%; height: 130px; object-fit: cover; display: block;
}
.library-card-placeholder {
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; background: #f3f4f6; color: #9ca3af;
}
.library-card-body { padding: .8rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.library-card-actions { display: flex; gap: .4rem; margin-top: auto; }
.library-header-preview img {
    max-width: 320px; max-height: 180px; border-radius: 10px;
    display: block; margin: .6rem 0; object-fit: cover;
}
.editor-label { display: block; font-weight: 600; font-size: .85rem; margin: 1rem 0 .35rem; }
.quill-editor { background: #fff; min-height: 160px; border-radius: 0 0 8px 8px; }
.ql-toolbar.ql-snow { border-radius: 8px 8px 0 0; }

/* Plan builder */
.builder-section {
    border: 1px solid var(--border, #e5e7eb); border-radius: 12px;
    padding: 1rem; margin-bottom: 1rem; background: #fafafa;
}
.builder-section-head { display: flex; gap: .6rem; align-items: center; margin-bottom: .8rem; }
.builder-section-title { flex: 1; font-weight: 600; }
.builder-controls { display: flex; gap: .3rem; }
.builder-elements { display: flex; flex-direction: column; gap: .7rem; }
.builder-element {
    border: 1px solid var(--border, #e5e7eb); border-radius: 10px;
    background: #fff; padding: .6rem .7rem;
}
.builder-element-head {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: .45rem;
}
.builder-element-type {
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em; color: #6b7280;
}
.builder-element-body input[type="text"], .builder-element-body textarea { width: 100%; }
.builder-palette { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .8rem; }
.builder-table { width: 100%; border-collapse: collapse; }
.builder-table td { padding: 2px; }
.builder-table input { width: 100%; font-size: .85rem; }
.builder-table input.builder-table-header { font-weight: 700; background: #f3f4f6; }
.builder-table-actions { display: flex; gap: .4rem; margin-top: .5rem; flex-wrap: wrap; }
.builder-image-preview {
    max-width: 260px; max-height: 160px; display: block;
    border-radius: 8px; margin-bottom: .5rem; object-fit: cover;
}
.builder-image-caption { margin-top: .4rem; }
.builder-item-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .5rem; }
.builder-item-chip {
    display: inline-flex; align-items: center; gap: .35rem;
    background: #eef2ff; color: #3730a3; border-radius: 999px;
    padding: .2rem .3rem .2rem .7rem; font-size: .82rem; font-weight: 600;
}
.builder-item-chip button {
    border: 0; background: transparent; cursor: pointer; font-size: 1rem;
    line-height: 1; color: inherit; padding: 0 .3rem;
}
.builder-item-picker { display: flex; gap: .4rem; align-items: center; }
.builder-item-picker select { flex: 1; }
.plan-status-actions {
    display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
    margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border, #e5e7eb);
}

/* Rendered plan (portal / print view) */
.plan-section { margin-bottom: 2rem; }
.plan-section-title {
    font-size: 1.25rem; margin: 0 0 .8rem; padding-bottom: .35rem;
    border-bottom: 2px solid var(--primary, #2563eb);
}
.plan-el-title { margin: 1rem 0 .4rem; }
.plan-el-text { margin: .4rem 0; }
.plan-el-content { margin: .5rem 0; }
.plan-el-image img { max-width: 100%; border-radius: 10px; }
.plan-el-image figcaption { margin-top: .3rem; }
.plan-el-image { margin: .8rem 0; }
.plan-library-item {
    border: 1px solid var(--border, #e5e7eb); border-radius: 12px;
    padding: 1rem; margin: .8rem 0; background: #fff;
}
.plan-library-header {
    width: 100%; max-height: 240px; object-fit: cover;
    border-radius: 8px; margin-bottom: .6rem; display: block;
}
.plan-library-name { margin: .2rem 0 .4rem; }
.plan-library-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .4rem; }
.rich-content p { margin: .35rem 0; }
.rich-content ul, .rich-content ol { margin: .4rem 0 .4rem 1.2rem; }
.rich-content blockquote {
    border-left: 3px solid var(--border, #e5e7eb); margin: .6rem 0; padding: .2rem .8rem; color: #4b5563;
}

/* ---- Module 8: invoices ------------------------------------------------------------ */
.card-head-row {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
    justify-content: space-between; margin-bottom: 12px;
}
.card-head-row h2 { margin: 0; }
.invoice-add-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.invoice-add-row select { min-width: 260px; max-width: 100%; }
.invoice-items-table .col-qty { width: 90px; }
.invoice-items-table .col-net { width: 130px; }
.invoice-items-table .col-num { width: 120px; text-align: right; white-space: nowrap; }
.invoice-items-table input[type="number"] { width: 100%; }
.invoice-items-table textarea { width: 100%; min-width: 220px; resize: vertical; }
.invoice-total-label { text-align: right; color: #4b5563; }
.invoice-total-label.strong, .col-num.strong { font-weight: 700; color: inherit; }
label.stacked { display: block; margin-bottom: 12px; }
label.stacked textarea { width: 100%; margin-top: 6px; }

/* ---- Module 9: contracts + signing ------------------------------------------------- */
.contract-preview { overflow-x: auto; }
.consent-check { margin-bottom: .6rem; }
.consent-check span { line-height: 1.45; }
.signature-block { margin-top: 18px; max-width: 560px; }
.signature-label { display: block; font-weight: 600; margin-bottom: 6px; }
.signature-canvas {
    display: block; width: 100%; height: 180px;
    background: #fff; border: 2px dashed #cbd5e1; border-radius: 10px;
    touch-action: none; cursor: crosshair;
}
.signature-canvas.has-ink { border-style: solid; border-color: var(--primary, #2563eb); }
.signature-canvas.sig-shake { animation: sig-shake .4s ease; border-color: #dc2626; }
@keyframes sig-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}
.signature-actions {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-top: 8px;
}
#sig-hint.sig-error { color: #dc2626; font-weight: 600; }

/* Responsive contract document: on small screens the info/consent table cells
   stack vertically (email clients ignore these classes and keep the inline
   styles; print is excluded so the paper layout stays identical). */
@media screen and (max-width: 640px) {
    .contract-doc .contract-info-table td,
    .contract-doc .contract-consents td {
        display: block;
        width: 100% !important;
        box-sizing: border-box;
    }
    .contract-doc .contract-info-table td + td,
    .contract-doc .contract-consents td + td { margin-top: -1px; }
    .contract-doc .contract-info-table td[style*="border:none"] { display: none; }
    .contract-doc img { max-width: 100%; height: auto; }
}

/* ---- Icon action buttons ------------------------------------------------------------ */
.library-card-title { color: var(--text); }
.library-card-title:hover { text-decoration: underline; }
svg.icon { width: 16px; height: 16px; flex-shrink: 0; display: inline-block; vertical-align: -2px; }
.btn-icon { padding: .34rem .5rem; }
.btn-icon .icon { display: block; }
.td-actions .btn-icon, .library-card-actions .btn-icon { vertical-align: middle; }

/* ---- Client overview dashboard ------------------------------------------------------ */
.overview-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem; margin-bottom: 1.25rem;
}
.overview-tile {
    display: block; border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface); padding: .9rem 1.1rem; color: var(--text);
}
.overview-tile:hover { text-decoration: none; border-color: var(--primary); }
.overview-tile-head {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
}
.overview-tile-value { font-size: 1.25rem; font-weight: 700; margin: .3rem 0 .15rem; }
.overview-tile-sub { font-size: .8rem; color: var(--muted); }

/* ---- Client portal home (hero + profile photo) --------------------------------------- */
.portal-hero { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.portal-hero-main { flex: 1; min-width: 220px; }
.portal-hero-main h2 { margin: 0 0 .15rem; }
.portal-hero-badges { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: .5rem 0 0; }
.portal-hero-side { display: flex; flex-direction: column; align-items: flex-end; gap: .6rem; }
.portal-hero-contract { display: flex; flex-direction: column; align-items: flex-end; gap: .1rem; text-align: right; }
.profile-photo-row { display: flex; align-items: flex-start; gap: 1.25rem; flex-wrap: wrap; }
.profile-photo-row form.inline-form { margin-top: .5rem; }
@media (max-width: 480px) {
    .portal-hero { flex-direction: column; align-items: flex-start; }
    .portal-hero-side, .portal-hero-contract { align-items: flex-start; text-align: left; }
}

/* ---- Progress & analysis (charts, metrics, entries) --------------------------------- */
.metric-charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 1rem; }
.metric-chart-card { border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem; background: var(--surface); }
.metric-chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.metric-chart-title { font-size: .85rem; font-weight: 600; }
.metric-chart-delta { font-size: .78rem; font-weight: 600; }
.metric-chart-delta.up { color: #157347; }
.metric-chart-delta.down { color: #b91c1c; }
.metric-chart-card canvas { width: 100% !important; height: 170px !important; }
.analytics-chart-card canvas { width: 100% !important; height: 260px !important; }

.progress-entry { border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1.1rem; margin-bottom: .9rem; }
.progress-entry-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .4rem; }
.progress-entry-head h3 { margin: 0; font-size: 1rem; }
.progress-entry .rich-content img { max-width: 100%; height: auto; border-radius: 8px; }
.progress-coach-comment {
    margin-top: .7rem; padding: .6rem .8rem; border-left: 3px solid var(--primary);
    background: var(--bg); border-radius: 0 8px 8px 0; font-size: .88rem;
}

/* ---- Risk status banner (Progress & Analysis tab) ----------------------------------- */
.badge-lg { font-size: .9rem; padding: .3rem .9rem; }
.risk-banner { border-left: 5px solid var(--border); }
.risk-banner.risk-bad { border-left-color: #dc2626; background: #fdf5f5; }
.risk-banner.risk-warn { border-left-color: #d97706; background: #fdf9f0; }
.risk-banner.risk-ok { border-left-color: #16a34a; background: #f4fbf6; }
.risk-banner.risk-good { border-left-color: #2563eb; background: #f3f7fe; }
.risk-banner-main {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap;
}
.risk-banner-status { display: flex; align-items: center; gap: .6rem; margin: .35rem 0; }
.risk-set-form { margin-bottom: 0; }
.risk-suggestion {
    margin-top: .9rem; padding: .8rem 1rem;
    border: 1px dashed var(--border); border-radius: 10px; background: var(--surface);
}
.risk-suggestion .form-actions { margin-top: .4rem; }

/* ---- Module 10: AI assistant ------------------------------------------------ */
.ai-analysis-content { margin: 12px 0; }
.ai-analysis-content h2, .ai-analysis-content h3, .ai-analysis-content h4 { margin: 14px 0 6px; }
.ai-sources-title { margin: 16px 0 4px; font-size: 0.95rem; }
.ai-sources { margin: 4px 0 0 18px; padding: 0; font-size: 0.85rem; }
.ai-sources li { margin: 2px 0; }
.ai-dash-stats { margin-top: 10px; }
.ai-generate-btn[disabled] { opacity: 0.7; cursor: wait; }
.text-orange { color: var(--warning, #d97706); }

/* Collapsible AI analysis list (portal, collapsed by default) */
.ai-icon-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 8px; flex: none;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: #fff; box-shadow: 0 1px 3px rgba(37, 99, 235, .35);
}
.ai-icon-badge .icon { width: 14px; height: 14px; vertical-align: 0; }
.ai-card-title { display: flex; align-items: center; gap: .55rem; }
.ai-accordion { display: flex; flex-direction: column; gap: .55rem; }
.ai-item {
    border: 1px solid #dbe7ff; border-radius: 10px;
    background: linear-gradient(180deg, #f8faff, #f4f8ff);
    overflow: hidden; transition: box-shadow .15s ease, border-color .15s ease;
}
.ai-item:hover { border-color: #b9d0fb; box-shadow: var(--shadow); }
.ai-item-summary {
    display: flex; align-items: center; gap: .7rem;
    padding: .7rem .9rem; cursor: pointer; list-style: none; user-select: none;
}
.ai-item-summary::-webkit-details-marker { display: none; }
.ai-item-summary::after {
    content: ''; flex: none; width: 8px; height: 8px; margin-left: .1rem;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
    transform: rotate(45deg) translateY(-2px); transition: transform .18s ease;
}
.ai-item[open] > .ai-item-summary::after { transform: rotate(225deg) translateY(-2px); }
.ai-item-title { font-weight: 600; font-size: .9rem; flex: 1; min-width: 0; }
.ai-item-date { flex: none; white-space: nowrap; }
.ai-item[open] > .ai-item-summary { border-bottom: 1px solid #dbe7ff; background: #eef4ff; }
.ai-item-body { padding: .3rem .9rem .8rem; background: var(--surface); }
.ai-item-footer {
    display: flex; align-items: center; gap: .4rem; margin-top: .6rem;
    padding-top: .55rem; border-top: 1px dashed #dbe7ff;
}
.ai-item-footer .icon { width: 13px; height: 13px; color: var(--primary); }
@media (max-width: 480px) {
    .ai-item-date { display: none; }
}

/* Finance dashboard on the admin invoices page */
.fin-charts { margin-bottom: 1.25rem; }
.fin-chart-wrap { position: relative; height: 220px; }
.fin-horizon-row {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
    margin-bottom: .8rem;
}
.fin-horizon {
    display: flex; flex-direction: column; gap: .1rem;
    border: 1px solid var(--border); border-radius: 9px;
    padding: .45rem .6rem; background: var(--bg);
}
.fin-horizon strong { font-size: .92rem; white-space: nowrap; }
@media (max-width: 480px) {
    .fin-horizon-row { grid-template-columns: repeat(2, 1fr); }
}

/* Legal documents management (settings > privacy) */
.legal-doc-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap; padding: .7rem 0;
    border-bottom: 1px solid var(--border);
}
.legal-doc-row:last-child { border-bottom: 0; }
.legal-doc-info { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.legal-doc-form { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.legal-doc-form input[type="file"] { font-size: .8rem; max-width: 240px; }
