:root {
    --bg: #eef1f6;
    --surface: #ffffff;
    --ink: #0f172a;
    --muted: #5b6b82;
    --line: #d7dee8;
    --header: #0f172a;
    --header-ink: #f8fafc;
    --run: #15803d;
    --run-bg: #dcfce7;
    --stop: #1d4ed8;
    --stop-bg: #dbeafe;
    --error: #dc2626;
    --error-bg: #fee2e2;
    --man: #bf8040;
    --man-bg: #f4e6d7;
    --off: #64748b;
    --off-bg: #e2e8f0;
    --offline: #475569;
    --accent: #0f766e;
    --radius: 16px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100dvh;
}
button, input { font: inherit; }
a { color: inherit; }

.hidden { display: none !important; }

.app-footer {
    margin: 24px 12px 0;
    padding: 16px 8px calc(18px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    text-align: center;
    color: var(--muted);
}
.footer-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px 16px;
    margin-bottom: 8px;
}
.app-footer strong {
    color: var(--ink);
}
.app-footer .btn-ghost {
    background: #e2e8f0;
    color: var(--ink);
    min-height: 40px;
}
.app-footer .copy {
    margin: 0;
    font-size: 12px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--header);
    color: var(--header-ink);
    padding: calc(10px + var(--safe-top)) 16px 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
}

.btn-ghost, .btn-primary, .seg-btn {
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    min-height: 44px;
    padding: 0 14px;
    touch-action: manipulation;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    color: #fff;
    text-decoration: none;
    font-weight: 600;
}

.status-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 0;
    font-size: 13px;
    color: #cbd5e1;
}

