* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #f4f6f8;
    color: #222;
    padding: 20px;
}

.container {
    max-width: 1500px;
    margin: auto;
}

.header {
    background: #fff;
    border-radius: 18px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,.06);
}

.header h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.header p {
    color: #777;
    font-size: 15px;
}

.card {
    background: #fff;
    border-radius: 18px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,.06);
}

.card-title {
    font-size: 21px;
    font-weight: bold;
    margin-bottom: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 14px;
}

input,
select {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    background: #fff;
    outline: none;
}

input:focus,
select:focus {
    border-color: #555;
}

.meter-note {
    margin-top: 7px;
    color: #888;
    font-size: 12px;
}

.button-row {
    margin-top: 22px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

button {
    border: none;
    border-radius: 10px;
    padding: 13px 22px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
}

.btn-primary {
    background: #111;
    color: white;
}

.btn-secondary {
    background: #e9ecef;
    color: #222;
}

.btn-danger {
    background: #dc3545;
    color: white;
    padding: 8px 12px;
    font-size: 13px;
}

.calculation {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-top: 20px;
}

.result-box {
    background: #f7f8fa;
    border-radius: 14px;
    padding: 18px;
}

.result-box .label {
    color: #777;
    font-size: 13px;
    margin-bottom: 8px;
}

.result-box .value {
    font-size: 21px;
    font-weight: bold;
}

.highlight {
    background: #111;
    color: white;
}

.highlight .label {
    color: #bbb;
}

.green-box {
    background: #eaf8ef;
}

.green-box .label {
    color: #38744c;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 1600px;
    border-collapse: collapse;
}

th,
td {
    padding: 13px 10px;
    border-bottom: 1px solid #eee;
    text-align: center;
    font-size: 13px;
    white-space: nowrap;
}

th {
    background: #f7f8fa;
    font-weight: bold;
}

.summary {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
}

.summary-box {
    padding: 20px;
    border-radius: 14px;
    background: #f7f8fa;
}

.summary-box h3 {
    font-size: 13px;
    color: #777;
    margin-bottom: 8px;
}

.summary-box strong {
    font-size: 21px;
}

.payment-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.payment-box {
    padding: 20px;
    border-radius: 14px;
    background: #f7f8fa;
}

.payment-box label {
    display: block;
    font-size: 13px;
    color: #777;
    margin-bottom: 8px;
    font-weight: bold;
}

.payment-box input {
    font-size: 18px;
    font-weight: bold;
}

.payment-result {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.empty {
    text-align: center;
    color: #888;
    padding: 30px;
}

.note {
    background: #fff8e1;
    border: 1px solid #ffe08a;
    padding: 14px;
    border-radius: 10px;
    margin-top: 15px;
    color: #795600;
    font-size: 14px;
    line-height: 1.7;
}

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

    .calculation {
        grid-template-columns: repeat(2, 1fr);
    }

    .summary {
        grid-template-columns: repeat(2, 1fr);
    }

    .payment-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .header,
    .card {
        padding: 18px;
    }

    .calculation,
    .summary,
    .payment-result {
        grid-template-columns: 1fr;
    }

    button {
        width: 100%;
    }
}

/* ===== Login / layout additions ===== */

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

.user-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.role-tag {
    background: #111;
    color: #fff;
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: bold;
}

.role-tag.worker {
    background: #e9ecef;
    color: #222;
}

.btn-small {
    padding: 8px 12px;
    font-size: 13px;
}

.btn-edit {
    background: #e9ecef;
    color: #222;
    padding: 8px 12px;
    font-size: 13px;
    margin-right: 6px;
}

.locked {
    background: #f1f3f5;
    color: #555;
}

.filters {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    align-items: end;
    margin-bottom: 20px;
}

.warn {
    color: #c77700;
    font-weight: bold;
    cursor: help;
}

tr.chain-broken td {
    background: #fff8e1;
}

table.compact {
    min-width: 900px;
}

table.compact input {
    padding: 8px 10px;
    font-size: 14px;
    max-width: 160px;
}

tr.total-row td {
    font-weight: bold;
    background: #f7f8fa;
}

.users-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.user-card {
    background: #f7f8fa;
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-card h4 {
    font-size: 15px;
}

.user-card label {
    font-size: 12px;
    color: #777;
    font-weight: bold;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}

/* Modal */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 30px 15px;
    overflow-y: auto;
    z-index: 50;
}

.modal-backdrop.open {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 18px;
    padding: 25px;
    width: 100%;
    max-width: 900px;
}

/* Login page */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    width: 100%;
    max-width: 420px;
}

.auth-card .form-group {
    margin-bottom: 16px;
}

.auth-card button {
    width: 100%;
}

.error-box {
    background: #fdecee;
    border: 1px solid #f5c2c7;
    color: #842029;
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 14px;
    display: none;
}

.error-box.show {
    display: block;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #111;
    color: #fff;
    padding: 13px 20px;
    border-radius: 10px;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
    z-index: 100;
    max-width: 90vw;
}

.toast.show {
    opacity: 1;
}

