/* CliniMemo — PWA styles */
:root {
	/* CliniMemo palette (provvisoria) — blu clinico + accento teal */
	--bg: #f4f7fb;
	--surface: #ffffff;
	--surface-2: #eef3fa;
	--border: #dde5f0;
	--text: #16202e;
	--text-soft: #5c6b80;
	--navy: #123f6b;
	--primary: #1a73b7;
	--primary-dark: #12578e;
	--primary-soft: #e4f0f8;
	--accent: #22b3a1;
	--accent-soft: #dcf4f0;
	--danger: #e5484d;
	--danger-soft: #fdeaea;
	--ok: #2a9d5c;
	--warn: #d98a1a;
	--shadow: 0 1px 3px rgba(20,35,60,.08), 0 8px 24px rgba(20,35,60,.06);
	--radius: 14px;
	--radius-sm: 10px;
	--maxw: 640px;
	--safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0e141d;
		--surface: #172230;
		--surface-2: #1e2b3b;
		--border: #2a3b4f;
		--text: #eaf1fb;
		--text-soft: #9db0c8;
		--navy: #9fc4e8;
		--primary: #3f95d6;
		--primary-dark: #2f7cb8;
		--primary-soft: #16324b;
		--accent: #2cc3b0;
		--accent-soft: #113a37;
		--danger: #ff6b6f;
		--danger-soft: #38222a;
		--shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
	}
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	background: var(--bg);
	color: var(--text);
	-webkit-font-smoothing: antialiased;
	line-height: 1.45;
}
#md-app { min-height: 100vh; }