.clock { margin-left: auto; font-variant-numeric: tabular-nums; }

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    flex-shrink: 0;
}
.live-dot.ok { background: #34d399; box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18); }
.live-dot.err { background: #f87171; }
.live-dot.wait { background: #fbbf24; }

.summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 12px;
}

.sum-btn {
    appearance: none;
    border: 0;
    border-radius: 12px;
    min-height: 52px;
    padding: 6px 4px;
    background: rgba(255,255,255,0.08);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    touch-action: manipulation;
}
.sum-btn strong { font-size: 16px; line-height: 1; }
.sum-btn span { font-size: 10px; letter-spacing: 0.02em; text-transform: uppercase; opacity: 0.8; }
.sum-btn[aria-pressed="true"] {
    background: #fff;
    color: var(--ink);
}

.toolbar {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

#search {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    border: 0;
    border-radius: 12px;
    padding: 0 14px;
    font-size: 16px;
    background: #fff;
    color: var(--ink);
}

.seg {
    display: flex;
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 3px;
    flex-shrink: 0;
}
.seg-btn {
    min-width: 64px;
    min-height: 38px;
    background: transparent;
    color: #cbd5e1;
    font-weight: 600;
    font-size: 13px;
}
.seg-btn[aria-pressed="true"] {
    background: #fff;
    color: var(--ink);
}

main { padding: 12px 12px 0; }

.banner {
    margin: 0 0 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fef3c7;
    color: #92400e;
    font-size: 14px;
}

.cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.tile {
    --status: var(--line);
    --ink-status: #fff;
    background: #fff;
    color: var(--ink);
    border-radius: 14px;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    text-align: left;
    width: 100%;
    margin: 0;
    font: inherit;
    appearance: none;
}

.tile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    min-height: 38px;
    background: var(--status);
    color: var(--ink-status);
}

.tile-head .num {
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
    flex-shrink: 0;
}

.tile-head .head-st {
    font-size: 11px;
    font-weight: 800;
    text-align: right;
    text-transform: uppercase;
    line-height: 1.2;
    max-width: 68%;
}

.tile-body {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kv {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.kv small {
    display: block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
}

.kv b {
    display: block;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.25;
    word-break: break-word;
}

.adv .bar {
    margin: 4px 0 3px;
}

.bar {
    height: 7px;
    background: #e5e7eb;
    border-radius: 99px;
    overflow: hidden;
}
.bar > i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: var(--status, var(--accent));
}

.tile.run { --status: var(--run); --ink-status: #fff; }
.tile.stop { --status: var(--stop); --ink-status: #fff; }
.tile.error { --status: var(--error); --ink-status: #fff; }
.tile.man { --status: var(--man); --ink-status: #fff; }
.tile.off { --status: lavender; --ink-status: #111; }
.tile.offline { --status: var(--offline); --ink-status: #fff; }

.tile.error {
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.18), var(--shadow);
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

.floor-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
}

.floor {
    min-width: 760px;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
}

.cell-empty {
    min-height: 118px;
    background: transparent;
    border: 0;
    box-shadow: none;
    pointer-events: none;
}

.floor-stats {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 8px;
    min-height: 0;
    text-align: left;
}
.floor-stats.on-floor {
    grid-column: span 3;
    grid-row: span 2;
}
.floor-stats.on-list {
    grid-column: 1 / -1;
}
.fs-title {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}
.fs-nums {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}
.fs-n {
    appearance: none;
    border: 0;
    border-radius: 12px;
    padding: 10px 4px 8px;
    text-align: center;
    cursor: pointer;
    font: inherit;
    touch-action: manipulation;
}
.fs-n b {
    display: block;
    font-size: 26px;
    line-height: 1;
    font-weight: 800;
}
.fs-n span {
    display: block;
    margin-top: 4px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.85;
}
.fs-n.run { background: var(--run-bg); color: var(--run); }
.fs-n.stop { background: var(--stop-bg); color: var(--stop); }
.fs-n.error { background: var(--error-bg); color: var(--error); }
.fs-next {
    background: #f8fafc;
    border-radius: 12px;
    padding: 8px 10px 10px;
}
.fs-next small {
    display: block;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}
.fs-next-btn {
    appearance: none;
    display: block;
    width: 100%;
    margin: 0;
    padding: 4px 0 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    touch-action: manipulation;
}
.fs-next-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}
.fs-next-row strong {
    font-size: 18px;
    font-weight: 800;
}
.fs-next-row b {
    font-size: 20px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    white-space: nowrap;
}
.fs-eta, .fs-muted {
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
}

.tile.is-filtered {
    opacity: 0.28;
    pointer-events: none;
}

.cards .tile-head .num { font-size: 26px; }
.cards .tile-head .head-st { font-size: 13px; }
.cards .kv small { font-size: 11px; }
.cards .kv b { font-size: 15px; }

.sheet {
    position: fixed;
    inset: 0;
    z-index: 40;
}
.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}
.sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 88dvh;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 8px 16px calc(18px + var(--safe-bottom));
    overflow: auto;
}
.sheet-handle {
    width: 44px;
    height: 4px;
    border-radius: 99px;
    background: #cbd5e1;
    margin: 6px auto 10px;
}
.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.sheet-head .btn-ghost {
    background: var(--bg);
    color: var(--ink);
}
.sheet-body {
    font-size: 15px;
    line-height: 1.45;
    color: var(--ink);
}
.sheet-model {
    margin: 0 0 12px;
    font-weight: 700;
    color: var(--muted);
}
.sheet-link {
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    margin-top: 8px;
}
.lfa-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    margin: 4px 0 8px;
}
.lfa-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 14px;
}
.lfa-grid span {
    background: var(--bg);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.sheet-body img { max-width: 100%; height: auto; }
.sheet-body table { width: 100%; border-collapse: collapse; }
.sheet-body td, .sheet-body th {
    padding: 6px 4px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}
.stat {
    background: var(--bg);
    border-radius: 12px;
    padding: 10px 12px;
}
.stat b { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.stat span { font-size: 18px; font-weight: 700; }

.legacy-html .progress {
    height: 10px;
    background: #e5e7eb;
    border-radius: 99px;
    overflow: hidden;
    margin: 8px 0;
    position: relative;
    width: 100%;
}
.legacy-html .progress-bar {
    height: 100%;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.legacy-html .progress-bar-success { background: var(--run); }
.legacy-html .progress-bar-inizio { background: #60a5fa; }
.legacy-html .dati, .legacy-html .giri { margin: 6px 0; }
.legacy-html h1 { font-size: 14px; margin: 0; }

.login-body {
    min-height: 100dvh;
    display: flex;
    align-items: stretch;
    background:
        radial-gradient(1200px 500px at 10% -10%, #134e4a 0%, transparent 55%),
        linear-gradient(180deg, #0f172a 0%, #111827 100%);
    padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}
.login-card {
    margin: auto;
    width: min(420px, 100%);
    background: #fff;
    border-radius: 24px;
    padding: 28px 22px 24px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.28);
}
.login-mark {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: #0f766e;
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 26px;
    font-weight: 800;
}
.login-kicker {
    margin: 16px 0 0;
    color: #0f766e;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}
.login-card h1 { margin: 4px 0 8px; font-size: 1.8rem; }
.login-lead { margin: 0 0 18px; color: var(--muted); line-height: 1.45; }
.login-card label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    margin: 12px 0 6px;
}
.login-card input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0 14px;
    font-size: 16px;
    background: #f8fafc;
}
.login-card input:focus {
    outline: 2px solid #0f766e;
    outline-offset: 1px;
    background: #fff;
}
.btn-primary {
    width: 100%;
    margin-top: 18px;
    background: #0f766e;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
}
.alert {
    background: var(--error-bg);
    color: #991b1b;
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 8px;
}

@media (min-width: 560px) {
    .cards { grid-template-columns: 1fr 1fr; }
    .app-header { padding-left: 20px; padding-right: 20px; }
    main, .app-footer { padding-left: 20px; padding-right: 20px; }
    .app-footer { margin-left: 0; margin-right: 0; }
    .summary { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .lfa-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
    .cards { grid-template-columns: 1fr 1fr 1fr; }
    .floor { min-width: 0; }
    .sheet-panel {
        left: 50%;
        right: auto;
        top: 50%;
        bottom: auto;
        transform: translate(-50%, -50%);
        width: min(560px, calc(100vw - 32px));
        max-height: 80vh;
        border-radius: 20px;
        padding-bottom: 18px;
    }
    .sheet-handle { display: none; }
}

@media (min-width: 1200px) {
    .cards { grid-template-columns: repeat(4, 1fr); }
}

@media (orientation: landscape) and (max-height: 500px) {
    .app-header { position: relative; }
    .summary { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
