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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

/* Контейнер для основного приложения (широкий и высокий) */
.app-container {
    max-width: 90%;
    width: 90%;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
    height: 90vh;
    display: flex;
    flex-direction: column;
}

/* Контейнер для логина (не растянут) */
.login-container {
    max-width: 400px;
    width: 100%;
    margin: 100px auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

.login-card {
    padding: 40px;
    text-align: center;
}

.login-card h2 {
    margin-bottom: 20px;
    color: #333;
}

.login-card input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 30px;
    font-size: 16px;
}

.login-card button {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
}

/* Хедер не сжимается */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    flex-shrink: 0;
}

/* Контейнер графика — фиксированная высота 35% от родителя */
.chart-container {
    width: 100%;
    height: 35%;
    min-height: 300px;
    padding: 20px;
    flex-shrink: 0;
}

#glucoseChart {
    width: 100%;
    height: 100%;
}

/* Таблица занимает оставшееся пространство и скроллится */
.table-scroll-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    margin: 20px;
    background: white;
}

#records-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

#records-table thead {
    position: sticky;
    top: 0;
    background: #f5f5f5;
    z-index: 10;
}

#records-table th,
#records-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

/* Кнопки и поля ввода — скруглённые, с тенями */
button, .btn-primary, .btn-secondary, .btn-logout, .btn-import,
.user-form button, .restore-btn, .edit-user, .delete-user {
    border-radius: 30px !important;
    padding: 8px 20px;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border: none;
    cursor: pointer;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

input, select, textarea {
    border-radius: 30px !important;
    padding: 10px 15px;
    border: 1px solid #ddd;
    transition: 0.2s;
    background: white;
}

input:focus, select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.2);
}

/* Модальные окна - абсолютное центрирование (работает всегда) */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 1000;
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.modal-content.large {
    max-width: 900px;
}

.close {
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.close:hover {
    color: #666;
}

/* Адаптивность */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    .app-container {
        max-width: 95%;
        width: 95%;
        height: 95vh;
    }
    .login-container {
        margin: 50px auto;
    }
    .header {
        flex-direction: column;
        text-align: center;
        padding: 15px;
    }
    .header-buttons {
        width: 100%;
        justify-content: center;
    }
    .chart-container {
        height: 30%;
        min-height: 250px;
        padding: 10px;
    }
    #records-table th,
    #records-table td {
        padding: 8px;
        font-size: 12px;
    }
    button, .btn-primary, .btn-secondary, .btn-logout, .btn-import {
        padding: 6px 12px;
        font-size: 12px;
    }
    .modal-content {
        margin: 20px;
        padding: 20px;
        max-width: 90%;
    }
}

/* Для планшетов */
@media (min-width: 769px) and (max-width: 1024px) {
    .app-container {
        max-width: 85%;
        width: 85%;
    }
    .chart-container {
        height: 30%;
    }
}

