/* Top Navigation Bar — CRM */

/* ========== Layout ========== */
.crm-topnav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 4px;
    z-index: 1000;
}

/* ========== Logo ========== */
.topnav-logo {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 15px;
    padding: 7px 10px;
    border-radius: 8px;
    transition: background 0.15s;
    white-space: nowrap;
    margin-right: 6px;
    flex-shrink: 0;
}
.topnav-logo:hover { background: var(--bg-hover); }
.topnav-logo .logo-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: cover;
}

/* ========== Center nav ========== */
.topnav-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.topnav-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 11px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    background: none;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    position: relative;
    line-height: 1;
}
.topnav-link:hover,
.topnav-link.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ========== Badge ========== */
.topnav-badge {
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #ef4444;
    color: #fff;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

/* ========== Dropdown ========== */
.topnav-dropdown { position: relative; }

.topnav-dropdown-btn { /* same as .topnav-link */ }

.topnav-chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform 0.15s;
    color: var(--text-muted);
}
.topnav-dropdown.open .topnav-chevron { transform: rotate(180deg); }

.topnav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    min-width: 185px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 5px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.45);
    z-index: 1200;
}
.topnav-dropdown.open .topnav-dropdown-menu { display: block; }

.topnav-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 7px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.topnav-dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.topnav-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 6px;
}

/* ========== Right side ========== */
.topnav-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
}

.topnav-right .global-search { width: 220px; }
.topnav-right .global-search-input { height: 36px; font-size: 13px; }

/* ========== Icon buttons ========== */
.topnav-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.topnav-icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.topnav-icon-btn .icon { width: 18px; height: 18px; }

/* ========== User button ========== */
.topnav-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 5px;
    border-radius: 8px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    max-width: 180px;
}
.topnav-user-btn:hover { background: var(--bg-hover); }
.topnav-user-btn .topnav-chevron { color: var(--text-muted); }

.topnav-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 110px;
}

.topnav-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.topnav-avatar-initials {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-primary);
    flex-shrink: 0;
    text-transform: uppercase;
}

.topnav-user-dropdown .topnav-dropdown-menu {
    right: 0;
    left: auto;
    min-width: 160px;
}

/* ========== Hamburger ========== */
.topnav-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.topnav-hamburger:hover { background: var(--bg-hover); color: var(--text-primary); }
.topnav-hamburger .icon { width: 20px; height: 20px; }

/* ========== Mobile menu ========== */
.topnav-mobile-menu {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 10px;
    z-index: 990;
    flex-direction: column;
    gap: 1px;
    box-shadow: 0 10px 24px rgba(0,0,0,0.35);
    max-height: calc(100vh - 60px);
    overflow-y: auto;
}
.topnav-mobile-menu.open { display: flex; }

.topnav-mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 60px;
    background: rgba(0,0,0,0.45);
    z-index: 980;
}
.topnav-mobile-backdrop.active { display: block; }

.topnav-mobile-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.topnav-mobile-link:hover,
.topnav-mobile-link.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.topnav-mobile-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    padding: 10px 14px 4px;
}
.topnav-mobile-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 0;
}

/* ========== Dashboard feature cards ========== */
.dashboard-header {
    margin-bottom: 24px;
}
.dashboard-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.dashboard-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px 20px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-decoration: none;
    color: inherit;
    user-select: none;
}
.dashboard-card:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
    transform: translateY(-2px);
}

.dashboard-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.dashboard-card-icon .icon { width: 22px; height: 22px; }

.dashboard-card-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.dashboard-card-value {
    font-size: 38px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}
.dashboard-card-sub {
    font-size: 13px;
    color: var(--text-muted);
}
.dashboard-card-alert {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(239,68,68,0.15);
    color: #f87171;
    margin-left: 4px;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
    .topnav-right .global-search { width: 160px; }
}

@media (max-width: 768px) {
    .topnav-nav { display: none; }
    .topnav-hamburger { display: flex; }
    .topnav-right .global-search { width: 130px; }

    .dashboard-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    .dashboard-card { padding: 18px 14px; gap: 10px; }
    .dashboard-card-value { font-size: 30px; }
}

@media (max-width: 480px) {
    .topnav-right .global-search { display: none; }
    .topnav-user-name { display: none; }
    .dashboard-cards { grid-template-columns: 1fr 1fr; gap: 10px; }
}


/* ============================================================
   MOBILE OVERRIDES — топнав-лэйаут + таблицы + Kanban
   ============================================================ */

@media (max-width: 991px) {
    /* Override old sidebar margin from mobile.css */
    .crm-main,
    .crm-content {
        margin-left: 0 !important;
    }

    /* Tables: horizontal scroll instead of fixed layout */
    .crm-content .table-wrap,
    .crm-content .clients-table-wrapper,
    .crm-content .lots-table-wrapper,
    .crm-content [class*="table-wrapper"],
    .crm-content [class*="table-scroll"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* Tables: let them scroll instead of truncating */
    .crm-content table {
        table-layout: auto !important;
        min-width: 600px;
        font-size: 12px !important;
    }

    /* Stages (Kanban) horizontal scroll */
    .stages-board-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .stages-board {
        min-width: max-content;
    }

    /* Don't make ALL buttons 100% width — only stack action groups */
    .crm-content .btn,
    .crm-content button {
        width: auto !important;
        font-size: 13px !important;
    }

    /* Hero actions stack on small screens */
    .client-hero-actions {
        flex-direction: column;
        width: 100%;
    }
    .client-hero-actions .btn-primary,
    .client-hero-actions .btn-secondary {
        width: 100% !important;
    }
}

@media (max-width: 600px) {
    /* Content padding tighter on phones */
    .crm-content {
        padding: 16px 14px !important;
    }

    /* Client hero stacks on phone */
    .client-hero {
        flex-direction: column;
        gap: 16px;
    }
    .client-hero-actions {
        width: 100%;
    }

    /* Info grid single column on phone */
    .info-grid {
        grid-template-columns: 1fr !important;
    }

    /* Kanban cards: remove slide buttons on phone (use swipe) */
    .stage-card-v2-move {
        display: none;
    }

    /* Tabs scroll on phone */
    .client-tabs {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .client-tab {
        flex-shrink: 0;
    }

    /* Dashboard single column on phone */
    .dashboard-cards {
        grid-template-columns: 1fr !important;
    }
}

/* Back to marketplace button */
.topnav-site-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.topnav-site-link:hover {
    color: var(--text-primary);
    border-color: var(--text-tertiary);
    background: var(--bg-hover);
}
.topnav-site-link svg {
    flex-shrink: 0;
}
@media (max-width: 480px) {
    .topnav-site-link span { display: none; }
}
