/* ============================================================================
   Табель — каркас: сброс, типографика, навигация, оболочка страницы.
   Mobile-first: базовые правила — для телефона, десктоп добавляется на ≥1024px.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любой display у компонента (.alert, .btn и прочие). */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
form { margin: 0; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ===== ИКОНКИ ===== */
.ic {
    width: 1em; height: 1em;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.135em;
}

/* ===== ЛОГОТИП: 24 деления циферблата ===== */
.wordmark {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.02em;
}
.wordmark .accent { color: var(--accent); }

.logomark { width: 28px; height: 28px; flex-shrink: 0; }
.logomark .face { fill: none; stroke: var(--border); stroke-width: 1.6; }
.logomark .arc   { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.logomark .pivot { fill: var(--accent); }

/* ===== БОКОВАЯ НАВИГАЦИЯ (на телефоне — выдвижная) ===== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 264px;
    max-width: 84vw;
    background: var(--sidebar);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    padding: 18px 14px calc(16px + env(safe-area-inset-bottom));
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    box-shadow: var(--shadow-lg);
}
body.drawer-open .sidebar { transform: none; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 8px 18px;
    font-size: 1.15rem;
    color: var(--text);
}
.sidebar-brand small {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.64rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 2px;
}

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }

.nav-section {
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    padding: 16px 12px 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    position: relative;
    transition: background 0.15s, color 0.15s;
}
.nav-link .ic { width: 18px; height: 18px; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--sidebar-active); color: var(--accent); font-weight: 600; }
.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0; top: 9px; bottom: 9px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
}

.sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    padding-top: 12px;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 2px 8px; min-width: 0; }
.sidebar-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-text);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem;
    flex-shrink: 0;
    font-family: var(--font-display);
}
.sidebar-user-meta { min-width: 0; }
.sidebar-user-name { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 0.72rem; color: var(--text-muted); }
.sidebar-actions { display: flex; gap: 8px; align-items: center; }
.sidebar-actions form { flex: 1; display: flex; }
.sidebar-actions .btn { width: 100%; height: 38px; justify-content: center; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 190;
    background: rgba(8,10,16,0.5);
}
body.drawer-open .sidebar-backdrop { display: block; }

/* ===== ВЕРХНЯЯ ПАНЕЛЬ ТЕЛЕФОНА ===== */
.mobile-bar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 150;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 14px;
    padding-top: env(safe-area-inset-top);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.mobile-bar .sidebar-brand { padding: 0; font-size: 1.05rem; }
.mobile-bar-actions { margin-left: auto; display: flex; gap: 8px; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .ic { width: 20px; height: 20px; }

/* ===== НИЖНЯЯ ПАНЕЛЬ (только телефон) ===== */
.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 160;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 9px 4px 7px;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-muted);
}
.tabbar a .ic { width: 21px; height: 21px; }
.tabbar a.active { color: var(--accent); }

/* ===== ПЕРЕКЛЮЧАТЕЛЬ ТЕМЫ ===== */
.theme-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}
.theme-btn:hover { background: var(--border); color: var(--text); }
.theme-btn-icon { width: 42px; height: 38px; padding: 0; flex-shrink: 0; }
.theme-btn-float {
    position: fixed;
    top: calc(16px + env(safe-area-inset-top)); right: 16px;
    z-index: 50;
    background: var(--surface);
    width: 40px; height: 40px;
    font-size: 1.05rem;
}

/* ===== ОБЛАСТЬ КОНТЕНТА ===== */
.app-main { min-height: 100vh; }
body.has-nav .app-main { padding-bottom: 68px; }   /* место под tabbar */

.shell {
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 14px 40px;
}

/* ===== ШАПКА СТРАНИЦЫ ===== */
.page-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 18px;
}

.page-eyebrow {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.page-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}
.page-subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 0.875rem; }

.page-header-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ===== ДЕСКТОП ===== */
@media (min-width: 1024px) {
    .sidebar { transform: none; box-shadow: none; }
    .sidebar-backdrop { display: none !important; }
    .mobile-bar, .tabbar { display: none; }
    body.has-nav .app-main { margin-left: 264px; padding-bottom: 0; }
    .shell { padding: 30px 28px 60px; }
    .page-header {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        gap: 16px;
        margin-bottom: 24px;
    }
    .page-title { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
