/* =========================================================
   PC-04 PWA styles - cleaned consolidated version
   ========================================================= */

/* ---------- Base ---------- */
html {
    scrollbar-width: thin;
    scrollbar-color: rgba(60, 40, 15, 0.55) rgba(255, 170, 35, 0.25);
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: rgba(255, 170, 35, 0.25); }
::-webkit-scrollbar-thumb {
    background: rgba(60, 40, 15, 0.55);
    border-radius: 20px;
    border: 2px solid rgba(255, 170, 35, 0.35);
}
::-webkit-scrollbar-thumb:hover { background: rgba(30, 20, 8, 0.75); }

body { overflow-y: auto; }

.login-body,
.dashboard-body,
.device-body {
    margin: 0;
    min-height: 100vh;
    background: #f79f08;
    font-family: Arial, sans-serif;
    color: #111;
}

a { -webkit-tap-highlight-color: transparent; }

/* ---------- Shared top bars / action buttons ---------- */
.topbar,
.dashboard-topbar,
.device-topbar,
.page-list-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 18px 16px;
}

.topbar h1,
.dashboard-body .topbar h1,
.topbar.device-topbar h1 {
    margin: 0;
    font-size: 28px !important;
    font-weight: 800;
    line-height: 1.05;
}

.device-topbar { align-items: flex-start !important; }
.device-topbar .circle-action-btn { flex-shrink: 0; margin-top: 0; }

.topbar-subtitle {
    font-size: 16px;
    font-weight: 700;
    opacity: .65;
    margin-top: 0;
}

.page-title-wrap {
    display: flex;
    align-items: center;
    gap: 7px;
}

.page-inline-logo,
.page-inline-logo-dash {
    width: 34px;
    height: 34px;
    opacity: .55;
}

.page-inline-logo-dash { margin-top: -21px; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.circle-action-btn,
.add-device-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #111;
    color: #fff;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 22px rgba(0,0,0,.28);
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.circle-action-btn:focus,
.circle-action-btn:active,
.circle-action-btn:visited {
    outline: none;
    box-shadow: 0 8px 22px rgba(0,0,0,.28);
}

.add-device-btn:active { transform: scale(.95); }

.circle-icon-back,
.circle-icon-plus,
.circle-icon-close {
    width: 24px;
    height: 24px;
    display: block;
    flex-shrink: 0;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    filter: invert(1);
}

.circle-icon-back { background-image: url('/assets/icons/arrow-left.svg'); }
.circle-icon-plus { background-image: url('/assets/icons/plus.svg'); }
.circle-icon-close { background-image: url('/assets/icons/x.svg'); }

/* ---------- Login / register ---------- */
.login-page {
    min-height: 100dvh;
    height: auto;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    margin-top: 8%;
}

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 34px 26px;
    border-radius: 28px;
    background: rgba(255,255,255,.22);
    box-shadow: 0 12px 35px rgba(0,0,0,.20);
    backdrop-filter: blur(6px);
    text-align: center;
}

.login-brand img {
    width: 78px;
    height: 78px;
    opacity: .95;
    transform: translateY(-4px);
    filter: drop-shadow(0 10px 22px rgba(0,0,0,.22));
}

.login-card h1 {
    margin: 0;
    font-size: 48px;
    font-weight: 800;
}

.login-subtitle {
    margin: 8px 0 28px;
    font-size: 18px;
    opacity: .75;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-form input {
    width: 89%;
    padding: 15px 16px;
    border: none;
    border-radius: 16px;
    font-size: 17px;
    outline: none;
    background: rgba(255,255,255,.85);
}

.login-form input:focus { box-shadow: 0 0 0 3px rgba(0,0,0,.18); }

.login-form button {
    margin-top: 8px;
    padding: 15px;
    border: none;
    border-radius: 16px;
    font-size: 18px;
    font-weight: 700;
    background: #111;
    color: #fff;
}

.register-link {
    display: inline-block;
    margin-top: 22px;
    color: #111;
    font-size: 16px;
    font-weight: 700;
    text-decoration: none;
}
.register-link:hover { text-decoration: underline; }

.error-box {
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(255,80,80,.18);
    color: #7a0000;
    font-weight: 700;
    text-align: center;
}

.form-divider {
    margin: 8px 0 2px;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    opacity: .65;
}

/* ---------- Dashboard / list cards ---------- */
.dashboard-grid {
    padding: 0 18px 120px;
    display: grid;
    gap: 18px;
}

.dash-device-card {
    display: block;
    text-decoration: none;
    color: #111;
    background: rgba(255,255,255,.24);
    border-radius: 24px;
    padding: 22px 18px;
    box-shadow: 0 10px 28px rgba(0,0,0,.18);
    text-align: left;
}

.dash-device-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dash-device-name {
    margin-top: 0;
    font-size: 28px;
    font-weight: 900;
    line-height: 1.1;
}

.dash-device-id {
    margin-top: 8px;
    font-size: 15px;
    font-weight: 700;
    opacity: .65;
}

.dash-device-lastseen {
    margin-top: 8px;
    font-size: 14px;
    opacity: .52;
}

.dash-device-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dash-status-dot,
.status-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
}

