:root {
    --app-bg: #1e1f22;
    --app-bg-deep: #191a1d;
    --panel: #2b2d30;
    --panel-2: #313338;
    --panel-hover: #3f4248;
    --border: #43454a;
    --border-soft: #36383d;
    --text: #f0f1f2;
    --text-muted: #a9adb5;
    --text-dim: #7f848d;
    --primary: #0d6efd;
    --primary-hover: #3d8bfd;
    --sidebar-width: 300px;
    --control-height: 40px;
    --radius: 7px;
    --radius-lg: 10px;
    --transition: 180ms ease;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    background: var(--app-bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

body {
    min-height: 100vh;
}

body.app-view {
    overflow: hidden;
    user-select: none;
}

a {
    color: var(--primary-hover);
    text-decoration: none;
}

a:hover {
    color: #6ea8fe;
}

.text-secondary,
.text-body-secondary {
    color: var(--text-muted) !important;
}

.login-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 18px;
    background:
        radial-gradient(circle at 18% 20%, rgba(13, 110, 253, .08), transparent 28%),
        radial-gradient(circle at 84% 74%, rgba(25, 135, 84, .05), transparent 30%),
        var(--app-bg-deep);
}

.login-shell {
    width: min(100%, 420px);
}

.login-shell-wide {
    width: min(100%, 520px);
}

.login-card {
    background: rgba(43, 45, 48, .97);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .35);
    padding: 30px;
}

.brand-lockup,
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    border: 1px solid rgba(91, 154, 255, .45);
    border-radius: 10px;
    background:
        linear-gradient(150deg, rgba(13, 110, 253, .22), rgba(25, 135, 84, .16)),
        #25272a;
    color: #e8f1ff;
    font-size: 18px;
    font-weight: 800;
}

.brand-text {
    display: grid;
}

.brand-name {
    font-size: 18px;
    font-weight: 650;
    color: var(--text);
}

.brand-caption {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 1px;
}

.login-title {
    margin-top: 32px;
    margin-bottom: 5px;
    font-size: 22px;
    font-weight: 650;
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.login-footer {
    margin-top: 18px;
    text-align: center;
}

.form-label {
    color: #d9dbdf;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 7px;
}

.form-control,
.form-select,
.form-check-input,
.input-group-text {
    background-color: #25272a;
    border-color: var(--border);
    color: var(--text);
    box-shadow: none !important;
}

.form-control,
.form-select {
    min-height: var(--control-height);
    border-radius: var(--radius);
    padding: 8px 11px;
}

.form-control::placeholder {
    color: #777c85;
}

.form-control:focus,
.form-select:focus {
    background-color: #292b2f;
    color: var(--text);
    border-color: #5b9aff;
    box-shadow: 0 0 0 2px rgba(13, 110, 253, .14) !important;
}

.btn {
    --bs-btn-border-radius: 6px;
    min-height: 38px;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 13px;
    box-shadow: none !important;
}

.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-hover);
    --bs-btn-hover-border-color: var(--primary-hover);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 1030;
    background: #25272a;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-inner {
    min-height: 0;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #4b4e54 transparent;
}

.sidebar-brand {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 78px;
    padding: 18px 20px;
    background: #25272a;
    border-bottom: 1px solid var(--border-soft);
    white-space: nowrap;
}

.sidebar-section-title {
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .12em;
    padding: 20px 20px 8px;
    white-space: nowrap;
}

.sidebar-menu {
    padding: 0 10px 18px;
}

.sidebar-menu .nav-link {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 42px;
    margin-bottom: 3px;
    padding: 9px 12px;
    border-radius: 6px;
    color: #c8cbd0;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition);
}

.sidebar-menu .nav-link:hover {
    background: var(--panel-hover);
    color: #fff;
}

.sidebar-menu .nav-link.active {
    background: rgba(13, 110, 253, .15);
    color: #dbe9ff;
}

.nav-icon {
    width: 20px;
    min-width: 20px;
    text-align: center;
    color: #9ca3ad;
    font-size: 16px;
}

.sidebar-footer {
    margin-top: auto;
    padding: 14px 12px 22px;
    border-top: 1px solid var(--border-soft);
}

.profile-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 7px;
    white-space: nowrap;
}

.profile-avatar {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    flex: 0 0 34px;
    border-radius: 50%;
    background: #3a3d42;
    border: 1px solid #4f535a;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

.profile-name {
    font-size: 12px;
    font-weight: 650;
    color: #eef0f2;
}

.profile-role {
    font-size: 10px;
    color: var(--text-dim);
}

.icon-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #282a2e;
    color: #b9bdc4;
    padding: 0;
}

