:root {
    --app-radius: 14px;
    --app-border: var(--bs-border-color);
    --bs-primary: #2563eb;
    --bs-primary-rgb: 37, 99, 235;
    --bs-link-color: #1d4ed8;
    --bs-link-hover-color: #1e40af;
}

body {
    background: var(--bs-body-bg);
}

body.auth-page {
    background: #f3f6fb;
}

.app-layout {
    min-height: 100vh;
    display: flex;
    background: #f5f7fb;
}

.app-sidebar {
    width: 280px;
    background: #123f7a;
    color: #dbeafe;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1030;
    box-shadow: none;
}

.app-sidebar::before {
    display: none;
}

.app-sidebar-brand {
    padding: 1.1rem 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.app-brand-title {
    font-weight: 700;
    color: #f8fafc;
    font-size: 0.98rem;
    line-height: 1.15;
}

.app-brand-subtitle {
    font-size: 0.75rem;
    opacity: 0.86;
}

.app-sidebar-user {
    margin: 0.9rem 0.8rem 0.75rem;
    padding: 0.75rem 0.8rem;
    border: 1px solid rgba(191, 219, 254, 0.2);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.app-user-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.app-user-badge {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: #0f172a;
    background: #86efac;
    box-shadow: none;
}

.app-user-name {
    font-weight: 600;
    color: #f8fafc;
    line-height: 1.1;
}

.app-user-role {
    font-size: 0.74rem;
    opacity: 0.8;
}

.app-user-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.app-user-action {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.32);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    box-shadow: none;
    transition: background 0.15s ease, border-color 0.15s ease;
    line-height: 1;
}

.app-user-action:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    color: #ffffff;
}

.app-user-action svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

.app-user-action--danger {
    background: rgba(248, 113, 113, 0.18);
    border-color: rgba(252, 165, 165, 0.45);
}

.app-user-action--danger:hover {
    background: rgba(248, 113, 113, 0.26);
    border-color: rgba(252, 165, 165, 0.65);
}

