/* ============================================================
   POSTERX · LAYOUT
   Каркас: app-shell, sidebar, topbar, mobile-nav, page-content,
   profile-menu, timezone-modal, header-clock.
   ============================================================ */

/* ============================================================
   APP SHELL
   ============================================================ */

.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    background: var(--bg-page);
}

.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.page-content {
    width: 100%;
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: var(--space-6) var(--space-7);
    flex: 1;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
    position: sticky;
    top: 0;
    z-index: var(--z-sidebar);

    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;

    display: flex;
    flex-direction: column;

    padding: var(--space-5) var(--space-4) var(--space-4);

    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);

    transition: width var(--transition-slow),
        min-width var(--transition-slow),
        background-color var(--transition);
}

.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: var(--space-3);
    scrollbar-width: thin;
}

/* Brand */

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-2) var(--space-7);
    white-space: nowrap;
    color: var(--text);
    transition: opacity var(--transition-fast);
}

.brand:hover {
    opacity: 0.85;
}

.brand-icon {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    color: #ffffff;
    transform: rotate(-8deg);
    box-shadow: 0 4px 14px var(--accent-glow);
}

.brand-name {
    font-size: var(--fs-2xl);
    font-weight: var(--fw-extrabold);
    letter-spacing: -0.03em;
}

/* Заголовки секций меню */

.menu-caption {
    padding: 0 var(--space-3) var(--space-2);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: var(--fw-extrabold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.menu-caption-spaced {
    margin-top: var(--space-5);
}

/* Навигация */

.side-nav {
    display: grid;
    gap: var(--space-1);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);

    min-height: 40px;
    padding: 0 var(--space-3);

    border-radius: var(--radius-sm);

    color: var(--text-secondary);
    font-size: var(--fs-base);
    font-weight: var(--fw-medium);

    white-space: nowrap;

    transition: background-color var(--transition-fast),
        color var(--transition-fast);
}

.nav-link:hover {
    background: var(--bg-surface-hover);
    color: var(--text);
}

.nav-link.active {
    background: var(--accent-gradient);
    color: #ffffff;
    box-shadow: 0 5px 16px var(--accent-glow);
}

.nav-link.active .nav-icon,
.nav-link.active .nav-label {
    color: #ffffff;
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 21px;
    flex: 0 0 21px;
}

.nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Низ сайдбара (профиль) */

.sidebar-bottom {
    display: flex;
    align-items: center;
    gap: var(--space-3);

    min-height: 58px;
    margin-top: var(--space-3);
    padding: var(--space-3) var(--space-1) 0;

    border-top: 1px solid var(--border);

    cursor: pointer;
    border-radius: var(--radius-sm);

    transition: background-color var(--transition-fast);
}

.sidebar-bottom:hover {
    background: var(--bg-surface-hover);
}

.sidebar-bottom:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.avatar {
    width: 42px;
    height: 42px;
    min-width: 42px;
    flex: 0 0 42px;

    display: grid;
    place-items: center;
    overflow: hidden;

    border-radius: 50%;

    background: var(--accent-gradient);
    color: #ffffff;

    font-size: var(--fs-md);
    font-weight: var(--fw-bold);
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

.small-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    flex-basis: 32px;
    font-size: var(--fs-sm);
}

.user-meta {
    flex: 1;
    min-width: 0;
    display: grid;
    gap: 2px;
}

.user-meta strong {
    overflow: hidden;
    color: var(--text);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-meta span {
    color: var(--text-muted);
    font-size: var(--fs-xs);
}

.user-more {
    color: var(--text-muted);
    font-size: var(--fs-lg);
}

/* Свёрнутый сайдбар */

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
    min-width: var(--sidebar-width-collapsed);
    padding-left: var(--space-3);
    padding-right: var(--space-3);
}

.sidebar.collapsed .brand {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.sidebar.collapsed .brand-name,
.sidebar.collapsed .menu-caption,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .user-meta,
.sidebar.collapsed .user-more {
    display: none;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 0;
}

.sidebar.collapsed .sidebar-bottom {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.sidebar.collapsed .nav-link:hover::after {
    content: attr(title);

    position: absolute;
    left: calc(var(--sidebar-width-collapsed) + 2px);
    top: 50%;
    transform: translateY(-50%);

    z-index: var(--z-dropdown);

    padding: var(--space-2) var(--space-3);

    border: 1px solid var(--border);
    border-radius: var(--radius-xs);

    background: var(--bg-surface);
    color: var(--text);

    white-space: nowrap;

    box-shadow: var(--shadow-md);

    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
}

/* ============================================================
   TOPBAR
   ============================================================ */

.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);

    min-height: var(--topbar-height);
    height: var(--topbar-height);

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);

    padding: 0 var(--space-6);

    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.topbar-left {
    min-width: 0;
    flex: 1;
}

.topbar-actions {
    flex-shrink: 0;
    position: relative;
    z-index: 5;
}

.breadcrumbs {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.breadcrumbs span {
    margin: 0 var(--space-2);
    color: var(--text-muted);
}

.breadcrumbs strong {
    color: var(--text);
    font-weight: var(--fw-semibold);
}

/* Кнопка темы */

.theme-toggle {
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
}

.theme-toggle:hover {
    color: var(--text);
    background: var(--bg-surface-hover);
}

/* Кнопка уведомлений */

.notification-button {
    position: relative;
}

.notification-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--bg-sidebar);
}