.icon-btn:hover {
    background: #373a3f;
    color: #fff;
    border-color: #595d65;
}

.main {
    height: 100vh;
    margin-left: var(--sidebar-width);
    overflow: auto;
    background:
        radial-gradient(circle at 90% 0%, rgba(13, 110, 253, .035), transparent 25%),
        var(--app-bg);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    min-height: 62px;
    padding: 0 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: rgba(30, 31, 34, .92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-soft);
}

.topbar-title {
    font-size: 15px;
    font-weight: 650;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.topbar-user {
    max-width: 220px;
    color: var(--text-muted);
    font-size: 12px;
}

.mobile-menu-btn {
    display: none;
}

.main-content {
    padding: 26px;
    max-width: 1680px;
    margin: 0 auto;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.page-title {
    margin: 0 0 4px;
    font-size: 23px;
    font-weight: 650;
}

.page-subtitle {
    color: var(--text-muted);
    margin: 0;
    font-size: 13px;
}

.panel,
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.panel {
    overflow: hidden;
}

.panel-header {
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border-soft);
}

.panel-title {
    margin: 0;
    font-size: 13px;
    font-weight: 650;
    color: #e8e9eb;
}

.panel-subtitle {
    margin: 3px 0 0;
    color: var(--text-muted);
    font-size: 12px;
}

.stat-card {
    min-height: 126px;
    padding: 16px;
}

.pump-card {
    position: relative;
    overflow: hidden;
}

.pump-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), rgba(25, 135, 84, .85));
}

.stat-label {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .07em;
}

.stat-value {
    margin-top: 9px;
    font-size: 23px;
    font-weight: 650;
}

.stat-value-sm {
    font-size: 18px;
}

.stat-meta {
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 12px;
}

.table-finora {
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--border-soft);
    --bs-table-color: var(--text);
    --bs-table-hover-bg: rgba(255, 255, 255, .025);
    --bs-table-hover-color: var(--text);
    font-size: 13px;
}

.table-finora thead th {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    border-bottom-color: var(--border);
    padding: 12px 16px;
}

.table-finora tbody td {
    padding: 13px 16px;
    border-color: var(--border-soft);
}

.table-finora tbody tr:hover {
    background: rgba(255, 255, 255, .025);
}

.badge {
    border-radius: 999px;
    font-size: 11px;
    font-weight: 650;
    padding: 5px 8px;
}

.alert {
    border-radius: var(--radius);
}

.panel-body {
    padding: 16px;
}

.field-note {
    margin-top: 7px;
    color: var(--text-dim);
    font-size: 12px;
}

.settings-state {
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
}

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

.settings-preview-item {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--panel-2);
}

.settings-preview-item strong {
    display: block;
    margin-top: 6px;
    overflow: hidden;
    color: var(--text);
    font-size: 13px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border-soft);
}

#onWaterPump[disabled] {
    opacity: .6;
    pointer-events: none;
}

@media (max-width: 991.98px) {
    body.app-view {
        overflow: auto;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition);
    }

    body.sidebar-mobile-open .sidebar {
        transform: translateX(0);
    }

    .main {
        height: auto;
        min-height: 100vh;
        margin-left: 0;
    }

    .mobile-menu-btn {
        display: grid;
    }

    .main-content {
        padding: 20px 14px;
    }

    .page-head {
        align-items: stretch;
        flex-direction: column;
    }

    .page-head .btn {
        width: 100%;
    }

    .settings-preview {
        grid-template-columns: 1fr;
    }

    .panel-actions {
        display: grid;
    }
}

@media (max-width: 768px) {
    .table-finora,
    .table-finora thead,
    .table-finora tbody,
    .table-finora th,
    .table-finora td,
    .table-finora tr {
        display: block;
    }

    .table-finora thead {
        display: none;
    }

    .table-finora tbody {
        padding: 10px;
    }

    .table-finora .log-row {
        margin-bottom: 10px;
        border: 1px solid var(--border-soft);
        border-radius: var(--radius-lg);
        background: var(--panel-2);
        overflow: hidden;
    }

    .table-finora tbody td {
        border: 0;
        display: flex;
        justify-content: space-between;
        gap: 14px;
        padding: 9px 11px;
        text-align: right;
    }

    .table-finora tbody td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--text-muted);
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .06em;
        text-align: left;
    }
}