.app-sidebar-nav {
    padding: 0.35rem 0.8rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.app-sidebar-nav--bottom {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    padding-top: 0.75rem;
}

.app-nav-caption {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: rgba(219, 234, 254, 0.78);
    padding: 0.2rem 0.35rem 0.35rem;
}

.app-nav-link {
    color: #dbeafe;
    text-decoration: none;
    font-size: 0.92rem;
    border-radius: 12px;
    padding: 0.55rem 0.75rem;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-weight: 600;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.app-nav-link-icon {
    width: 0.88rem;
    height: 0.88rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    color: #ffffff;
    opacity: 0.9;
}

.app-nav-link-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.app-nav-link-label {
    flex: 1;
    min-width: 0;
}

.app-nav-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(191, 219, 254, 0.35);
}

.app-nav-link.active {
    color: #ffffff;
    background: rgba(37, 99, 235, 0.45);
    border-color: rgba(147, 197, 253, 0.55);
    box-shadow: none;
}

.app-sidebar-footer {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.app-main {
    flex: 1;
    min-width: 0;
    padding: 1rem 1.15rem 1.4rem;
    margin-left: 280px;
    width: calc(100% - 280px);
}

.app-shell {
    max-width: 1320px;
}

.app-page-head {
    border: 1px solid #d9e4f4;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: none;
    padding: 0.8rem 0.95rem;
}

.app-header {
    border-bottom: 1px solid var(--app-border);
    background: linear-gradient(180deg, color-mix(in srgb, #2563eb 10%, var(--bs-body-bg) 90%) 0%, var(--bs-body-bg) 100%);
    backdrop-filter: blur(4px);
}

.app-title {
    letter-spacing: 0.2px;
}

.app-card {
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    box-shadow: none;
    background: #ffffff;
    overflow: hidden;
}

.app-card .card-body {
    padding: 1rem 1.05rem;
}

.app-card .card-header {
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.app-card .card-footer {
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

.app-panel-title {
    font-weight: 700;
    margin-bottom: 0.8rem;
}

.device-kpi {
    border: 1px solid #d6dbe5;
    border-radius: 10px;
    background: #ffffff;
    padding: 0.65rem 0.8rem;
}

.device-kpi--primary {
    background: #f8fafc;
    box-shadow: none;
}

.device-kpi-label {
    font-size: 0.72rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.device-kpi-value {
    margin-top: 0.15rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
}

.device-status-row {
    border: 1px solid #cfe8da;
    background: #e9f8ef;
    border-radius: 10px;
    padding: 0.85rem 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    font-weight: 700;
    color: #14532d;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    display: inline-block;
}

.status-dot.online {
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}

.status-dot.offline {
    background: #ef4444;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15);
}

.device-info-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
}

.device-info-item {
    border: 1px solid #dce1ea;
    border-radius: 10px;
    background: #ffffff;
    padding: 0.65rem 0.7rem;
}

.device-info-key {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
}

.device-info-value {
    margin-top: 0.18rem;
    font-weight: 700;
}

.page-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.page-subtitle {
    font-size: 0.88rem;
    color: #64748b;
}

.device-head-meta {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 0.15rem;
}

.device-head-centered {
    text-align: center;
}

.device-head-title {
    margin-bottom: 0.2rem;
}

.device-head-actions {
    margin-top: 0.6rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.device-info-card .device-kpi-label {
    font-size: 0.66rem;
}

.device-info-card .device-kpi-value {
    font-size: 1.05rem;
    font-weight: 600;
}

.device-detail-page .app-card .app-panel-title,
.device-detail-page .device-section-title {
    font-size: 0.86rem;
}

.device-detail-page .app-card .text-body-secondary,
.device-detail-page .app-card small {
    font-size: 0.76rem;
}

.device-detail-page .app-card .device-kpi-label {
    font-size: 0.64rem;
}

.device-detail-page .app-card .device-kpi-value {
    font-size: 1.12rem;
}

.device-section-title {
    font-weight: 700;
    font-size: 0.92rem;
    color: #1e3a8a;
    margin-bottom: 0.75rem;
}

.form-label {
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.35rem;
}

.form-control,
.form-select {
    border-radius: 10px;
    border-color: #d0d9e8;
    box-shadow: none;
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.18);
}

.form-check-input {
    border-color: #94a3b8;
}

.btn {
    border-radius: 8px;
    font-weight: 600;
}

.btn-sm,
.btn-group-sm > .btn {
    border-radius: 9px;
}

.table {
    --bs-table-striped-bg: #f8fbff;
}

.table > thead > tr > th {
    font-size: 0.73rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #475569;
    border-bottom-width: 1px;
    border-color: #dbe4f0;
    background: #f8fafc;
}

.table > tbody > tr > td {
    border-color: #e5edf7;
}

.table-responsive {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    background: #ffffff;
}

.alert {
    border-radius: 10px;
    border-width: 1px;
}

.alert-success {
    border-color: #86efac;
}

.alert-warning {
    border-color: #fcd34d;
}

.alert-danger {
    border-color: #fca5a5;
}

.auth-shell {
    max-width: 560px;
}

.auth-card {
    border-radius: 14px;
    border-color: #d8e4f6;
    box-shadow: none;
}

.auth-card .card-body {
    padding: 1.35rem 1.4rem;
}

.auth-card h1 {
    font-weight: 700;
    color: #1e3a8a;
}

.auth-card .btn-primary {
    width: 100%;
}

.online-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    border: 1px solid #86efac;
    background: #dcfce7;
    color: #166534;
    font-weight: 700;
}

.online-pill--offline {
    border-color: #fca5a5;
    background: #fee2e2;
    color: #991b1b;
}

.chart-container {
    position: relative;
    min-height: 320px;
}

.btn-primary {
    --bs-btn-bg: #2563eb;
    --bs-btn-border-color: #2563eb;
    --bs-btn-hover-bg: #1d4ed8;
    --bs-btn-hover-border-color: #1d4ed8;
    --bs-btn-active-bg: #1e40af;
    --bs-btn-active-border-color: #1e40af;
}

.btn-outline-primary {
    --bs-btn-color: #1d4ed8;
    --bs-btn-border-color: #2563eb;
    --bs-btn-hover-bg: #2563eb;
    --bs-btn-hover-border-color: #2563eb;
    --bs-btn-active-bg: #1d4ed8;
    --bs-btn-active-border-color: #1d4ed8;
}

.device-tile {
    border: 1px solid var(--app-border);
    border-radius: 12px;
    background: var(--bs-light-bg-subtle);
    padding: 0.85rem 0.9rem;
    height: 100%;
    transition: border-color 0.15s ease;
}

.device-tile:hover {
    border-color: #2563eb;
}

.device-title {
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.45rem;
}

.device-line {
    line-height: 1.25;
    margin-bottom: 0.15rem;
}

.device-line:last-child {
    margin-bottom: 0;
}

.section-heading {
    font-weight: 700;
    margin-bottom: 0.8rem;
    color: #1e3a8a;
}

.dashboard-group {
    border: 1px solid #cfd5de;
    background: #e9ecef;
    border-radius: 3px;
    padding: 12px 14px;
}

.dashboard-group-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0b4f8a;
    margin-bottom: 10px;
}

.dashboard-device-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 16px;
}

.dashboard-device-card {
    width: 250px;
    min-height: 84px;
    border: 1px solid #b8bcc4;
    background: #e6e6e6;
    color: #0f172a;
    padding: 6px 8px 6px 30px;
    position: relative;
    display: block;
}

.dashboard-device-card::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 4px;
    bottom: 4px;
    width: 18px;
    background: #7d7d7d;
}

.dashboard-device-card.dashboard-device-card--online::before {
    background: #22c55e;
}

.dashboard-device-card.dashboard-device-card--offline::before {
    background: #ef4444;
}

.dashboard-device-card.dashboard-device-card--alarm {
    border-color: #ef4444;
    background: #fee2e2;
}

.dashboard-device-card.dashboard-device-card--alarm::before {
    background: #ef4444;
}

.dashboard-device-card:hover {
    border-color: #9aa3af;
    color: #0f172a;
}

.dashboard-device-name {
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 3px;
}

.dashboard-device-line {
    font-size: 0.82rem;
    line-height: 1.18;
}

.table > :not(caption) > * > * {
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
}

@media (max-width: 1199px) {
    .device-info-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 991px) {
    .app-layout {
        display: block;
    }

    .app-sidebar {
        position: relative;
        width: 100%;
        height: auto;
        overflow: visible;
    }

    .app-main {
        padding: 0.9rem 0.8rem 1.1rem;
        margin-left: 0;
        width: auto;
    }

    .app-page-head {
        padding: 0.75rem 0.8rem;
    }

    .auth-shell {
        max-width: 100%;
    }

    .dashboard-device-grid {
        gap: 10px;
    }

    .dashboard-device-card {
        width: calc(50% - 5px);
        min-width: 240px;
    }

    .chart-container {
        min-height: 280px;
    }

    .device-head-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
}

@media (max-width: 767px) {
    .app-main {
        padding: 0.75rem 0.65rem 1rem;
    }

    .app-card .card-body,
    .auth-card .card-body {
        padding: 0.9rem;
    }

    .app-page-head {
        padding: 0.65rem 0.7rem;
    }

    .dashboard-device-card {
        width: 100%;
        min-width: 0;
    }

    .table > thead > tr > th,
    .table > tbody > tr > td {
        font-size: 0.78rem;
        white-space: nowrap;
    }

    .device-detail-page .btn-group[aria-label="Zeitraum"] {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.35rem;
    }

    .device-detail-page .btn-group[aria-label="Zeitraum"] > .btn {
        border-radius: 8px;
    }
}

@media (max-width: 575px) {
    .device-info-grid {
        grid-template-columns: 1fr;
    }

    .device-kpi-value {
        font-size: 1.25rem;
    }

    .device-detail-page .app-card .device-kpi-value {
        font-size: 1rem;
    }

    .chart-container {
        min-height: 230px;
    }
}
