html, body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

/* iPhone: niente zoom automatico sui campi (serve font-size >= 16px) */
input, select, textarea { font-size: 16px !important; }
/* Webapp: niente zoom con doppio tocco, testo che non si ingrandisce ruotando il telefono */
html, body { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* iPhone a schermo intero: spazio per notch e barra in basso */
.mud-appbar { padding-top: env(safe-area-inset-top); }
.mud-main-content { margin-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.mud-drawer-content { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.mud-snackbar-location-bottom-center, .mud-snackbar-location-bottom-right { margin-bottom: env(safe-area-inset-bottom); }

.fh-muted { opacity: .7; }
.fh-small { font-size: .85rem; }

/* ---------- Pagine di accesso (rendering statico): nero e arancione ---------- */
.fh-auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 30% 20%, #2a1600 0%, #000 60%);
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}

.fh-auth-card, .fh-auth-page > article {
    background: #121212;
    color: #f2f2f2;
    border: 1px solid #262626;
    border-radius: 18px;
    padding: 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0,0,0,.6);
}

.fh-auth-card h1 { margin: 0 0 4px; font-size: 1.8rem; }
.fh-auth-logo { width: 72px; height: 72px; margin-bottom: 10px; }
.fh-auth-logo img { width: 100%; height: 100%; border-radius: 16px; }

.fh-field { display: flex; flex-direction: column; margin: 14px 0; }
.fh-field label { font-size: .9rem; margin-bottom: 4px; font-weight: 500; }
.fh-field input, .form-control {
    padding: 13px 14px;
    background: #0a0a0a;
    color: #f2f2f2;
    border: 1px solid #3a3a3a;
    border-radius: 12px;
    width: 100%;
    box-sizing: border-box;
}
.fh-field input:focus, .form-control:focus { outline: 2px solid #FF8A00; border-color: transparent; }

.fh-check { display: flex; align-items: center; gap: 8px; margin: 10px 0 18px; }
.fh-check input { accent-color: #FF8A00; width: 20px; height: 20px; }

.fh-button, .btn {
    display: inline-block;
    width: 100%;
    background: #FF8A00;
    color: #000;
    border: none;
    border-radius: 12px;
    padding: 15px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    margin-top: 6px;
}
.fh-button:hover, .btn:hover { filter: brightness(1.08); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-link { background: transparent; color: #FF8A00; }
.fh-alert, .alert {
    background: #fdecea;
    color: #8a1c1c;
    border-radius: 10px;
    padding: 10px 14px;
    margin: 12px 0;
}
.alert-success { background: #e8f5e9; color: #1b5e20; }
.alert-warning { background: #fff8e1; color: #7a4f01; }

.fh-error, .text-danger, .validation-message { color: #d32f2f; font-size: .85rem; }
.form-floating { display: flex; flex-direction: column-reverse; margin: 12px 0; }
.form-floating > label { font-size: .9rem; margin-bottom: 4px; font-weight: 500; }
.mb-3 { margin-bottom: 1rem; }

/* ---------- Pannello touch (pagina Casa) ---------- */
.fh-tile {
    min-height: 120px;
    cursor: pointer;
    user-select: none;
    transition: transform .08s ease, box-shadow .15s ease;
    -webkit-tap-highlight-color: transparent;
}
.fh-tile:active { transform: scale(.97); }
.fh-tile.fh-on { background: linear-gradient(135deg, #fff7d6, #ffe08a) !important; color: #3d2c00; }
.fh-tile.fh-alert-on { background: linear-gradient(135deg, #ffe0e0, #ffb3b3) !important; color: #5c0000; }
.fh-tile.fh-unavailable { opacity: .45; }
.fh-tile-value { font-size: 1.6rem; font-weight: 600; }

/* ---------- Assistente ---------- */
.fh-chat { display: flex; flex-direction: column; gap: 10px; }
.fh-msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.fh-msg-user { align-self: flex-end; background: #FF8A00; color: #000; border-bottom-right-radius: 4px; }
.fh-msg-assistant { align-self: flex-start; background: var(--mud-palette-background-gray, #eceff3); border-bottom-left-radius: 4px; }
.fh-msg-tool { align-self: flex-start; font-size: .8rem; opacity: .75; }

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 2000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* ---------- Flusso di energia ---------- */
.fh-flow { width: 100%; max-width: 460px; margin: 0 auto; }
.fh-flow svg { width: 100%; height: auto; overflow: visible; }
.fh-flow-line { fill: none; stroke-width: 2; opacity: .18; }
.fh-flow-line.on { opacity: .55; stroke-width: 3; }
.fh-phase-bar { display: flex; height: 34px; border-radius: 8px; overflow: hidden; }
.fh-phase-bar > div { display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: .85rem; min-width: 2px; transition: width .6s ease; }

/* ---------- Modello "Inverter" ---------- */
.fh-inv { position: relative; display: grid; grid-template-columns: 1fr 1.1fr 1fr; grid-template-rows: auto auto; gap: 18px 24px; align-items: center; min-height: 340px; }
.fh-inv-wires { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.fh-wire { fill: none; stroke: var(--mud-palette-lines-default); stroke-width: .8; }
.fh-wire.on { stroke: #f59e0b; stroke-dasharray: 2 2; animation: fh-dash 1s linear infinite; }
@keyframes fh-dash { to { stroke-dashoffset: -8; } }
.fh-inv-box, .fh-inv-core { position: relative; z-index: 1; background: var(--mud-palette-surface); border: 2px solid var(--mud-palette-lines-default); border-radius: 14px; padding: 12px 14px; }
.fh-inv-box.on { border-color: var(--c, #1f6feb); }
.fh-inv-pv { grid-column: 1; grid-row: 1; --c: #f59e0b; }
.fh-inv-grid { grid-column: 3; grid-row: 1; --c: #64748b; }
.fh-inv-bat { grid-column: 1; grid-row: 2; --c: #16a34a; }
.fh-inv-load { grid-column: 3; grid-row: 2; --c: #1f6feb; }
.fh-inv-core { grid-column: 2; grid-row: 1 / span 2; text-align: center; border-color: #1f6feb; border-width: 3px; min-height: 160px; display: flex; flex-direction: column; justify-content: center; }
.fh-inv-title { font-size: .8rem; opacity: .7; text-transform: uppercase; letter-spacing: .04em; }
.fh-inv-value { font-size: 1.6rem; font-weight: 700; }
.fh-inv-state { font-size: 1.3rem; font-weight: 700; color: #1f6feb; margin: 4px 0; }
.fh-inv-sub { font-size: .85rem; opacity: .85; }
@media (max-width: 700px) {
  .fh-inv { grid-template-columns: 1fr 1fr; }
  .fh-inv-core { grid-column: 1 / span 2; grid-row: 3; min-height: auto; }
  .fh-inv-pv { grid-column: 1; grid-row: 1; } .fh-inv-grid { grid-column: 2; grid-row: 1; }
  .fh-inv-bat { grid-column: 1; grid-row: 2; } .fh-inv-load { grid-column: 2; grid-row: 2; }
  .fh-inv-wires { display: none; }
}

/* ---------- Modello "Tablet a muro" ---------- */
.fh-wall { background: #0d1117; color: #e6edf3; border-radius: 18px; padding: 24px; }
.fh-wall-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.fh-wall-clock { font-size: 3.6rem; font-weight: 300; line-height: 1; }
.fh-wall-date { opacity: .7; font-size: 1.1rem; }
.fh-wall-weather { font-size: 2.6rem; display: flex; gap: 12px; align-items: center; }
.fh-wall-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.fh-wall-tile { background: #161b22; border-left: 8px solid var(--c); border-radius: 14px; padding: 18px 20px; }
.fh-wall-label { font-size: 1.05rem; opacity: .75; }
.fh-wall-value { font-size: 3.2rem; font-weight: 700; color: var(--c); line-height: 1.15; }
.fh-wall-sub { opacity: .7; }
.fh-wall-bar { height: 10px; background: #30363d; border-radius: 6px; overflow: hidden; margin: 6px 0; }
.fh-wall-bar > div { height: 100%; background: var(--c); transition: width .6s ease; }
.fh-wall-foot { margin-top: 18px; font-size: 1.2rem; opacity: .85; text-align: center; }
@media (max-width: 600px) { .fh-wall-grid { grid-template-columns: 1fr; } .fh-wall-value { font-size: 2.4rem; } }

.fh-button-secondary { background: transparent; color: #FF8A00; border: 2px solid #FF8A00; margin-top: 10px; }
.fh-passkey-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--mud-palette-lines-default, #2a2a2a); }
/* ---------- Ambrogio e Assunta (assistente con volto) ---------- */
.fh-avatar { display: flex; gap: 16px; align-items: stretch; border: 1px solid rgba(255,138,0,.35); }
.fh-avatar-stage { position: relative; flex: 0 0 240px; height: 300px; border-radius: 16px; overflow: hidden; cursor: pointer;
  background: radial-gradient(circle at 50% 35%, #2b2b2b 0%, #111 70%); box-shadow: inset 0 0 0 2px rgba(255,138,0,.25); }
.fh-avatar-video { width: 100%; height: 100%; object-fit: cover; display: none; }
.fh-avatar-stage.on .fh-avatar-video { display: block; }
.fh-avatar-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.fh-avatar-placeholder span { width: 120px; height: 120px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 56px; font-weight: 700; color: #000; background: linear-gradient(135deg, #FFB347, #FF8A00); box-shadow: 0 0 40px rgba(255,138,0,.35); }
.fh-avatar-placeholder.f span { background: linear-gradient(135deg, #FFC48C, #FF7A59); }
.fh-avatar-badge { position: absolute; left: 10px; bottom: 10px; padding: 2px 10px; border-radius: 999px; font-size: .75rem;
  background: rgba(0,0,0,.6); color: #fff; backdrop-filter: blur(4px); }
.fh-avatar-badge.speaking { background: #FF8A00; color: #000; }
.fh-avatar-side { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.fh-avatar-talk { flex: 1 1 auto; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.fh-mic { width: 56px; height: 56px; }
@media (max-width: 700px) {
  .fh-avatar { flex-direction: column; }
  .fh-avatar-stage { flex: none; width: 100%; height: 56vw; max-height: 340px; }
}
/* ---------- Spesa e scadenze ---------- */
.fh-shop-row { border-bottom: 1px solid rgba(128,128,128,.15); min-height: 52px; }
.fh-shop-row:last-child { border-bottom: none; }
.fh-due { width: 48px; text-align: center; border-radius: 10px; padding: 4px 0; background: rgba(128,128,128,.15); flex: none; }
.fh-due .d { font-size: 1.3rem; font-weight: 700; line-height: 1.1; }
.fh-due .m { font-size: .7rem; text-transform: uppercase; }
.fh-due.soon { background: rgba(255,138,0,.25); }
.fh-due.late { background: rgba(244,67,54,.3); }
/* ---------- Le mie notifiche ---------- */
.fh-inbox { display: flex; align-items: flex-start; gap: 10px; }
.fh-inbox.unread { border-left: 4px solid #FF8A00; }
.fh-inbox-img { width: 112px; height: 72px; object-fit: cover; border-radius: 8px; cursor: zoom-in; flex: none; }
.fh-inbox-img.none { display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(128,128,128,.15); cursor: default; opacity: .7; }
@media (max-width: 600px) { .fh-inbox-img { width: 84px; height: 60px; } }
/* ---------- Player telecamere (stile Google Home) ---------- */
.fh-player { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 16 / 9; width: 100%; max-height: 75vh; }
.fh-player-media { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.fh-player-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; text-align: center; padding: 16px; background: radial-gradient(circle, rgba(30,30,30,.6), rgba(0,0,0,.85)); font-size: .9rem; }
.fh-player-live { position: absolute; left: 12px; top: 10px; font-size: .72rem; font-weight: 700; letter-spacing: .08em; color: #fff;
  background: rgba(0,0,0,.45); padding: 2px 8px; border-radius: 999px; display: flex; align-items: center; gap: 6px; }
.fh-player-live span { width: 8px; height: 8px; border-radius: 50%; background: #ff3b30; animation: fh-pulse 1.4s infinite; }
.fh-player-bar { position: absolute; right: 8px; bottom: 6px; display: flex; gap: 2px; background: rgba(0,0,0,.4); border-radius: 999px; }
.fh-player:fullscreen { border-radius: 0; max-height: none; aspect-ratio: auto; }
@keyframes fh-pulse { 0%, 100% { opacity: 1 } 50% { opacity: .3 } }