.toast.error {
    background: #dc3545;
}

button:disabled {
    opacity: .6;
    cursor: wait;
}

@media (max-width: 1000px) {
    .filters,
    .users-grid,
    .settings-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .filters,
    .users-grid,
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Withdrawals ===== */

.summary.summary-4 {
    grid-template-columns: repeat(4, 1fr);
}

.summary-box.highlight {
    background: #111;
    color: #fff;
}

.summary-box.highlight h3 {
    color: #bbb;
}

.payment-result.wallet-grid {
    grid-template-columns: repeat(3, 1fr);
    margin-top: 0;
}

table.compact td.note-cell {
    white-space: normal;
    max-width: 320px;
}

@media (max-width: 1000px) {
    .summary.summary-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .summary.summary-4,
    .payment-result.wallet-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Оплата по клиентам ===== */

.form-group.pay-group {
    grid-column: 1 / -1;
}

.pay-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
}

.pay-item span {
    display: block;
    font-size: 12px;
    color: #777;
    margin-bottom: 5px;
}

.pay-item input.missing {
    border-color: #dc3545;
}

.pay-total {
    margin-top: 12px;
    padding: 14px 16px;
    background: #111;
    color: #fff;
    border-radius: 10px;
    font-size: 15px;
}

.pay-total strong {
    font-size: 20px;
    margin-left: 6px;
}

.pay-breakdown {
    display: block;
    font-size: 11px;
    color: #888;
    margin-top: 3px;
}

/* ===== Касса ===== */

.stat-grid {
    display: grid;
    gap: 15px;
}

.stat-grid.stat-5 { grid-template-columns: repeat(5, 1fr); }
.stat-grid.stat-4 { grid-template-columns: repeat(4, 1fr); }

.sub-title {
    font-size: 15px;
    font-weight: bold;
    margin-bottom: 10px;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.two-col table.compact {
    min-width: 0;
}

table.drawer-table {
    min-width: 1200px;
}

table.drawer-table input {
    max-width: 130px;
}

.cell-actions {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.muted {
    color: #999;
    font-size: 12px;
}

@media (max-width: 1000px) {
    .stat-grid.stat-5,
    .stat-grid.stat-4 { grid-template-columns: repeat(2, 1fr); }
    .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .stat-grid.stat-5,
    .stat-grid.stat-4 { grid-template-columns: 1fr; }
}

/* ===== Тест аппарата ===== */

.test-toggle {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #f7f8fa;
    border: 1px dashed #bbb;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 20px;
    cursor: pointer;
    font-size: 14px;
}

.test-toggle input {
    width: 20px;
    height: 20px;
    margin-top: 1px;
    flex: none;
}

.test-toggle small {
    display: block;
    color: #777;
    margin-top: 4px;
    font-size: 12px;
}

.test-mode .test-toggle {
    background: #e8f0fe;
    border-color: #4a6fd8;
}

.test-mode .test-hide {
    display: none !important;
}

tr.test-row td {
    background: #eef3ff;
    color: #555;
}

.test-badge {
    display: inline-block;
    background: #4a6fd8;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    border-radius: 6px;
    padding: 3px 8px;
}

/* ===== Навигация по месяцам ===== */

.hist-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.hist-head .card-title {
    margin-bottom: 0;
}

.month-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.month-nav button {
    padding: 10px 14px;
}

.month-label {
    min-width: 160px;
    text-align: center;
    font-weight: bold;
    font-size: 16px;
    background: #f7f8fa;
    border-radius: 10px;
    padding: 10px 14px;
}

.month-nav input[type="month"] {
    width: auto;
    padding: 9px 10px;
    font-size: 14px;
}

.hist-info {
    color: #777;
    font-size: 13px;
    margin-bottom: 14px;
}

.title-month {
    font-size: 14px;
    color: #777;
    font-weight: normal;
}

.filters.filters-month {
    grid-template-columns: 1fr 2fr;
    margin-bottom: 8px;
}

/* ===== Мобильная версия ===== */

@media (max-width: 1000px) {
    .filters.filters-month {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {

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

    .month-nav {
        display: grid;
        grid-template-columns: auto 1fr auto;
        gap: 8px;
    }

    .month-nav .nav-word {
        display: none;
    }

    .month-label {
        min-width: 0;
    }

    .month-nav input[type="month"],
    .month-nav #monthNow {
        grid-column: 1 / -1;
        width: 100%;
    }

    /* кнопки «‹ ›» не растягиваем на всю ширину */
    .month-nav button#monthPrev,
    .month-nav button#monthNext {
        width: auto;
    }

    .topbar .user-badge {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .topbar .user-badge button {
        width: auto;
    }

    .header h1 {
        font-size: 22px;
    }

    .card-title {
        font-size: 18px;
    }

    .pay-list {
        grid-template-columns: 1fr 1fr;
    }

    .cell-actions {
        flex-direction: column;
    }

    .modal {
        padding: 18px;
    }

    .modal-backdrop {
        padding: 10px;
    }

    .test-toggle {
        font-size: 13px;
    }
}
