body {
    font-family: Arial, sans-serif;
    margin: 30px;
    color: #17212b;
}

body.login-page {
    margin: 0;
    background: #f4f7f9;
}

a {
    color: #0f5fa8;
    text-decoration: none;
}

table {
    border-collapse: collapse;
    width: 100%;
    margin-top: 18px;
}

th,
td {
    border: 1px solid #ccd5dd;
    padding: 8px;
    text-align: left;
}

th {
    background: #1e3a5f;
    color: white;
}

label {
    font-weight: bold;
}

.login-card {
    max-width: 360px;
    margin: 12vh auto;
    padding: 24px;
    background: white;
    border: 1px solid #d8e0e7;
    border-radius: 8px;
}

.login-card label {
    display: block;
    margin-top: 14px;
}

.login-card input {
    box-sizing: border-box;
    width: 100%;
    padding: 10px;
    margin-top: 6px;
    border: 1px solid #b8c4ce;
    border-radius: 4px;
}

.login-card button {
    width: 100%;
    margin-top: 20px;
    padding: 10px;
    border: 0;
    border-radius: 4px;
    background: #1e3a5f;
    color: white;
    font-weight: bold;
    cursor: pointer;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.logout-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 13px;
    border-radius: 4px;
    background: #1e3a5f;
    color: white;
    font-weight: bold;
}

.logout-button:hover {
    background: #162b47;
}

.notice,
.error {
    padding: 10px 12px;
    border-radius: 4px;
}

.notice {
    margin: 14px 0;
}

.notice.ok {
    background: #e8f6ed;
    border: 1px solid #b9dfc5;
    color: #1d5c2d;
}

.notice.error,
.error {
    background: #ffe8e8;
    border: 1px solid #ffb8b8;
    color: #7a1c1c;
}

.admin-panel {
    margin: 18px 0;
    padding: 14px;
    border: 1px solid #ccd5dd;
    border-radius: 6px;
    background: #f8fafc;
}

.admin-panel h2 {
    margin: 0 0 12px;
    font-size: 18px;
}

.admin-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
    gap: 8px;
    align-items: end;
    margin-bottom: 18px;
}

.admin-form label {
    font-size: 13px;
}

.admin-form input,
.admin-form select,
.edit-form input,
.meter-edit-form input,
.meter-edit-form select {
    box-sizing: border-box;
    width: 100%;
    padding: 7px;
    border: 1px solid #b8c4ce;
    border-radius: 4px;
    background: white;
}

.admin-form input,
.admin-form select {
    padding: 8px;
}

.admin-form button,
.edit-form button,
.meter-edit-form button {
    border: 0;
    border-radius: 4px;
    background: #1e3a5f;
    color: white;
    font-weight: bold;
    cursor: pointer;
}

.admin-form button {
    padding: 9px 12px;
}

.edit-form button,
.meter-edit-form button {
    padding: 8px 10px;
}

.checkbox-row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding-bottom: 8px;
}

.checkbox-row input {
    width: auto;
}

.assignments {
    margin-top: 8px;
    font-size: 14px;
}

.edit-form {
    display: grid;
    grid-template-columns: 110px 1fr 1fr auto auto;
    gap: 8px;
    align-items: center;
    margin: 6px 0;
}

.meter-edit-form {
    display: grid;
    grid-template-columns: 150px 75px 1fr 115px 95px 95px 75px 75px auto auto;
    gap: 8px;
    align-items: center;
    margin: 6px 0;
}

.danger-button {
    background: #b42318 !important;
    color: white;
}

.danger-button:hover {
    background: #8f1c13 !important;
}

.admin-section {
    margin-top: 22px;
}

.user-meter-list {
    margin-top: 18px;
}

.user-meter-list table {
    margin-top: 10px;
}

.value-col {
    width: 16%;
    white-space: nowrap;
}

.panel {
    border: 1px solid #ccd5dd;
    padding: 15px;
    margin: 20px 0;
    border-radius: 6px;
}

.menu {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.back-button,
.action-button,
.pagination a {
    background: #1e3a5f;
    color: white;
    font-weight: bold;
}

.back-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 13px;
    border-radius: 4px;
}