/* Остальные стили (тосты, статусы, треугольники, панель управления) */
.toast-container { position:fixed; top:20px; right:20px; z-index:9999; }
.toast { min-width:250px; padding:15px 20px; margin-bottom:10px; border-radius:8px; color:white; animation:slideIn 0.3s ease; box-shadow:0 4px 12px rgba(0,0,0,0.15); }
.toast.success { background:#4caf50; }
.toast.error { background:#f44336; }
.toast.info { background:#2196f3; }
.toast.warning { background:#ff9800; }
@keyframes slideIn { from { transform:translateX(100%); opacity:0; } to { transform:translateX(0); opacity:1; } }
@keyframes slideOut { from { transform:translateX(0); opacity:1; } to { transform:translateX(100%); opacity:0; } }

.user-info { font-size:18px; display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.role-badge { background:rgba(255,255,255,0.3); padding:4px 12px; border-radius:20px; font-size:12px; }
.header-buttons { display:flex; gap:10px; flex-wrap:wrap; }

.status-up, .status-down { display:inline-flex; align-items:center; gap:5px; color:#f44336; }
.status-normal { color:#4caf50; display:inline-flex; align-items:center; gap:5px; }
.triangle-up { width:0; height:0; border-left:8px solid transparent; border-right:8px solid transparent; border-bottom:14px solid #f44336; display:inline-block; }
.triangle-down { width:0; height:0; border-left:8px solid transparent; border-right:8px solid transparent; border-top:14px solid #f44336; display:inline-block; }
.circle-green { width:14px; height:14px; background:#4caf50; border-radius:50%; display:inline-block; }
.bold-text { font-weight:bold; }

/* Панель управления */
/* .control-panel { position:fixed; top:0; left:0; width:100%; height:100%; background:white; z-index:2000; overflow-y:auto; padding:20px; box-sizing:border-box; }
.panel-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; padding-bottom:10px; border-bottom:1px solid #ddd; }
.panel-tabs { display:flex; gap:5px; margin-bottom:20px; border-bottom:1px solid #ddd; }
.tab-btn { padding:10px 20px; background:none; border:none; cursor:pointer; font-size:16px; color:#666; transition:all 0.2s; }
.tab-btn.active { color:#667eea; border-bottom:2px solid #667eea; font-weight:bold; }
.tab-content { display:none; padding:20px 0; }
.tab-content.active { display:block; }
.settings-group { margin-bottom:20px; }
.settings-group label { display:block; margin-bottom:5px; font-weight:bold; }
.range-inputs { display:flex; align-items:center; gap:10px; }
.range-inputs input { width:120px; padding:8px; }
.user-form { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:20px; align-items:center; }
.user-form input, .user-form select { padding:8px; border:1px solid #ddd; border-radius:5px; flex:1; min-width:120px; }
.audit-table { width:100%; border-collapse:collapse; font-size:13px; }
.audit-table th, .audit-table td { padding:8px; border-bottom:1px solid #eee; text-align:left; }
.backup-item { display:flex; justify-content:space-between; align-items:center; padding:8px; border-bottom:1px solid #eee; }
.backup-info { font-size:12px; color:#666; } */

/* ==================== ПАНЕЛЬ УПРАВЛЕНИЯ ==================== */

.control-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 2000;
    overflow-y: auto;
    padding: 30px;
    box-sizing: border-box;
}

.control-panel .panel-header {
    background: white;
    border-radius: 20px;
    padding: 20px 30px;
    margin-bottom: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.control-panel .panel-header h2 {
    margin: 0;
    color: #333;
    font-size: 24px;
}

.control-panel .panel-actions button {
    margin-left: 10px;
    padding: 10px 25px;
}

/* Стили вкладок (табов) */
.control-panel .panel-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.control-panel .tab-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 12px 25px;
    border-radius: 40px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s;
    backdrop-filter: blur(5px);
}

.control-panel .tab-btn.active {
    background: white;
    color: #667eea;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.control-panel .tab-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}

/* Контент вкладок – карточки */
.control-panel .tab-content {
    display: none;
    background: white;
    border-radius: 20px;
    padding: 25px;
    margin-top: 5px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.control-panel .tab-content.active {
    display: block;
}

.control-panel .tab-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #333;
    font-size: 20px;
    border-left: 4px solid #667eea;
    padding-left: 15px;
}

.control-panel .settings-group {
    margin-bottom: 25px;
}

.control-panel .settings-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #555;
}

.control-panel input,
.control-panel select {
    width: 100%;
    max-width: 300px;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 30px;
    font-size: 14px;
}

.control-panel .range-inputs {
    display: flex;
    gap: 15px;
    align-items: center;
}

.control-panel .range-inputs input {
    width: 130px;
}

/* Пользователи */
.control-panel .user-form {
    background: #f9f9f9;
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.control-panel .user-form input,
.control-panel .user-form select {
    flex: 1;
    min-width: 150px;
}

.control-panel .users-table-container {
    max-height: 400px;
    overflow-y: auto;
    border-radius: 16px;
    border: 1px solid #eee;
}

.control-panel .users-table {
    width: 100%;
    border-collapse: collapse;
}

.control-panel .users-table th,
.control-panel .users-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.control-panel .users-table th {
    background: #f5f5f5;
    position: sticky;
    top: 0;
}

/* Аудит */
.control-panel .audit-filters {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.control-panel .audit-filters input {
    flex: 1;
}

.control-panel .audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.control-panel .audit-table th,
.control-panel .audit-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    text-align: left;
}

/* Бэкапы */
.control-panel .backup-info {
    background: #f0f7ff;
    border-radius: 16px;
    padding: 15px 20px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.control-panel .backup-list {
    border: 1px solid #eee;
    border-radius: 16px;
    max-height: 300px;
    overflow-y: auto;
}

.control-panel .backup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
}

.control-panel .backup-item:last-child {
    border-bottom: none;
}

.control-panel .restore-btn {
    background: #ff9800;
    color: white;
    border: none;
    padding: 6px 15px;
    border-radius: 30px;
    cursor: pointer;
}

.control-panel .restore-btn:hover {
    background: #f57c00;
}