.dash-status-dot.online,
.status-dot.online {
    background: #32d74b;
    box-shadow: 0 0 14px #32d74b;
}

.dash-status-dot.offline,
.status-dot.offline { background: #999; }

.dash-signal-icon {
    width: 28px;
    height: 28px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: .72;
}

.dash-signal-icon.offline {
    opacity: .18;
    filter: grayscale(1);
}

.empty-card {
    background: rgba(255,255,255,.22);
    border-radius: 24px;
    padding: 28px;
    text-align: center;
    font-size: 18px;
}

/* Telegram dashboard card */
.dash-telegram-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.dash-user-box,
.dash-telegram-box {
    margin: 10px 16px 20px;
    border-radius: 22px;
    background: rgba(255,255,255,.18);
    backdrop-filter: blur(8px);
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
}

.dash-telegram-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 20px 5px;
    cursor: pointer;
}

.dash-telegram-box:active { transform: scale(.985); }

.dash-telegram-left {
    display: flex;
    align-items: flex-start;
    gap: 32px;
    flex: 1;
}

.dash-telegram-icon {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    transform: translateY(-7px);
}

.dash-telegram-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    margin-left: -20px;
    margin-top: -4px;
}

.dash-telegram-title {
    font-size: 1.15rem;
    font-weight: 900;
    line-height: 1;
}

.dash-telegram-subtitle {
    margin-top: 4px;
    font-size: .7rem;
    font-weight: 800;
    color: rgba(60,120,50,.75);
    text-transform: uppercase;
    letter-spacing: .4px;
}