.back-button:hover {
    background: #162b47;
}

.chart-title {
    font-size: 30px;
    margin: 12px 0 8px;
}

.chart-note {
    margin: 0 0 10px;
    color: #53616e;
    font-size: 14px;
}

.chart-controls,
.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.chart-controls {
    margin: 12px 0 14px;
}

.controls {
    margin: 12px 0 18px;
}

.range-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.range-buttons a {
    box-sizing: border-box;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid #b8c4ce;
    border-radius: 4px;
    background: #f4f7f9;
    color: #0f5fa8;
    font: bold 14px Arial, sans-serif;
    line-height: 18px;
}

.chart-controls select {
    box-sizing: border-box;
    min-height: 36px;
    border: 1px solid #b8c4ce;
    border-radius: 4px;
    background: white;
    color: #0f5fa8;
    font: bold 14px Arial, sans-serif;
    line-height: 18px;
}

.range-buttons a.active {
    background: #1e3a5f;
    color: white;
    border-color: #1e3a5f;
}

.date-range-form {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.date-range-form input,
.chart-controls select,
.chart-controls button,
.chart-controls input {
    padding: 7px;
    margin-left: 6px;
}

.date-range-form button {
    border: 1px solid #1e3a5f;
    border-radius: 4px;
    background: #1e3a5f;
    color: white;
    font-weight: bold;
    cursor: pointer;
}

.action-button {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid #1e3a5f;
    border-radius: 4px;
    font: bold 14px Arial, sans-serif;
    line-height: 18px;
    cursor: pointer;
}

.table-action-button {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 10px;
    border-radius: 4px;
    background: #1e3a5f;
    color: white;
    font-weight: bold;
    line-height: 18px;
}

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 7px;
}

.meter-name {
    font-weight: bold;
}

.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: bold;
    white-space: nowrap;
}

.status-age {
    white-space: nowrap;
}

.status-ok {
    background: #e8f6ed;
    color: #1d5c2d;
}

.status-warning {
    background: #b42318;
    color: white;
}

.table-action-button:hover {
    background: #162b47;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 18px 0;
}

.pagination a,
.pagination span {
    padding: 8px 12px;
    border-radius: 4px;
}

.pagination span {
    background: #f4f7f9;
    border: 1px solid #ccd5dd;
}

.empty {
    margin-top: 18px;
    padding: 12px;
    border: 1px solid #ccd5dd;
    border-radius: 4px;
    background: #f8fafc;
}

.chart-wrap {
    position: relative;
    width: 100%;
    height: min(62vh, 620px);
    min-height: 360px;
}

.chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    max-height: none;
}

.meter-table th,
.meter-table td {
    white-space: nowrap;
}

.table-wrap {
    width: 100%;
}

@media (max-width: 700px) {
    body {
        margin: 12px;
        font-size: 15px;
    }

    h1 {
        font-size: 24px;
        margin: 12px 0;
    }

    h2 {
        font-size: 20px;
    }

    .topbar {
        align-items: flex-start;
    }

    .topbar h1 {
        margin-top: 0;
    }

    .menu,
    .chart-controls,
    .controls,
    .date-range-form {
        align-items: stretch;
        flex-direction: column;
    }

    .range-buttons {
        display: grid;
        grid-template-columns: 1fr;
    }

    .range-buttons a,
    .action-button,
    .table-action-button,
    .back-button,
    .pagination a,
    .pagination span {
        box-sizing: border-box;
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .date-range-form input,
    .chart-controls select,
    .chart-controls button,
    .chart-controls input {
        box-sizing: border-box;
        width: 100%;
        margin-left: 0;
    }

    .panel {
        padding: 12px;
        margin: 14px 0;
    }

    .chart-title {
        font-size: 22px;
    }

    .chart-note {
        font-size: 13px;
    }

    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-wrap table {
        min-width: 640px;
    }

    .user-meter-list .table-wrap table {
        min-width: 820px;
    }

    .chart-wrap {
        height: 58vh;
        min-height: 300px;
    }
}
