:root {
    --primary: #0c6b6e;
    --primary-hover: #0a5b5d;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
}
[data-theme="dark"] {
    --bg: #111827;
    --card-bg: #1f2937;
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --border: #374151;
}
body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, color 0.3s;
}
header {
    background-color: var(--card-bg); border-bottom: 1px solid var(--border);
    padding: 0 20px; padding-top: env(safe-area-inset-top);
    padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right));
    position: sticky; top: 0; z-index: 1000; box-sizing: border-box;
}
.nav-container { max-width: 1200px; margin: 0 auto; height: 70px; display: flex; align-items: center; }
.logo { font-size: 22px; font-weight: 800; color: var(--primary); text-decoration: none; display: flex; align-items: center; gap: 8px; white-space: nowrap; flex-shrink: 0; }
.logo-icon { width: 50px; height: 50px; }
.nav-menu { display: flex; align-items: center; gap: 15px; margin-left: auto; }
.nav-link { color: var(--text); text-decoration: none; font-size: 15px; font-weight: 500; padding: 8px 12px; border-radius: 6px; transition: all 0.2s; }
.nav-link:hover, .nav-link.active { background-color: var(--bg); color: var(--primary); }
.btn-service { color: white !important; text-decoration: none; padding: 10px 16px; border-radius: 8px; font-weight: 600; font-size: 14px; transition: opacity 0.2s; display: flex; align-items: center; gap: 8px; }
.btn-service:hover { opacity: 0.9; }
.btn-bitwarden { background: #175ddc; box-shadow: 0 4px 6px -1px rgba(23, 93, 220, 0.2); }
.btn-n8n { background: #ff6d5a; box-shadow: 0 4px 6px -1px rgba(255, 109, 90, 0.2); }
.btn-study { background: #0a2641; box-shadow: 0 4px 6px -1px rgba(10, 38, 65, 0.3); }
.btn-study-icon { width: 18px; height: 18px; border-radius: 4px; display: block; }
.nav-right { display: flex; align-items: center; gap: 4px; margin-left: 15px; flex-shrink: 0; }
.btn-theme-toggle { background: none; border: none; cursor: pointer; padding: 8px; border-radius: 50%; font-size: 18px; color: var(--text); display: flex; align-items: center; }
.btn-theme-toggle:hover { background-color: var(--border); }
.btn-menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 8px; border-radius: 8px; color: var(--text); align-items: center; justify-content: center; }
.btn-menu-toggle:hover { background-color: var(--border); }
.menu-toggle-icon { font-size: 22px; line-height: 1; }
.nav-services { display: flex; align-items: center; gap: 15px; }

/* Стадия 1: только кнопки сервисов (Bitwarden/n8n) уходят в выпадающую панель,
   пункты меню остаются видимыми в строке. */
@media (max-width: 1200px) and (min-width: 1001px) {
    .btn-menu-toggle { display: flex; }
    .nav-menu { margin-left: auto; }
    .nav-services {
        position: absolute; top: 100%; right: 20px;
        flex-direction: column; align-items: stretch; gap: 8px;
        min-width: 220px;
        background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
        padding: 0; box-sizing: border-box;
        max-height: 0; overflow: hidden; opacity: 0; pointer-events: none;
        transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.25s ease;
    }
    .nav-menu.open .nav-services {
        max-height: 200px; opacity: 1; padding: 10px; pointer-events: auto;
        box-shadow: 0 12px 20px -8px rgba(0, 0, 0, 0.15);
    }
    .btn-service { width: 100%; justify-content: center; box-sizing: border-box; }
}

/* Стадия 2: пункты меню и кнопки сервисов вместе уходят в одну выпадающую панель. */
@media (max-width: 1000px) {
    .nav-container { height: 70px; }
    .btn-menu-toggle { display: flex; }
    .nav-right { margin-left: auto; }
    .nav-menu {
        position: absolute; top: 100%; left: 0; right: 0;
        flex-direction: column; align-items: stretch; gap: 8px;
        margin-left: 0;
        background: var(--card-bg); border-bottom: 1px solid var(--border);
        padding: 0 20px; box-sizing: border-box;
        max-height: 0; overflow: hidden; opacity: 0;
        transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.25s ease;
    }
    .nav-menu.open { max-height: 500px; opacity: 1; padding: 15px 20px 20px; box-shadow: 0 12px 20px -8px rgba(0, 0, 0, 0.15); }
    .nav-services {
        position: static; flex-direction: column; align-items: stretch; gap: 8px;
        min-width: 0; background: none; border: none; box-shadow: none;
        padding: 0; max-height: none; opacity: 1; pointer-events: auto;
        margin-top: 8px;
    }
    .btn-service { width: 100%; justify-content: center; box-sizing: border-box; }
}
