/* ============================================================
   Multi Calendar System v2 — layout.css
   Каркас: header, nav, main, grid, адаптив.
   ============================================================ */

/* ------------------------------------------------------------
   1. Контейнер приложения
   ------------------------------------------------------------ */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: var(--content-max-width);
    width: 100%;
    margin: 0 auto;
    padding: var(--space-4);
    padding-bottom: calc(var(--space-4) + 80px); /* место под bottom-nav на мобилке */
}

/* ------------------------------------------------------------
   2. Шапка
   ------------------------------------------------------------ */
.header {
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    background-color: var(--color-bg-paper);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-height: var(--header-height);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-primary);
    text-decoration: none;
    white-space: nowrap;
}

.header-logo:hover {
    text-decoration: none;
    color: var(--color-primary-hover);
}

.header-logo-icon {
    font-size: 24px;
    line-height: 1;
}

/* Навигация в шапке (desktop) */
.header-nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
}

.header-nav::-webkit-scrollbar {
    display: none;
}

.header-nav a {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.header-nav a:hover {
    background-color: var(--color-bg-muted);
    color: var(--color-text);
    text-decoration: none;
}

.header-nav a.active {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
}

/* Блок пользователя */
.header-user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
    flex-shrink: 0;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    background-color: var(--color-bg-muted);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background-color: var(--color-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--font-size-sm);
    flex-shrink: 0;
}

.user-name {
    color: var(--color-text);
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role-badge {
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.user-role-badge.role-admin    { background-color: var(--color-danger-light);  color: var(--color-danger);  }
.user-role-badge.role-operator { background-color: var(--color-warning-light); color: var(--color-warning); }
.user-role-badge.role-employee { background-color: var(--color-success-light); color: var(--color-success); }

/* ------------------------------------------------------------
   3. Основной контент
   ------------------------------------------------------------ */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-2);
}

.page-title {
    margin: 0;
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--color-text);
}

.page-subtitle {
    margin: var(--space-1) 0 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.page-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* ------------------------------------------------------------
   4. Сетка
   ------------------------------------------------------------ */
.grid {
    display: grid;
    gap: var(--space-3);
}

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

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

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

.grid-auto {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid-auto-sm {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* ------------------------------------------------------------
   5. Раскладка sidebar + content
   ------------------------------------------------------------ */
.layout-sidebar {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--space-4);
}

.layout-sidebar-right {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: var(--space-4);
}

/* ------------------------------------------------------------
   6. Мобильная нижняя навигация
   ------------------------------------------------------------ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-bottom-nav);
    display: none; /* показывается на мобилке */
    background-color: var(--color-bg-paper);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 64px;
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    text-decoration: none;
    transition: color var(--transition-fast);
    min-height: 44px;
}

.bottom-nav-item:hover {
    text-decoration: none;
    color: var(--color-primary);
}

.bottom-nav-item.active {
    color: var(--color-primary);
}

.bottom-nav-icon {
    font-size: 22px;
    line-height: 1;
}

.bottom-nav-label {
    font-size: 11px;
    font-weight: 500;
}

/* ------------------------------------------------------------
   7. Адаптив
   ------------------------------------------------------------ */

/* Планшеты и меньше */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(3, 1fr); }
    .layout-sidebar        { grid-template-columns: 240px 1fr; }
    .layout-sidebar-right  { grid-template-columns: 1fr 280px; }
}

/* Мобилки / узкие экраны */
@media (max-width: 768px) {

    .app-container {
        padding: var(--space-3);
        padding-bottom: calc(var(--space-3) + 80px);
    }

    .header-inner {
        padding: var(--space-2) var(--space-3);
        gap: var(--space-2);
        min-height: 56px;
    }

    /* Скрываем desktop-навигацию в шапке */
    .header-nav {
        display: none;
    }

    .header-logo {
        font-size: var(--font-size-md);
    }

    .header-logo-text {
        display: none; /* на мобилке только иконка */
    }

    .user-name {
        display: none;
    }

    .user-role-badge {
        display: none;
    }

    /* Показываем нижнюю навигацию */
    .bottom-nav {
        display: block;
    }

    /* Сетки — в колонку */
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

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

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

    /* Sidebar — сверху */
    .layout-sidebar,
    .layout-sidebar-right {
        grid-template-columns: 1fr;
    }

    .page-title {
        font-size: var(--font-size-xl);
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-actions {
        width: 100%;
    }

    .page-actions > * {
        flex: 1;
    }
}

/* Очень узкие экраны */
@media (max-width: 480px) {

    .app-container {
        padding: var(--space-2);
        padding-bottom: calc(var(--space-2) + 80px);
    }

    .grid-auto-sm {
        grid-template-columns: 1fr;
    }

    .bottom-nav-icon {
        font-size: 20px;
    }

    .bottom-nav-label {
        font-size: 10px;
    }
}

/* ------------------------------------------------------------
   8. Утилиты раскладки
   ------------------------------------------------------------ */
.w-full     { width: 100%; }
.h-full     { height: 100%; }
.mx-auto    { margin-left: auto; margin-right: auto; }
.sticky-top { position: sticky; top: var(--header-height); z-index: 50; }

.scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

/* ------------------------------------------------------------
   9. Экран логина (отдельный layout)
   ------------------------------------------------------------ */
.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: linear-gradient(135deg, #e3f2fd 0%, #f5f5f5 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--color-bg-paper);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-6);
}

.auth-title {
    text-align: center;
    margin-bottom: var(--space-2);
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--color-primary);
}

.auth-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: var(--space-5);
    font-size: var(--font-size-sm);
}