/* Splash */
.md-splash { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.md-splash__logo { width: 76px; height: 76px; }
.md-spinner { width: 30px; height: 30px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.md-screen { max-width: var(--maxw); margin: 0 auto; padding: 0 16px 96px; }
.md-topbar {
	position: sticky; top: 0; z-index: 20;
	background: color-mix(in srgb, var(--bg) 85%, transparent);
	backdrop-filter: saturate(1.4) blur(8px);
	border-bottom: 1px solid var(--border);
}
.md-topbar__inner { max-width: var(--maxw); margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.md-topbar__title { font-weight: 700; font-size: 17px; flex: 1; }
.md-back { background: none; border: none; color: var(--primary); font-size: 16px; padding: 6px 4px; cursor: pointer; }

/* Patient switcher */
.md-switcher { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: none; padding: 4px 0; cursor: pointer; color: var(--text); }
.md-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.md-switcher__meta { text-align: left; line-height: 1.15; overflow: hidden; }
.md-switcher__name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.md-switcher__sub { font-size: 12px; color: var(--text-soft); }
.md-switcher__chev { margin-left: auto; color: var(--text-soft); }

/* Cards */
.md-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.md-card--tap { cursor: pointer; transition: transform .08s ease; }
.md-card--tap:active { transform: scale(.99); }
.md-card__head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.md-card__icon { font-size: 26px; }
.md-card__title { font-weight: 700; font-size: 16px; }
.md-card__sub { color: var(--text-soft); font-size: 13px; }

.md-section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); margin: 22px 4px 10px; font-weight: 700; }

/* Buttons */
.md-btn { -webkit-appearance: none; appearance: none; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 13px 16px; font-size: 15px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.md-btn--primary { background: var(--primary); color: #fff; }
.md-btn--primary:active { background: var(--primary-dark); }
.md-btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.md-btn--soft { background: var(--primary-soft); color: var(--primary); }
.md-btn--danger { background: var(--danger-soft); color: var(--danger); }
.md-btn--sm { width: auto; padding: 8px 12px; font-size: 13px; }
.md-btn:disabled { opacity: .55; cursor: default; }
.md-btn-row { display: flex; gap: 10px; }
.md-btn-row .md-btn { width: auto; flex: 1; }

/* Forms */
.md-field { margin-bottom: 14px; }
.md-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
.md-input, .md-select, .md-textarea {
	width: 100%; padding: 12px 14px; font-size: 16px; color: var(--text);
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
	font-family: inherit;
}
.md-input:focus, .md-select:focus, .md-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.md-textarea { min-height: 72px; resize: vertical; }
.md-hint { font-size: 12px; color: var(--text-soft); margin-top: 5px; }
.md-inline { display: flex; gap: 10px; }
.md-inline > * { flex: 1; }

/* Field: number with unit */
.md-unitwrap { position: relative; }
.md-unit { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-soft); font-size: 13px; pointer-events: none; }

/* Toggle (bool) */
.md-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.md-toggle__label { font-size: 15px; }
.md-switch { position: relative; width: 48px; height: 28px; flex: none; }
.md-switch input { opacity: 0; width: 0; height: 0; }
.md-switch span { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; transition: .2s; }
.md-switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.md-switch input:checked + span { background: var(--primary); border-color: var(--primary); }
.md-switch input:checked + span::before { transform: translateX(20px); }

/* Scale */
.md-scale { display: flex; align-items: center; gap: 12px; }
.md-scale input[type=range] { flex: 1; accent-color: var(--primary); }
.md-scale__val { min-width: 44px; text-align: center; font-weight: 700; font-size: 18px; color: var(--primary); }

/* Chips (condition select) */
.md-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.md-chip { padding: 9px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 14px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.md-chip--on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }

/* Moment selector */
.md-moments { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.md-moment { text-align: left; padding: 11px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.md-moment--on { border-color: var(--primary); background: var(--primary-soft); }
.md-moment__label { font-weight: 600; font-size: 14px; }
.md-moment__hint { font-size: 11px; color: var(--text-soft); }

/* Entry rows (history) */
.md-entry { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.md-entry:last-child { border-bottom: none; }
.md-entry__date { font-size: 12px; color: var(--text-soft); min-width: 58px; text-align: center; }
.md-entry__date .md-entry__ico { font-size: 16px; display: block; }
.md-entry__main { flex: 1; min-width: 0; cursor: pointer; }
.md-stats { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.md-stat { display: flex; flex-direction: column; line-height: 1.1; }
.md-stat b { font-size: 16px; font-variant-numeric: tabular-nums; }
.md-stat span { font-size: 11px; color: var(--text-soft); }
.md-entry__meta { font-size: 12px; color: var(--text-soft); margin-top: 5px; }
.md-entry__edit { color: var(--primary); font-size: 18px; flex: none; padding: 6px; }
.md-entry__del { background: none; border: none; color: var(--danger); font-size: 18px; cursor: pointer; padding: 6px; flex: none; }

/* Bottom sheet / modal */
.md-sheet-backdrop { position: fixed; inset: 0; background: rgba(10,18,30,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.md-sheet { background: var(--surface); width: 100%; max-width: var(--maxw); border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); max-height: 88vh; overflow-y: auto; animation: sheetUp .22s ease; }
@keyframes sheetUp { from { transform: translateY(20px); opacity: .6; } }
.md-sheet__grip { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 8px auto 14px; }
.md-sheet__title { font-weight: 700; font-size: 18px; margin: 0 0 14px; }

/* Auth */
.md-auth { max-width: 420px; margin: 0 auto; padding: 40px 20px calc(40px + var(--safe-b)); min-height: 100vh; display: flex; flex-direction: column; justify-content: center; }
.md-auth__logo { text-align: center; margin-bottom: 10px; }
.md-auth__logo img { width: 76px; height: 76px; }
.md-auth__brand { text-align: center; font-weight: 800; font-size: 26px; margin-bottom: 2px; letter-spacing: -.01em; }
.md-auth__brand .clini { color: var(--navy); }
.md-auth__brand .memo { color: var(--accent); }
.md-auth__tag { text-align: center; color: var(--text-soft); margin-bottom: 26px; }
.md-auth__switch { text-align: center; margin-top: 18px; color: var(--text-soft); font-size: 14px; }
.md-auth__switch button { background: none; border: none; color: var(--primary); font-weight: 600; cursor: pointer; font-size: 14px; }

/* Steps / wizard */
.md-steps { display: flex; gap: 6px; margin: 8px 0 20px; }
.md-steps__dot { flex: 1; height: 4px; border-radius: 2px; background: var(--border); }
.md-steps__dot--on { background: var(--primary); }

/* Misc */
.md-toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: 90%; }
.md-toast--err { background: var(--danger); color: #fff; }
.md-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; }
.md-empty { text-align: center; color: var(--text-soft); padding: 40px 16px; }
.md-empty__icon { font-size: 44px; margin-bottom: 8px; }
.md-fab { position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); }
.md-list-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.md-list-row:last-child { border-bottom: none; }
.md-list-row__main { flex: 1; }
.md-list-row__name { font-weight: 600; }
.md-list-row__sub { font-size: 12px; color: var(--text-soft); }
.md-spacer { height: 8px; }
.md-center { text-align: center; }
.md-muted { color: var(--text-soft); font-size: 13px; }
.md-tag { display: inline-block; background: var(--surface-2); border-radius: 6px; padding: 2px 7px; font-size: 12px; margin: 2px 4px 2px 0; color: var(--text-soft); }

/* Statistiche */
.md-statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; margin-bottom: 14px; }
.md-stattile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.md-stattile__v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.md-stattile__v small { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.md-stattile__l { font-size: 12px; color: var(--text-soft); margin-top: 3px; }
.md-stattile__x { font-size: 11px; color: var(--text-soft); margin-top: 4px; }
.md-chartcard { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.md-chartcard__title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.md-chart { width: 100%; height: auto; display: block; }
.md-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--text-soft); }
.md-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.md-badge { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 14px; font-weight: 700; }

/* Install banner (PWA) */
.md-install { position: fixed; left: 12px; right: 12px; bottom: calc(14px + var(--safe-b)); max-width: 560px; margin: 0 auto; z-index: 90;
	background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; animation: sheetUp .25s ease; }
.md-install__row { display: flex; align-items: center; gap: 12px; }
.md-install__icon { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.md-install__txt { flex: 1; min-width: 0; }
.md-install__title { font-weight: 700; font-size: 15px; }
.md-install__sub { font-size: 12px; color: var(--text-soft); }
.md-install__close { background: none; border: none; color: var(--text-soft); font-size: 20px; cursor: pointer; padding: 4px; flex: none; }
.md-install__actions { display: flex; gap: 8px; margin-top: 12px; }
.md-install__actions .md-btn { width: auto; flex: 1; }
.md-install__ios { margin-top: 10px; font-size: 13px; color: var(--text); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; line-height: 1.5; }
.md-ios-share { display: inline-block; width: 18px; height: 18px; vertical-align: -4px; }