/* Баланс */

.balance-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);

    min-height: 44px;
    padding: 0 var(--space-4);

    border: 1px solid var(--border);
    border-radius: var(--radius-md);

    background: var(--bg-surface);
    color: var(--text-secondary);

    font-size: var(--fs-sm);

    cursor: pointer;
    transition: border-color var(--transition-fast),
        background-color var(--transition-fast);
}

.balance-pill:hover {
    border-color: var(--accent);
    background: var(--bg-surface-hover);
}

.balance-symbol {
    color: var(--accent);
    display: inline-flex;
}

.balance-pill strong {
    color: var(--text);
    font-weight: var(--fw-semibold);
    font-variant-numeric: tabular-nums;
}

.add-balance {
    display: grid;
    place-items: center;

    width: 26px;
    height: 26px;

    border-radius: var(--radius-xs);

    background: var(--accent);
    color: #ffffff;

    font-size: var(--fs-lg);
    font-weight: var(--fw-bold);
    line-height: 1;

    transition: background-color var(--transition-fast);
}

.add-balance:hover {
    background: var(--accent-hover);
}

/* Профиль */

.profile-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);

    min-height: 44px;
    padding: 4px var(--space-3) 4px 4px;

    border: 1px solid var(--border);
    border-radius: var(--radius-md);

    background: var(--bg-surface);
    color: var(--text);

    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);

    cursor: pointer;
    transition: border-color var(--transition-fast),
        background-color var(--transition-fast);
}

.profile-button:hover {
    border-color: var(--border-hover);
    background: var(--bg-surface-hover);
}

.profile-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   HEADER CLOCK
   ============================================================ */

.header-clock {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;

    display: flex;
    align-items: center;
    gap: var(--space-2);

    padding: var(--space-1) var(--space-3);

    border: 0;
    border-radius: var(--radius-md);

    background: transparent;
    color: var(--text);

    cursor: pointer;

    transition: background-color var(--transition-fast);
}

.header-clock:hover {
    background: var(--bg-surface-hover);
}

.header-clock-icon {
    display: grid;
    place-items: center;

    width: 28px;
    height: 28px;

    border-radius: var(--radius-sm);

    background: var(--success-soft);
    color: var(--success);
}

.header-clock-icon [data-lucide] {
    width: 15px;
    height: 15px;
}

.header-clock-meta {
    display: grid;
    gap: 1px;
    text-align: center;
    min-width: 0;
}

.header-clock-meta strong {
    color: var(--text);
    font-size: var(--fs-2xl);
    line-height: 1;
    font-weight: var(--fw-bold);
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
}

.header-clock-meta small {
    color: var(--text-secondary);
    font-size: 10px;
    line-height: 1.3;
    white-space: nowrap;
}

.header-clock-meta #headerClockDate {
    color: var(--text);
    font-size: 11px;
    font-weight: var(--fw-semibold);
}

.header-clock-chevron {
    position: absolute;
    right: 6px;
    top: 6px;
    width: 12px;
    height: 12px;
    color: var(--text-muted);
}

/* Стили часов */

.header-clock.clock-style-glow {
    border: 1px solid var(--accent);
    background: radial-gradient(ellipse at 50% 0%, var(--accent-soft), transparent 75%),
        var(--bg-surface);
    box-shadow: 0 0 25px var(--accent-glow);
}

.header-clock.clock-style-glow .header-clock-meta strong {
    color: #70b7ff;
    text-shadow: 0 0 12px var(--accent-glow);
}

.header-clock.clock-style-minimal {
    min-width: 200px;
    border: none;
    background: transparent;
    box-shadow: none;
}

.header-clock.clock-style-minimal .header-clock-meta strong {
    font-size: var(--fs-3xl);
    letter-spacing: 0.06em;
}

/* ============================================================
   PROFILE MENU (выпадающее окно)
   ============================================================ */

.profile-menu {
    position: fixed;
    z-index: var(--z-modal);

    width: 292px;
    padding: var(--space-3);

    border: 1px solid var(--border);
    border-radius: var(--radius-lg);

    background: var(--bg-surface);
    color: var(--text);

    box-shadow: var(--shadow-lg);

    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);

    animation: px-fade-slide var(--transition) ease;
}

