body {
    margin: 0;
    font-family: 'Segoe UI', sans-serif;
    background: #f3f6fb;
    overflow: hidden;
}

/* LAYOUT */
.layout {
    display: flex;
    height: 100vh;
}

/* SIDEBAR */
.sidebar {
    width: 240px;
    background: white;
    padding: 20px;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.logo {
    font-size: 24px;
    font-weight: 800;
    color: #2a66ff;
    margin-bottom: 40px;
}
.menu {
    /* ... существующие стили ... */
    display: flex; /* Сделать меню Flex-контейнером */
    flex-direction: column; /* Элементы внутри будут располагаться вертикально */
    flex-grow: 1; /* Позволяет меню заполнить все доступное пространство между логотипом и низом сайдбара */
}

.menu a {
    display: block;
    padding: 12px 15px;
    border-radius: 8px;
    cursor: pointer;
    color: #555;
    text-decoration: none;
    margin-bottom: 5px;
    font-weight: 500;
    transition: background 0.2s;
}

.menu a.active {
    background: #e6eeff;
    color: #2a66ff;
}

.menu a:hover:not(.active) {
    background: #f4f4f4;
}

/* MAIN CONTENT */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 30px 40px;
    position: relative;
}

/* DASHBOARD HEADER */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    height: 50px;
}

.dashboard-header h2 { margin: 0; }

.edit-btn, .save-btn {
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s;
}

.edit-btn { background: #2a66ff; color: white; }
.edit-btn:hover { background: #1a50e0; }

.save-btn { background: #10b981; color: white; display: none; }
.save-btn:hover { background: #059669; }

/* --- GRID SYSTEM --- */
:root {
    --cell-w: 100px; 
    --cell-h: 120px;
    --gap: 20px; 
}

.grid {
    position: relative;
    /* Убираем width: 100%, ставим жесткую ширину или max-width */
    /* 24 колонки * 100px = 2400px + отступы */
    width: 2400px; 
    max-width: 100%; /* Чтобы не вылезало на мобилках */
    min-height: calc(100vh - 150px);
    padding-bottom: 100px;
    overflow-x: auto; /* Добавляем скролл, если сетка шире экрана */
}

.grid.edit-mode::before {
    content: "";
    position: absolute;
    inset: 0;
    width: 100%; 
    height: 100%;
    background-image:
        linear-gradient(to right, #dbe1ee 1px, transparent 1px),
        linear-gradient(to bottom, #dbe1ee 1px, transparent 1px);
    background-size: var(--cell-w) var(--cell-h);
    pointer-events: none;
    opacity: 0.6;
}

.widget-wrapper {
    position: absolute;
    box-sizing: border-box;
    padding: calc(var(--gap) / 2);
    transition: transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 10;
}

.dashboard-widget {
    position: relative;
    width: 100%;
    height: 100%;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02), 0 10px 15px rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.dashboard-widget .inner {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.widget-wrapper.dragging {
    transition: none;
    z-index: 100;
}

.widget-wrapper.dragging .dashboard-widget {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    transform: scale(1.02);
    cursor: grabbing;
}

.resize-handle {
    display: none;
    position: absolute;
    bottom: 10px; right: 10px;
    width: 20px; height: 20px;
    background: white;
    border: 2px solid #2a66ff;
    border-radius: 50%;
    cursor: nwse-resize;
    z-index: 20;
}

.grid.edit-mode .resize-handle { display: block; }
.grid.edit-mode .widget-wrapper { cursor: grab; }

/* WIDGET PICKER */
.widget-picker {
    position: fixed;
    right: 30px; top: 90px;
    width: 280px;
    background: white;
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
    z-index: 999;
}
.widget-picker.hidden { display: none; }

#widgetPickerList div {
    padding: 12px 16px; margin-bottom: 8px;
    background: #f8fafc; border: 1px solid #e2e8f0;
    border-radius: 8px; font-size: 14px;
    cursor: pointer; transition: 0.2s;
}
#widgetPickerList div:hover {
    background: #eff6ff; border-color: #2a66ff; color: #2a66ff;
}
.picker-close-btn {
    margin-top: 10px; width: 100%; padding: 8px;
    background: #eee; border: none; border-radius: 6px; cursor: pointer;
}
/* --- КНОПКА УДАЛЕНИЯ ВИДЖЕТА --- */
.delete-widget-btn {
    display: none; /* Скрыта по умолчанию */
    position: absolute;
    top: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 22px;
    font-weight: bold;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    z-index: 50; /* Поверх всего */
    border: 2px solid white;
    transition: transform 0.2s;
}

.delete-widget-btn:hover {
    background: #ff0000;
    transform: scale(1.1);
}

/* Показываем кнопку только в режиме редактирования */
.grid.edit-mode .delete-widget-btn {
    display: block;
}

/* --- СТИЛИ ДЛЯ БИТЫХ ВИДЖЕТОВ --- */
.dashboard-widget.error-state {
    background: #fff1f2;
    border: 2px solid #ef4444;
    color: #b91c1c;
}

.error-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 10px;
}

.error-icon {
    font-size: 24px;
    margin-bottom: 5px;
}

.error-text {
    font-size: 12px;
    font-weight: bold;
}

/* --- ЭКРАН ВХОДА --- */
.auth-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #f3f6fb;
    z-index: 9999;
    
    /* ИЗМЕНЕНИЕ: Скрыто по умолчанию */
    display: none; 
    
    justify-content: center;
    align-items: center;
}

/* ИЗМЕНЕНИЕ: Класс для показа окна */
.auth-overlay.show {
    display: flex;
}
.auth-overlay.hidden {
    display: none;
}

.auth-box {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
    width: 350px;
    text-align: center;
}

.auth-box h2 { color: #333; margin-bottom: 20px; }

.auth-input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 2px solid #eee;
    border-radius: 8px;
    font-size: 16px;
    box-sizing: border-box;
}

.auth-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 10px;
    transition: 0.2s;
}

.btn-login { background: #2a66ff; color: white; }
.btn-login:hover { background: #1a50e0; }

.btn-register { background: white; border: 2px solid #2a66ff; color: #2a66ff; }
.btn-register:hover { background: #f0f5ff; }

.auth-error {
    color: #ff4757;
    margin-bottom: 15px;
    font-size: 14px;
    min-height: 20px;
}