.dash-telegram-box.disconnected .dash-telegram-subtitle { color: #c94d4d; }

.dash-telegram-description {
    margin-top: 5px;
    font-size: .5rem;
    line-height: 1.35;
    color: #c94d4d;
}

.dash-telegram-arrow {
    width: 22px;
    height: 22px;
    background-image: url('/assets/icons/arrow-up-right.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: .45;
    flex-shrink: 0;
    margin-left: 18px;
    margin-top: -12px;
}

/* ---------- Device card / live view ---------- */
.device-page {
    min-height: 100dvh;
    height: auto;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 0 0 120px;
    margin-top: 0;
}

.device-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #111;
    background: rgba(255,255,255,.22);
    border-radius: 24px;
    padding: 20px;
    box-shadow: 0 10px 28px rgba(0,0,0,.18);
    backdrop-filter: blur(6px);
    width: 80%;
}

.pc04-device-head-icons {
    display: grid !important;
    grid-template-columns: 28px 1fr 28px !important;
    align-items: center !important;
    column-gap: 10px !important;
    width: 100% !important;
    min-height: 32px !important;
    margin-bottom: 4px !important;
}

.pc04-device-param-center {
    text-align: center !important;
    line-height: 1.2 !important;
    min-width: 0 !important;
    margin-top: -15px;
}

.pc04-device-icon {
    width: 22px !important;
    height: 22px !important;
    display: block !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    opacity: .72 !important;
}

.pc04-device-history-icon {
    justify-self: start !important;
    margin-left: 0 !important;
    margin-top: -15px;
    background-image: url('/assets/icons/chart-dots-2.svg') !important;
}

.pc04-device-signal-icon {
    justify-self: end !important;
    margin-right: 0 !important;
    margin-top: -15px;
    background-image: url('/assets/icons/antenna-bars-off.svg');
}

.pc04-device-signal-icon.is-offline { opacity: .30 !important; }

.small-label {
    display: block;
    width: 100%;
    text-align: center;
}

.device-name-main { font-weight: 900; }

.state-pill {
    display: block;
    width: fit-content;
    padding: 8px 22px;
    border-radius: 999px;
    font-size: 20px;
    font-weight: 800;
    background: rgba(255,255,255,.45);
    margin: 6px auto 24px;
}

.tower-row {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin: 18px 0 10px;
}

.tower-lamp {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    opacity: .18;
    transition: .2s ease;
}

.tower-lamp.active {
    opacity: 1;
    transform: scale(1.08);
}

.tower-green { background: #20b24b; }
.tower-yellow { background: #FFFD01; }
.tower-red { background: #d62d2d; }

.tower-green.active { box-shadow: 0 0 10px rgba(32,178,75,.9), 0 0 22px rgba(32,178,75,.55); }
.tower-yellow.active { box-shadow: 0 0 12px rgba(255,220,0,.95), 0 0 28px rgba(255,220,0,.75); }
.tower-red.active { box-shadow: 0 0 10px rgba(214,45,45,.9), 0 0 22px rgba(214,45,45,.55); }

.value-center {
    width: 100%;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 6px;
    margin: 34px 0 20px;
}

.big-value {
    font-size: 82px;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -2px;
}

.big-unit {
    font-size: 34px;
    font-weight: 800;
    margin-left: 6px;
}

.current-line {
    width: 100%;
    text-align: center;
    font-size: 24px;
    margin: -20px 0 38px;
}

.current-error {
    color: #c40000;
    animation: currentBlink 1s infinite;
}

@keyframes currentBlink {
    0% { opacity: 1; }
    50% { opacity: .35; }
    100% { opacity: 1; }
}

.measurement-invalid {
    opacity: .15;
    filter: grayscale(1);
}

.outputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 24px;
}

.out-box {
    text-align: center;
    padding: 16px 10px;
    border-radius: 20px;
    background: rgba(255,255,255,.32);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 140px;
}

.out-box span {
    display: block;
    font-size: 15px;
    opacity: .7;
}

.out-box strong {
    display: block;
    font-size: 28px;
    margin-top: 5px;
}

.out-box.out-on { background: rgba(120,240,120,.45); }
.out-box.out-off { background: rgba(255,80,70,.55); }
.out-box.out-offline {
    background: rgba(150,150,150,.45);
    color: rgba(0,0,0,.55);
}

.updated {
    font-size: 16px;
    opacity: .55;
    margin-top: 28px;
}

/* ---------- History ---------- */
.history-page {
    padding: 18px 18px 120px;
    display: flex;
    justify-content: center;
}

.history-card {
    width: 95%;
    max-width: 1100px;
    background: rgba(255,255,255,.22);
    border-radius: 28px;
    padding: 22px;
    box-shadow: 0 12px 32px rgba(0,0,0,.18);
    backdrop-filter: blur(6px);
}

.history-filter {
    display: flex;
    gap: 10px;
    margin-bottom: 22px;
}

.history-filter input,
.history-filter button {
    border: none;
    border-radius: 14px;
    padding: 12px 16px;
    font-size: 16px;
}

.history-filter button,
.history-export-btn {
    background: #111;
    color: #fff;
    font-weight: 800;
}

.history-chart {
    height: 280px;
    margin-bottom: 28px;
    background: rgba(255,255,255,.25);
    border-radius: 20px;
    padding: 10px;
}

.history-table-wrap { overflow-x: auto; }
.history-table {
    width: 100%;
    border-collapse: collapse;
}

.history-table th,
.history-table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid rgba(0,0,0,.08);
    white-space: nowrap;
}

.history-table th {
    font-size: 15px;
    opacity: .72;
}

.history-table td { font-weight: 700; }
.history-value { white-space: nowrap; }

.history-actions {
    margin-top: 24px;
    display: flex;
    justify-content: center;
}

.history-export-btn {
    text-decoration: none;
    padding: 14px 22px;
    border-radius: 18px;
}

.history-scroll-bottom {
    position: fixed;
    right: 18px;
    bottom: 92px;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: #111;
    color: #fff;
    font-size: 1.5rem;
    font-weight: 900;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
    z-index: 40;
    cursor: pointer;
}

.history-scroll-bottom:active { transform: scale(.96); }

/* ---------- Settings / profile / config ---------- */
.settings-card {
    background: rgba(255,255,255,.24);
    border-radius: 28px;
    padding: 28px;
    box-shadow: 0 18px 40px rgba(0,0,0,.16);
    margin-bottom: 110px;
}

.settings-device-id {
    margin-top: 0;
    margin-bottom: -4px;
    font-size: 34px;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-form label {
    display: block;
    margin-top: 12px;
    margin-bottom: -7px;
    font-size: 1rem;
    font-weight: 800;
}

.settings-form input {
    width: 100%;
    box-sizing: border-box;
    border: none;
    border-radius: 18px;
    padding: 16px 18px;
    font-size: 20px;
    font-weight: 700;
    background: rgba(255,255,255,.7);
    color: #111;
    outline: none;
    margin-top: 0;
    margin-bottom: 0;
}

.settings-form button,
.save-settings-btn {
    margin-top: 0;
    margin-bottom: 4px;
    border: none;
    border-radius: 22px;
    padding: 18px;
    background: #111;
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    box-shadow: 0 8px 22px rgba(0,0,0,.24);
}

.settings-form label.settings-check-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 14px;
    margin-top: 12px;
    margin-bottom: 0;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.2;
}

.settings-form label.settings-check-row + label.settings-check-row { margin-top: 10px; }

.settings-form label.settings-check-row input[type="checkbox"] {
    width: 24px;
    height: 24px;
    margin: 0;
    flex: 0 0 24px;
    accent-color: #111;
}

.settings-form label.settings-check-row span {
    display: inline-block;
    line-height: 1.2;
}

.settings-section-title {
    margin-top: 22px;
    margin-bottom: 10px;
    font-size: 1.05rem;
    font-weight: 900;
}

.form-success,
.form-error {
    padding: 14px 18px;
    border-radius: 16px;
    margin-bottom: 18px;
    font-weight: 700;
}

.form-success { background: rgba(50,180,80,.18); color: #155724; }
.form-error { background: rgba(255,80,80,.18); color: #7a0000; }

.settings-info {
    margin-top: 24px;
    background: rgba(255,255,255,.18);
    border-radius: 20px;
    padding: 14px 16px;
}

.settings-info summary {
    cursor: pointer;
    font-size: 18px;
    font-weight: 800;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.settings-info summary::-webkit-details-marker { display: none; }

.settings-info summary::after {
    content: "";
    width: 24px;
    height: 24px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 24px;
    opacity: .78;
    transition: .18s ease;
    flex-shrink: 0;
    background-image: url('/assets/icons/caret-down.svg');
}

.settings-info[open] summary::after { background-image: url('/assets/icons/caret-up.svg'); }

.settings-info-grid {
    margin-top: 14px;
    display: grid;
    gap: 10px;
}

.settings-info-grid div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.settings-info-grid span { opacity: .72; }
.settings-info-grid strong { font-weight: 800; }

.settings-separator {
    height: 1px;
    background: rgba(0,0,0,.10);
    margin: 10px 0;
}

.settings-info-note {
    margin-top: 4px;
    margin-bottom: 20px;
    font-size: 14px;
    opacity: .65;
    line-height: 1.3;
}

.fw-outdated { color: #c40000; }
.fw-update-note {
    margin-top: 4px;
    font-size: 13px;
    font-weight: 800;
    color: #c40000;
}

.wifi-config-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wifi-config-icon {
    width: 18px;
    height: 18px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: .65;
}

.config-edit-btn {
    margin-top: 18px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 14px;
    background: rgba(255,255,255,.06);
    text-decoration: none;
    color: inherit;
    font-weight: 700;
    font-size: .95rem;
    transition: background .15s ease, transform .15s ease;
}

.config-edit-btn:hover { background: rgba(255,255,255,.1); }
.config-edit-btn:active { transform: scale(.985); }

.config-edit-icon {
    width: 18px;
    height: 18px;
    background-image: url('/assets/icons/edit.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: .8;
}

/* Config history */
.config-history-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.config-history-item {
    padding: 16px 18px;
    border-radius: 18px;
    background: rgba(255,255,255,.08);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.config-history-summary {
    list-style: none;
    cursor: pointer;
}

.config-history-summary::-webkit-details-marker { display: none; }

.config-history-details {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid rgba(0,0,0,.12);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.config-history-top,
.config-history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.config-history-top strong,
.config-history-row { font-weight: 900; }
.config-history-row { font-size: .92rem; }
.config-history-row span { opacity: .65; }
.config-history-row strong {
    min-width: 0;
    text-align: right;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.config-history-main-row span,
.config-history-main-row strong { font-weight: 500; }
.config-status-pending { color: #c47a00; font-weight: 900; }
.config-status-applied { color: #4f8f35; font-weight: 900; }

/* Profile */
.profile-link,
.profile-link-danger {
    font-weight: 900;
    text-decoration: none;
}

.profile-link { color: #111; }
.profile-link-danger { color: #c40000; }

.profile-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.profile-label {
    display: flex;
    align-items: center;
    gap: 10px;
}

.profile-icon {
    width: 18px;
    height: 18px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: .72;
}

.profile-icon-mail { background-image: url('/assets/icons/mail.svg'); }
.profile-icon-telegram { background-image: url('/assets/icons/brand-telegram.svg'); }
.profile-icon-lock { background-image: url('/assets/icons/lock.svg'); }
.profile-icon-logout { background-image: url('/assets/icons/logout.svg'); }

.profile-action,
.profile-action-danger {
    display: block;
    margin-top: 16px;
    padding: 14px 18px;
    border-radius: 16px;
    text-align: center;
    text-decoration: none;
    font-weight: 900;
}

.profile-action { background: rgba(0,0,0,.08); color: #111; }
.profile-action-danger { background: rgba(196,0,0,.12); color: #c40000; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 54px;
    background: rgba(20,20,20,.92);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    grid-template-columns: repeat(4, 1fr);
    z-index: 999;
    transition: transform .25s ease, opacity .25s ease;
    will-change: transform;
}

.bottom-nav.nav-hidden {
    transform: translateY(110%);
    opacity: 0;
    pointer-events: none;
}

.bottom-nav a {
    color: rgba(255,255,255,.78);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 700;
}

.bottom-nav a.active { color: #ffbf47; }

.bottom-nav img {
    width: 24px;
    height: 24px;
    display: block;
    margin: 0 auto 4px;
    opacity: .85;
    filter: invert(1);
}

.bottom-nav a.active img {
    opacity: 1;
    filter: invert(74%) sepia(85%) saturate(539%) hue-rotate(349deg) brightness(101%) contrast(101%);
}

/* ---------- SCADA view ---------- */
.scada-page { padding: 0 24px 110px; }

.scada-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 22px;
    justify-items: center;
}

.scada-card {
    width: 100%;
    max-width: 640px;
    box-sizing: border-box;
    cursor: grab;
}

@media (min-width: 900px) {
    .scada-page {
        padding-left: 42px;
        padding-right: 42px;
    }

    .scada-grid {
        grid-template-columns: repeat(auto-fill, 380px);
        justify-content: start;
        justify-items: stretch;
        align-items: start;
        gap: 26px;
    }

    .scada-card {
        width: 380px !important;
        max-width: 380px !important;
        min-height: 610px;
        box-sizing: border-box;
    }
}

@media (max-width: 899px) and (orientation: landscape) {
    .scada-page {
        padding-left: 18px;
        padding-right: 18px;
    }

    .scada-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 360px));
        justify-content: start;
        justify-items: stretch;
        gap: 18px;
    }

    .scada-card {
        width: 360px !important;
        max-width: 360px !important;
        min-height: 560px;
    }

    .scada-card .big-value { font-size: 3.8rem; }
    .scada-card .out-box {
        width: 62px;
        height: 98px;
        min-height: 98px;
    }
    .scada-card .out-box strong { font-size: 1.25rem; }
    .scada-card .updated { margin-top: 20px; }
}

.scada-card-header {
    display: grid;
    grid-template-columns: 28px 1fr 28px;
    align-items: start;
    column-gap: 10px;
    width: 100%;
    margin-bottom: 16px;
}

.scada-head-icon {
    width: 22px;
    height: 22px;
    display: block;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: .72;
}

.scada-history-icon {
    justify-self: start;
    background-image: url('/assets/icons/chart-dots-2.svg');
}

.scada-signal-icon {
    justify-self: end;
    background-image: url('/assets/icons/antenna-bars-off.svg');
}

.scada-signal-icon.is-offline { opacity: .30; }

.scada-title-center {
    min-width: 0;
    text-align: center;
}

.scada-title-line {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    max-width: 100%;
}

.scada-title-line h2 {
    margin: 0;
    font-size: 1.35rem;
    line-height: 1.08;
    font-weight: 900;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scada-open-device {
    color: inherit;
    text-decoration: none;
}

.scada-device-id {
    margin-top: 5px;
    font-size: .78rem;
    font-weight: 800;
    opacity: .68;
}

.scada-param-row {
    margin-bottom: 24px;
    text-align: center;
    font-size: .95rem;
    line-height: 1.2;
}

.scada-param-row span { opacity: .75; }
.scada-param-row strong { font-weight: 900; }

.scada-card .state-pill {
    margin-top: 0;
    margin-bottom: 24px;
}

.scada-card .value-center { margin-top: 18px; }
.scada-card .big-value { font-size: 4.3rem; }
.scada-card .current-line { font-size: 1.25rem; }
.scada-card .outputs {
    margin-top: 28px;
    gap: 14px;
}

.scada-card .out-box {
    width: 68px;
    height: 108px;
    min-height: 108px;
    border-radius: 20px;
    padding: 10px 8px;
}

.scada-card .out-box span {
    font-size: .78rem;
    letter-spacing: .04em;
}

.scada-card .out-box strong {
    font-size: 1.4rem;
    line-height: 1;
}

.scada-card .updated { margin-top: 28px; }
.scada-card.is-offline { opacity: .65; }
.scada-card:active { cursor: grabbing; }
.scada-card-ghost { opacity: .35; }
.scada-card-chosen { transform: scale(.985); }
.scada-card-drag { box-shadow: 0 18px 42px rgba(0,0,0,.24); }
.history-scroll-bottom-icon {
    width: 24px;
    height: 24px;

    display: block;

    background-image: url('/assets/icons/arrow-left.svg');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;

    filter: invert(1);

    transform: rotate(270deg);
}
.history-scroll-bottom {
    transition: transform 0.25s ease, opacity 0.25s ease;
    will-change: transform;
}

.history-scroll-bottom.nav-hidden {
    transform: translateY(130%);
    opacity: 0;
    pointer-events: none;
}
.history-scroll-bottom {
    -webkit-tap-highlight-color: transparent;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
}

.history-scroll-bottom:focus,
.history-scroll-bottom:active {
    outline: none;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
}/* Relay output cards */

.relay-outputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;

    width: 100%;
    margin-top: 26px;
    margin-bottom: 24px;

    justify-items: center;
}

.relay-card {
    width: 138px;
    min-height: 205px;

    border-radius: 22px;
    padding: 14px 12px 12px;

    background: rgba(255,255,255,.42);
    border: 2px solid rgba(0,0,0,.16);

    text-align: center;
    box-sizing: border-box;

    box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.18),
    0 8px 20px rgba(0,0,0,.08);
}

.relay-card.relay-on {
    color: #386f20;
    border-color: rgba(56,111,32,.85);
}

.relay-card.relay-off {
    color: #555;
    border-color: rgba(140,80,40,.45);
}

.relay-title {
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: .12em;
    margin-bottom: 4px;
}

.relay-symbol {
    width: 100%;
    max-width: 128px;
    height: auto;

    display: block;
    margin: 0 auto 2px;

    stroke: currentColor;
    fill: none;
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.relay-symbol circle {
    fill: rgba(255,255,255,.55);
    stroke: currentColor;
}

.relay-dashed {
    stroke-dasharray: 8 7;
    opacity: .85;
}

.relay-contact {
    stroke-width: 5;
}

.relay-contact-on {
    display: none;
}

.relay-contact-off {
    display: block;
}

.relay-on .relay-contact-on {
    display: block;
}

.relay-on .relay-contact-off {
    display: none;
}

.relay-terminals {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;

    margin-top: 0;
    padding-bottom: 10px;

    border-bottom: 2px solid rgba(0,0,0,.22);
}

.relay-terminals strong {
    display: block;
    font-size: .95rem;
    font-weight: 900;
    line-height: 1;
}

.relay-terminals span {
    display: block;
    margin-top: 3px;

    font-size: .68rem;
    font-weight: 800;
    opacity: .78;
}

.relay-state {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;

    margin-top: 12px;
}

.relay-state strong {
    font-size: 1.55rem;
    font-weight: 900;
    line-height: 1;
}

.relay-dot {
    width: 25px;
    height: 25px;

    border-radius: 50%;
    background: #777;

    box-shadow: inset 0 0 0 2px rgba(0,0,0,.18);
}

.relay-on .relay-dot {
    background: #65b82e;
    box-shadow:
    0 0 12px rgba(101,184,46,.55),
    inset 0 0 0 2px rgba(0,0,0,.15);
}

.relay-off .relay-dot {
    background: #777;
}

/* SCADA compact relay cards */
.scada-card .relay-outputs {
    margin-top: 24px;
    gap: 14px;
}

.scada-card .relay-card {
    width: 118px;
    min-height: 178px;
    padding: 12px 9px 10px;
    border-radius: 18px;
}

.scada-card .relay-title {
    font-size: .95rem;
}

.scada-card .relay-symbol {
    max-width: 112px;
}

.scada-card .relay-state strong {
    font-size: 1.35rem;
}

.scada-card .relay-dot {
    width: 22px;
    height: 22px;
}

.scada-card .relay-terminals strong {
    font-size: .82rem;
}

.scada-card .relay-terminals span {
    font-size: .58rem;
}
.relay-fixed-contact,
.relay-terminal-stem {
    stroke: currentColor;
    stroke-width: 4;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.relay-contact {
    stroke-width: 5;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.relay-contact-on {
    display: none;
}

.relay-contact-off {
    display: block;
}

.relay-on .relay-contact-on {
    display: block;
}

.relay-on .relay-contact-off {
    display: none;
}
/* Relay outputs desktop alignment */
.relay-outputs {
    max-width: 430px;
    margin-left: auto;
    margin-right: auto;
    column-gap: 34px;
}
.relay-outputs {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 22px;

    width: 100%;
    margin-top: 26px;
    margin-bottom: 24px;
}
/* Compact relay cards in SCADA View */

.scada-card .scada-relay-outputs {
    gap: 14px;
    margin-top: 22px;
    margin-bottom: 20px;
}

.scada-card .relay-card {
    width: 112px;
    flex: 0 0 112px;
    min-height: 160px;

    padding: 10px 8px 9px;
    border-radius: 18px;
}

.scada-card .relay-title {
    font-size: .82rem;
    letter-spacing: .18em;
    margin-bottom: 3px;
}

.scada-card .relay-symbol {
    max-width: 92px;
    stroke-width: 4;
    margin-bottom: 0;
}

.scada-card .relay-terminals {
    padding-bottom: 7px;
}

.scada-card .relay-terminals strong {
    font-size: .72rem;
}

.scada-card .relay-terminals span {
    font-size: .50rem;
    margin-top: 2px;
}

.scada-card .relay-state {
    margin-top: 8px;
    gap: 7px;
}

.scada-card .relay-state strong {
    font-size: 1.15rem;
}

.scada-card .relay-dot {
    width: 18px;
    height: 18px;
}

/* Device page relay fine tuning */

.device-card .relay-outputs {
    gap: 20px;
    margin-top: 24px;
    margin-bottom: 22px;
}

.device-card .relay-card {
    width: 126px;
    flex: 0 0 126px;
    min-height: 182px;

    padding: 11px 9px 10px;
    border-radius: 19px;
}

.device-card .relay-title {
    font-size: .9rem;
    letter-spacing: .18em;
    margin-bottom: 4px;
}

.device-card .relay-symbol {
    max-width: 108px;
}

.device-card .relay-terminals {
    padding-bottom: 8px;
}

.device-card .relay-terminals strong {
    font-size: .82rem;
}

.device-card .relay-terminals span {
    font-size: .58rem;
}

.device-card .relay-state {
    margin-top: 9px;
    gap: 8px;
}

.device-card .relay-state strong {
    font-size: 1.35rem;
}

.device-card .relay-dot {
    width: 21px;
    height: 21px;
}
/* Device page relay compact FINAL */

body.device-body .device-card .relay-outputs {
    gap: 18px !important;
    margin-top: 22px !important;
    margin-bottom: 20px !important;
}

body.device-body .device-card .relay-card {
    width: 124px !important;
    flex: 0 0 124px !important;
    min-height: 178px !important;

    padding: 10px 8px 9px !important;
    border-radius: 18px !important;
}

body.device-body .device-card .relay-title {
    font-size: .88rem !important;
    letter-spacing: .16em !important;
    margin-bottom: 3px !important;
}

body.device-body .device-card .relay-symbol {
    max-width: 104px !important;
}

body.device-body .device-card .relay-terminals {
    padding-bottom: 7px !important;
}

body.device-body .device-card .relay-terminals strong {
    font-size: .78rem !important;
}

body.device-body .device-card .relay-terminals span {
    font-size: .55rem !important;
}

body.device-body .device-card .relay-state {
    margin-top: 8px !important;
    gap: 7px !important;
}

body.device-body .device-card .relay-state strong {
    font-size: 1.28rem !important;
}

body.device-body .device-card .relay-dot {
    width: 20px !important;
    height: 20px !important;
}
/* Config wizard */

.wizard-card {
    max-width: 720px;
}

.wizard-step {
    display: none;
}

.wizard-step.active {
    display: block;
}

.wizard-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;

    gap: 14px;

    margin-top: 24px;
}

.wizard-nav button:disabled {
    opacity: .35;
    cursor: default;
}

.wizard-step-counter {
    font-size: .9rem;
    font-weight: 900;
    opacity: .75;
    white-space: nowrap;
}

.wizard-json-preview {
    width: 100%;
    min-height: 260px;

    box-sizing: border-box;

    border: none;
    border-radius: 18px;

    padding: 16px;

    font-family: monospace;
    font-size: .86rem;
    font-weight: 700;
    line-height: 1.35;

    background: rgba(255,255,255,.72);
    color: #111;

    outline: none;
    resize: vertical;
}

.wizard-actions-final {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;

    margin-top: 18px;
}

@media (min-width: 700px) {
    .wizard-actions-final {
        grid-template-columns: 1fr 1fr;
    }
}
/* Config wizard layout fixes */

.wizard-card {
    max-width: 720px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 120px;
}

.wizard-json-preview {
    display: block;
    width: 100%;
    max-width: 100%;
    min-height: 220px;

    box-sizing: border-box;

    border: none;
    border-radius: 18px;

    padding: 14px 16px;

    font-family: monospace;
    font-size: .82rem;
    font-weight: 700;
    line-height: 1.35;

    background: rgba(255,255,255,.72);
    color: #111;

    outline: none;
    resize: vertical;
    overflow: auto;
}

.wizard-actions-final {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;

    margin-top: 18px;
    padding-bottom: 30px;
}

.wizard-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;

    gap: 14px;

    margin-top: 24px;
    padding-bottom: 20px;
}

@media (max-width: 699px) {
    .wizard-card {
        padding-left: 22px;
        padding-right: 22px;
    }

    .wizard-json-preview {
        font-size: .76rem;
        min-height: 190px;
    }
}
/* Config wizard form cleanup */

.wizard-card {
    width: 100%;
    max-width: 640px;
    box-sizing: border-box;
    padding-bottom: 120px;
}

.wizard-card .settings-form label {
    display: block;
    margin-top: 18px;
    margin-bottom: 8px;

    font-size: 1rem;
    font-weight: 900;
    line-height: 1.2;
}

.wizard-card .settings-form input,
.wizard-card .settings-form select,
.wizard-card .settings-form textarea {
    width: 100%;
    box-sizing: border-box;

    border: none;
    border-radius: 18px;

    padding: 15px 18px;

    font-size: 1.05rem;
    font-weight: 800;

    background: rgba(255,255,255,.72);
    color: #111;

    outline: none;
}

.wizard-card .settings-form select {
    appearance: none;
    -webkit-appearance: none;

    min-height: 54px;

    background-image:
    linear-gradient(45deg, transparent 50%, #111 50%),
    linear-gradient(135deg, #111 50%, transparent 50%);
    background-position:
    calc(100% - 22px) 50%,
    calc(100% - 16px) 50%;
    background-size:
    6px 6px,
    6px 6px;
    background-repeat: no-repeat;
}

.wizard-card .settings-section-title {
    margin-top: 0;
    margin-bottom: 20px;

    font-size: 1.15rem;
    font-weight: 900;
}

.wizard-card .settings-device-id {
    margin-bottom: 26px;
}

.wizard-json-preview {
    min-height: 220px;
    font-size: .78rem !important;
    line-height: 1.35;
    white-space: pre;
    overflow: auto;
}
.wizard-readonly-field {
    width: 100%;
    box-sizing: border-box;

    border-radius: 18px;
    padding: 15px 18px;

    font-size: 1.05rem;
    font-weight: 900;

    background: rgba(255,255,255,.45);
    color: rgba(0,0,0,.72);
}
/* Wizard help */

.wizard-label-help {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;

    margin-top: 18px;
    margin-bottom: 8px;
}

.wizard-label-help label {
    margin: 0 !important;
}

.help-btn {
    width: 28px;
    height: 28px;

    flex: 0 0 28px;

    border: none;
    border-radius: 50%;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    font-size: .95rem;
    font-weight: 900;
    line-height: 1;

    background: rgba(0,0,0,.14);
    color: #111;

    cursor: pointer;

    -webkit-tap-highlight-color: transparent;
}

.help-btn.active {
    background: rgba(0,0,0,.82);
    color: #fff;
}

.help-box {
    display: none;

    margin: 0 0 12px;
    padding: 12px 14px;

    border-radius: 14px;

    background: rgba(255,255,255,.52);
    color: rgba(0,0,0,.78);

    font-size: .88rem;
    font-weight: 700;
    line-height: 1.35;
}

.help-box.active {
    display: block;
}
.profile-action-card {
    display: flex;
    align-items: center;
    gap: 14px;

    width: 100%;
    box-sizing: border-box;

    padding: 16px 18px;
    margin-top: 18px;

    border-radius: 20px;

    background: rgba(255,255,255,.52);
    color: #111;

    text-decoration: none;

    box-shadow: 0 8px 22px rgba(0,0,0,.08);
}

.profile-action-icon {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;

    opacity: .9;
}

.profile-action-title {
    display: block;

    font-size: 1.05rem;
    font-weight: 900;
    line-height: 1.15;
}

.profile-action-subtitle {
    display: block;
    margin-top: 4px;

    font-size: .86rem;
    font-weight: 700;
    opacity: .72;
    line-height: 1.25;
}