.profile-menu[hidden] {
    display: none !important;
}

.profile-menu-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-2) var(--space-4);
}

.profile-menu-avatar {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
}

.profile-menu-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow: hidden;
}

.profile-menu-name {
    overflow: hidden;
    color: var(--text);
    font-size: var(--fs-md);
    font-weight: var(--fw-bold);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-menu-info span {
    color: var(--text-secondary);
    font-size: var(--fs-xs);
}

.profile-menu-divider {
    height: 1px;
    margin: var(--space-2) 0;
    background: var(--border);
}

.profile-menu > button {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: 44px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
    text-align: left;
    transition: background-color var(--transition-fast);
}

.profile-menu > button:hover {
    background: var(--bg-surface-hover);
}

.profile-menu > button svg {
    width: 17px;
    height: 17px;
    color: var(--text-secondary);
}

.profile-menu > .profile-menu-logout {
    color: var(--danger);
}

.profile-menu > .profile-menu-logout svg {
    color: var(--danger);
}

/* ============================================================
   TIMEZONE MODAL
   ============================================================ */

.timezone-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);

    display: grid;
    place-items: center;

    padding: var(--space-4);
}

.timezone-modal[hidden] {
    display: none !important;
}

.timezone-backdrop {
    position: absolute;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.timezone-dialog {
    position: relative;
    z-index: 1;

    width: min(100%, 490px);
    max-height: min(88vh, 820px);

    display: flex;
    flex-direction: column;
    overflow-y: auto;

    padding: var(--space-6);

    border: 1px solid var(--border);
    border-radius: var(--radius-xl);

    background: var(--bg-surface);
    color: var(--text);

    box-shadow: var(--shadow-lg);

    animation: px-fade-slide var(--transition) ease;
}

.timezone-dialog-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
}

.timezone-dialog-head h2 {
    margin: 0 0 var(--space-1);
    font-size: var(--fs-xl);
}

.timezone-dialog-head p {
    max-width: 370px;
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    line-height: var(--lh-normal);
}

.timezone-search {
    display: flex;
    align-items: center;
    gap: var(--space-2);

    min-height: 42px;
    margin: var(--space-4) 0 var(--space-3);
    padding: 0 var(--space-3);

    border: 1px solid var(--border);
    border-radius: var(--radius-sm);

    background: var(--bg-input);
    color: var(--text-muted);

    transition: border-color var(--transition-fast);
}

.timezone-search:focus-within {
    border-color: var(--accent);
    box-shadow: var(--shadow-focus);
}

.timezone-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font-size: var(--fs-md);
    min-height: auto;
    padding: 0;
}

.timezone-current {
    display: grid;
    gap: 2px;
    margin-bottom: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
}

.timezone-current span,
.timezone-current small {
    color: var(--text-secondary);
    font-size: var(--fs-xs);
}

.timezone-current strong {
    color: var(--text);
    font-size: var(--fs-md);
}

.timezone-list {
    min-height: 100px;
    max-height: 260px;
    overflow-y: auto;
}

.timezone-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);

    width: 100%;
    min-height: 52px;
    padding: var(--space-2) var(--space-3);

    border: 0;
    border-bottom: 1px solid var(--border);

    background: transparent;
    color: var(--text);

    text-align: left;

    transition: background-color var(--transition-fast);
}

.timezone-option:hover,
.timezone-option.selected {
    background: var(--bg-surface-hover);
}

.timezone-option > span:first-child {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.timezone-option strong {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

.timezone-option small {
    color: var(--text-secondary);
    font-size: var(--fs-xs);
}

.timezone-option-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.timezone-option-right [data-lucide] {
    width: 16px;
    height: 16px;
    color: var(--success);
}

.timezone-no-results {
    padding: var(--space-5) var(--space-2);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    text-align: center;
}

.timezone-dialog-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);

    padding-top: var(--space-4);
}

.timezone-dialog-foot span {
    max-width: 290px;
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    line-height: var(--lh-normal);
}

/* Стили превью часов в модалке */

.timezone-style-heading {
    margin: var(--space-5) 0 var(--space-3);
    font-size: var(--fs-sm);
    font-weight: var(--fw-bold);
    color: var(--text);
}

.timezone-style-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.timezone-style-option {
    display: grid;
    justify-items: center;
    gap: var(--space-1);

    padding: var(--space-3) var(--space-2);

    border: 1px solid var(--border);
    border-radius: var(--radius-md);

    background: var(--bg-surface-2);
    color: var(--text);

    cursor: pointer;

    transition: border-color var(--transition-fast),
        background-color var(--transition-fast);
}

.timezone-style-option:hover {
    border-color: var(--border-hover);
}

