:root {
    --ink: #2b2b2b;
    --muted: #6b7280;
    --flow: #e11d48;       /* red flow numbers */
    --totalizer: #f59e0b;  /* orange totalizer numbers */
    --panel: #ffffff;
    --page-bg: #f4f5f7;
    --border: #e5e7eb;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--page-bg);
    color: var(--ink);
}

/* ---------- Shell / top bar ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: 0.6rem 1.25rem;
    background: #0f2a43; color: #fff;
    position: sticky; top: 0; z-index: 10;
}
.app-brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.app-brand-mark { color: #6fb7e0; }
.app-brand-text { font-size: 1rem; }
.app-nav { display: flex; gap: .25rem; }
.app-nav-link {
    color: #cbd5e1; text-decoration: none; padding: .4rem .8rem;
    border-radius: 6px; font-size: .92rem;
}
.app-nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.app-nav-link.active { background: rgba(255,255,255,.16); color: #fff; }

.app-main { flex: 1; padding: 1rem 1.25rem 2.5rem; max-width: 1600px; width: 100%; margin: 0 auto; }

/* ---------- Page head / toolbar ---------- */
.page-head { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .5rem; }
.applied-filters { font-size: .72rem; font-weight: 700; color: #111; }
.applied-filters-value { font-size: .72rem; color: #111; }
.page-title { font-size: 1.15rem; font-weight: 600; letter-spacing: .04em; margin: .35rem 0 0; }

.toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 1rem;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: .75rem 1rem; margin: .75rem 0 1.25rem;
}
.brand-block { line-height: 1.15; }
.brand-logo { height: 46px; width: auto; max-width: 100%; display: block; }
.brand-title { font-weight: 700; color: #0f2a43; font-size: 1rem; }
.brand-sub { font-style: italic; color: var(--muted); font-size: .82rem; }
.datepicker-block { display: flex; flex-direction: column; gap: .25rem; }
.datepicker-block label { font-size: .78rem; color: var(--muted); }

.refresh-chip {
    margin-left: auto; display: inline-flex; align-items: center; gap: .5rem;
    font-size: .82rem; color: var(--muted);
    background: #f8fafc; border: 1px solid var(--border);
    padding: .35rem .7rem; border-radius: 999px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip-sep { color: #cbd5e1; margin: 0 .15rem; }
.dot-live { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.dot-busy { background: #f59e0b; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.error-banner {
    background: #fef2f2; color: #991b1b; border: 1px solid #fecaca;
    border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1rem; font-size: .9rem;
}
.warn-banner {
    background: #fffbeb; color: #92400e; border: 1px solid #fde68a;
    border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1rem; font-size: .9rem;
}

/* ---------- Live Status grid ---------- */
.live-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}
.live-card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.live-card-head {
    padding: .9rem 1rem; text-align: center; font-weight: 700;
    font-size: .95rem; color: #1f2937;
}
.live-card-body { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); }
.metric { background: #fff; padding: 1.1rem .75rem; text-align: center; }
.metric-label { font-size: .8rem; color: var(--muted); margin-bottom: .4rem; }
.totalizer-label { color: var(--totalizer); font-weight: 600; }
.metric-value { font-size: 2.4rem; font-weight: 700; line-height: 1; }
.metric-value.flow { color: var(--flow); }
.metric-value.totalizer { color: var(--totalizer); }

.updated-card {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 1.5rem 1rem; text-align: center;
}
.updated-value { font-size: 1.35rem; font-weight: 700; }
.updated-caption { font-size: .8rem; color: var(--muted); margin-top: .35rem; }

/* ---------- Equipment page ---------- */
.equip-row {
    display: grid;
    grid-template-columns: 1.15fr 1fr 1.35fr;
    gap: 1rem; margin-bottom: 1.25rem;
    align-items: stretch;
}
.equip-panel {
    background: var(--panel); border: 1px solid #e3e7eb;
    border-radius: 10px; padding: .5rem; overflow: hidden;
    box-shadow: 0 1px 3px rgba(16,24,40,.06);
}
.chart-panel { display: flex; flex-direction: column; }
.chart-bar { display: flex; justify-content: flex-end; gap: .35rem; padding: .3rem .35rem .4rem; }
.chart-panel.maximised .chart-host { height: auto; flex: 1 1 auto; min-height: 0; }
.expand-hint {
    text-align: center; font-size: .72rem; color: #94a3b8; padding: .35rem 0 .1rem; flex: 0 0 auto;
}
.gauge-panel { display: flex; flex-direction: column; justify-content: center; flex: 1 1 auto; }
.equip-left { display: flex; flex-direction: column; gap: 1rem; }
.totalizer-block {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 1.1rem 1rem; text-align: center;
}
.live-tag {
    display: flex; align-items: center; justify-content: center; gap: .4rem;
    font-size: .72rem; color: #16a34a; font-weight: 600; letter-spacing: .06em;
    margin: -.2rem 0 .1rem;
}
.equip-panel-title {
    font-weight: 700; font-size: .9rem; padding: .6rem .5rem; border-radius: 8px;
    margin-bottom: .5rem;
}
.equip-panel-title.center { text-align: center; }

.panel-bar {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    font-weight: 700; font-size: .9rem; padding: .55rem .7rem; border-radius: 8px;
    margin-bottom: .5rem;
}
.panel-bar.center-bar { justify-content: space-between; }
.bar-actions { display: flex; gap: .35rem; flex: 0 0 auto; }
.icon-btn {
    border: 1px solid rgba(0,0,0,.18); background: rgba(255,255,255,.75);
    border-radius: 6px; font-size: .72rem; padding: .15rem .5rem; cursor: pointer;
    color: #33404d; line-height: 1.5; white-space: nowrap;
}
.icon-btn:hover { background: #fff; }
.chart-host { width: 100%; height: 330px; }

.equip-panel.maximised {
    position: fixed; inset: 12px; z-index: 1000; overflow: hidden;
    background: #fff; box-shadow: 0 12px 48px rgba(0,0,0,.35);
    display: flex; flex-direction: column;
}
.gauge-readout { font-size: 1.4rem; font-weight: 700; text-align: center; }
.gauge-wrap { display: flex; justify-content: center; width: 100%; }
.svg-gauge { width: 100%; max-width: 290px; height: auto; display: block; margin: 0 auto; }
.gauge-value {
    text-align: center; font-size: 1.7rem; font-weight: 700;
    color: var(--totalizer); margin-top: -.35rem; line-height: 1;
}
.gauge-totalizer { margin-top: auto; text-align: center; padding: .5rem 0 .25rem; }
.equip-grid { border: none; }

/* ---------- Responsive: tablet ---------- */
@media (max-width: 1100px) {
    .equip-row { grid-template-columns: 1fr 1fr; }
    .equip-row .equip-panel:nth-child(3) { grid-column: 1 / -1; }
}

/* ---------- Responsive: mobile ---------- */
@media (max-width: 720px) {
    .app-main { padding: .75rem .75rem 2rem; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .refresh-chip { margin-left: 0; align-self: flex-start; }
    .live-grid { grid-template-columns: 1fr; }
    .metric-value { font-size: 2rem; }
    .equip-row { grid-template-columns: 1fr; }
    .equip-row .equip-panel:nth-child(3) { grid-column: auto; }
    .app-brand-text { font-size: .9rem; }
}

/* ---------- Auth: nav user + logout ---------- */
.nav-user {
    color: #cbd5e1; font-size: .9rem; margin-left: .5rem;
    padding: .4rem .6rem; border-left: 1px solid rgba(255,255,255,.15);
}
.logout-form { margin: 0; }
.logout-btn {
    background: rgba(255,255,255,.10); color: #fff; border: 1px solid rgba(255,255,255,.2);
    border-radius: 6px; padding: .35rem .8rem; font-size: .9rem; cursor: pointer;
}
.logout-btn:hover { background: rgba(255,255,255,.2); }

/* ---------- Login page ---------- */
.login-page {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 1rem;
    background: linear-gradient(160deg, #12456a 0%, #0f2a43 55%, #0a1c2e 100%);
    padding: 2rem 1rem;
}
.login-card {
    width: 100%; max-width: 400px; background: #fff;
    border-radius: 16px; padding: 2rem 1.8rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
    text-align: center;
}
.login-logo { width: 240px; max-width: 90%; height: auto; margin: .2rem auto 1rem; display: block; }
.login-heading { font-size: 1.25rem; font-weight: 700; color: #0f2a43; margin: .2rem 0 .3rem; }
.login-tagline { font-size: .8rem; color: #7a8794; margin: 0 0 1.4rem; }
.login-form { display: flex; flex-direction: column; text-align: left; }
.login-label { font-size: .82rem; color: #475569; font-weight: 600; margin: .6rem 0 .3rem; }
.login-input {
    width: 100%; box-sizing: border-box; padding: .65rem .75rem;
    border: 1px solid #d5dbe1; border-radius: 8px; font-size: .95rem; outline: none;
}
.login-input:focus { border-color: #12456a; box-shadow: 0 0 0 3px rgba(18,69,106,.15); }
.login-val { color: #b91c1c; font-size: .78rem; margin-top: .2rem; }
.login-submit {
    margin-top: 1.3rem; padding: .7rem 1rem; border: none; border-radius: 8px;
    background: #0f2a43; color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-submit:hover { background: #16506f; }
.login-submit:disabled { opacity: .6; cursor: default; }
.login-error {
    background: #fef2f2; color: #991b1b; border: 1px solid #fecaca;
    border-radius: 8px; padding: .6rem .8rem; font-size: .88rem; margin-bottom: .8rem; text-align: left;
}
.login-ok {
    background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0;
    border-radius: 8px; padding: .6rem .8rem; font-size: .88rem; margin-bottom: .8rem; text-align: left;
}
.login-footer { color: rgba(255,255,255,.6); font-size: .78rem; }

/* ---------- User management ---------- */
.users-grid {
    display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 1rem; align-items: start;
}
.users-card {
    background: #fff; border: 1px solid #e3e7eb; border-radius: 10px; padding: 1.1rem 1.2rem;
    box-shadow: 0 1px 3px rgba(16,24,40,.06);
}
.users-card-title { font-weight: 700; color: #0f2a43; margin-bottom: .8rem; }
.users-card .login-input { margin-bottom: .2rem; }
.users-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.users-table th, .users-table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid #eef1f4; }
.users-table th { color: #64748b; font-weight: 600; }
.users-empty { color: #94a3b8; text-align: center; }
.role-badge {
    display: inline-block; padding: .1rem .55rem; border-radius: 999px;
    background: #eef2f7; color: #475569; font-size: .78rem; font-weight: 600;
}
.role-badge.role-admin { background: #e6f4ea; color: #166534; }

@media (max-width: 820px) {
    .users-grid { grid-template-columns: 1fr; }
}

/* ---------- SignalR reconnect overlay (mobile-friendly) ---------- */
.reconnect-modal { display: none; }
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex; position: fixed; inset: 0; z-index: 20000;
    align-items: center; justify-content: center;
    background: rgba(10, 28, 46, .55);
}
.reconnect-box {
    background: #fff; border-radius: 12px; padding: 1.5rem 2rem; text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.35); min-width: 220px;
}
.reconnect-spinner {
    width: 34px; height: 34px; border: 3px solid #d5dbe1; border-top-color: #0f2a43;
    border-radius: 50%; margin: 0 auto .8rem; animation: reconnect-spin 1s linear infinite;
}
.reconnect-title { font-weight: 700; color: #0f2a43; }
.reconnect-sub { font-size: .82rem; color: #7a8794; margin-top: .2rem; }
@keyframes reconnect-spin { to { transform: rotate(360deg); } }
