* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    direction: rtl;
    font-family: Tahoma, Arial, sans-serif;
    background: #f4f8f6;
    color: #17251f;
    line-height: 1.7;
}

button,
input,
textarea,
select {
    font-family: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.main-header {
    max-width: 1100px;
    margin: 28px auto 18px;
    padding: 25px 20px;
    text-align: center;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 8px 25px rgba(28, 65, 48, .07);
}

.main-header h1 {
    margin: 0 0 5px;
    font-size: 32px;
    color: #173f2c;
}

.main-header p {
    margin: 0;
    color: #718078;
    font-size: 15px;
}

.hall-section,
.beds-section {
    max-width: 1100px;
    margin: 0 auto 18px;
    padding: 22px;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 8px 25px rgba(28, 65, 48, .06);
}

.hall-section h2,
.beds-section h2 {
    margin: 0 0 18px;
    text-align: center;
    color: #173f2c;
}

.hall-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.hall-button {
    border: 0;
    padding: 11px 24px;
    min-width: 105px;
    border-radius: 11px;
    background: #e6eee9;
    color: #315047;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: .2s;
}

.hall-button:hover {
    transform: translateY(-1px);
    background: #d9e7df;
}

.hall-button.active-hall {
    background: #218451;
    color: #ffffff;
    box-shadow: 0 6px 16px rgba(33, 132, 81, .22);
}

.beds-container {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.bed-card {
    min-width: 0;
    padding: 18px;
    background: #ffffff;
    border: 1px solid #e5ece8;
    border-radius: 16px;
    box-shadow: 0 5px 16px rgba(28, 65, 48, .05);
    text-align: right;
}

.bed-card h3 {
    margin: 0 0 13px;
    text-align: center;
    color: #173f2c;
    font-size: 19px;
}

.bed-card p {
    margin: 8px 0;
    color: #58665f;
}

.ec-value,
.ph-value {
    display: inline-block;
    min-width: 34px;
    padding: 1px 7px;
    border-radius: 7px;
    font-weight: bold;
    text-align: center;
}

.status-good {
    color: #147a45 !important;
    background: #e7f7ed;
}

.status-warning {
    color: #a36500 !important;
    background: #fff4d9;
}

.status-danger {
    color: #b42318 !important;
    background: #ffe8e7;
}

.status-empty {
    color: #69756f !important;
    background: #edf1ef;
}

.last-measurement {
    font-size: 12px;
    color: #78857f !important;
}

.date-value {
    display: block;
    margin-top: 3px;
    direction: ltr;
    text-align: right;
    word-break: break-word;
}

.bed-button {
    width: 100%;
    margin-top: 10px;
    padding: 11px;
    border: 0;
    border-radius: 10px;
    background: #218451;
    color: white;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: .2s;
}

.bed-button:hover {
    background: #176b43;
    transform: translateY(-1px);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(12, 28, 21, .55);
}

.modal-content {
    position: relative;
    width: min(900px, 100%);
    max-height: 94vh;
    overflow-y: auto;
    padding: 25px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, .25);
}

.close-button {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: #eef2f0;
    color: #26362f;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
}

.modal-content h2 {
    margin: 0 45px 22px 0;
    color: #173f2c;
    text-align: center;
}

#measurementForm {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-group {
    min-width: 0;
}

.form-group:last-of-type {
    grid-column: 1 / -1;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: #3e5148;
    font-weight: bold;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid #d7e2dc;
    border-radius: 10px;
    outline: none;
    background: #ffffff;
    color: #18261f;
    font-size: 15px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: #218451;
    box-shadow: 0 0 0 3px rgba(33, 132, 81, .1);
}

.form-group textarea {
    resize: vertical;
    min-height: 95px;
}

.save-button {
    grid-column: 1 / -1;
    width: 100%;
    padding: 13px;
    border: 0;
    border-radius: 11px;
    background: #218451;
    color: #ffffff;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}

.save-button:hover {
    background: #176b43;
}

.chart-section,
.history-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e8efeb;
}

.chart-section h3,
.history-section h3 {
    margin: 0 0 13px;
    color: #23453a;
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 270px;
    padding: 10px;
    border: 1px solid #e7eeea;
    border-radius: 12px;
    background: #ffffff;
}

.chart-wrapper canvas {
    max-width: 100%;
}

.history-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.history-table {
    width: 100%;
    min-width: 650px;
    border-collapse: collapse;
    background: #ffffff;
}

.history-table th,
.history-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #e8eeeb;
    text-align: center;
    font-size: 13px;
}

.history-table th {
    background: #f3f7f5;
    color: #3f534a;
}

.history-table button {
    border: 0;
    border-radius: 7px;
    padding: 6px 9px;
    margin: 2px;
    cursor: pointer;
    font-weight: bold;
}

.history-table button:first-child {
    background: #e8f5ee;
    color: #176b43;
}

.history-table button:last-child {
    background: #fee2e2;
    color: #b42318;
}

@media (max-width: 900px) {

    .beds-container {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

    .main-header,
    .hall-section,
    .beds-section {
        margin-left: 12px;
        margin-right: 12px;
    }
}

@media (max-width: 600px) {

    .main-header {
        margin-top: 12px;
        padding: 20px 14px;
    }

    .main-header h1 {
        font-size: 26px;
    }

    .hall-section,
    .beds-section {
        padding: 15px;
        border-radius: 14px;
    }

    .beds-container {
        grid-template-columns: 1fr;
    }

    #measurementForm {
        grid-template-columns: 1fr;
    }

    .form-group:last-of-type,
    .save-button {
        grid-column: auto;
    }

    .modal {
        padding: 8px;
        align-items: flex-start;
    }

    .modal-content {
        max-height: 96vh;
        margin-top: 5px;
        padding: 20px 14px;
        border-radius: 16px;
    }

    .modal-content h2 {
        font-size: 20px;
        margin-right: 35px;
    }

    .chart-wrapper {
        height: 230px;
    }
}