.timezone-style-option.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.style-preview {
    width: 100%;
    padding: var(--space-3) var(--space-1);
    border-radius: var(--radius-xs);
    text-align: center;
    font-size: var(--fs-xl);
    font-weight: var(--fw-extrabold);
    font-variant-numeric: tabular-nums;
}

.preview-digital {
    background: var(--bg-input);
    color: var(--text);
}

.preview-glow {
    background: var(--bg-input);
    color: #70b7ff;
    text-shadow: 0 0 9px var(--accent-glow);
}

.preview-minimal {
    background: transparent;
    color: var(--text);
}

.timezone-style-option strong {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

.timezone-style-option small {
    color: var(--text-secondary);
    font-size: var(--fs-xs);
}

/* ============================================================
   MOBILE NAV
   ============================================================ */

.mobile-nav {
    display: none;
}

/* ============================================================
   АДАПТИВ
   ============================================================ */

/* Планшет: узкий сайдбар */
@media (max-width: 1100px) {
    :root {
        --sidebar-width: 225px;
        --sidebar-width-collapsed: 76px;
    }

    .page-content {
        padding: var(--space-5) var(--space-5);
    }
}

/* Малый планшет: только иконки */
@media (max-width: 900px) {
    .topbar {
        min-height: 64px;
        height: 64px;
        padding: 0 var(--space-4);
    }

    .header-clock {
        position: static;
        transform: none;
        margin-left: auto;
        padding: var(--space-1) var(--space-2);
    }

    .header-clock-meta strong {
        font-size: var(--fs-xl);
    }

    .header-clock-icon,
    .header-clock-chevron {
        display: none;
    }

    .header-clock-meta #headerClockDate,
    .header-clock-meta #sidebarTimezone {
        display: none;
    }

    .balance-pill {
        display: none;
    }

    .profile-name {
        max-width: 100px;
    }

    .topbar-left {
        flex: 0 1 auto;
    }

    .topbar-actions {
        margin-left: auto;
    }
}

/* Узкий планшет / большой телефон */
@media (max-width: 760px) {
    .sidebar {
        width: var(--sidebar-width-collapsed);
        min-width: var(--sidebar-width-collapsed);
        padding-left: var(--space-3);
        padding-right: var(--space-3);
    }

    .sidebar .brand {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    .sidebar .brand-name,
    .sidebar .menu-caption,
    .sidebar .nav-label,
    .sidebar .user-meta,
    .sidebar .user-more {
        display: none;
    }

    .sidebar .nav-link {
        justify-content: center;
        padding: 0;
    }

    .sidebar .sidebar-bottom {
        justify-content: center;
    }

    .page-content {
        padding: var(--space-4) var(--space-4);
    }
}

/* Мобильный: сайдбар скрыт, mobile-nav */
@media (max-width: 640px) {
    .sidebar {
        display: none;
    }

    .topbar {
        min-height: 60px;
        height: 60px;
        padding: 0 var(--space-3);
    }

    .topbar-left {
        gap: var(--space-2);
    }

    .topbar-actions {
        gap: var(--space-1);
    }

    .sidebar-toggle {
        display: none;
    }

    .breadcrumbs {
        font-size: var(--fs-xs);
    }

    .icon-button,
    .theme-toggle,
    .notification-button {
        width: 38px;
        height: 38px;
        min-width: 38px;
        border-radius: var(--radius-sm);
    }

    .profile-button {
        min-height: 38px;
        padding: 3px;
        border: 0;
        background: transparent;
    }

    .profile-button:hover {
        background: var(--bg-surface-hover);
    }

    .profile-button .small-avatar {
        width: 34px;
        height: 34px;
    }

    .profile-name {
        display: none;
    }

    .header-clock {
        margin-left: 0;
        padding: 0;
    }

    .header-clock-meta strong {
        font-size: var(--fs-lg);
    }

    .header-clock-meta small {
        font-size: 9px;
    }

    .page-content {
        padding: var(--space-3) var(--space-3) calc(84px + env(safe-area-inset-bottom));
    }

    .mobile-nav {
        position: fixed;
        z-index: var(--z-mobile-nav);
        left: 0;
        right: 0;
        bottom: 0;

        display: flex;
        justify-content: space-around;

        height: calc(64px + env(safe-area-inset-bottom));

        padding: var(--space-1) 0 env(safe-area-inset-bottom);

        background: var(--bg-sidebar);
        border-top: 1px solid var(--border);

        box-shadow: var(--shadow-md);
    }

    .mobile-nav a {
        flex: 1;

        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;

        color: var(--text-muted);
        font-size: 10px;
        font-weight: var(--fw-medium);

        transition: color var(--transition-fast);
    }

    .mobile-nav a.active {
        color: var(--accent);
    }

    .mobile-nav a:hover {
        color: var(--text);
    }
}