/**
 * App Shell Styles — Contract Box Realty
 * Layout: sidebar + content area.
 * Mobile: sidebar collapses to bottom tab bar.
 */

/* ── App Wrapper ─────────────────────────────────────────────────────────── */
.app-wrapper {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-page);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.app-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--primary-dark);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 200;
    transition: width var(--t-normal);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-brand-text {
    font-size: .8rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    letter-spacing: .02em;
}

.sidebar-brand-sub {
    font-size: .7rem;
    font-weight: 400;
    color: rgba(255,255,255,0.5);
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.nav-section-label {
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.3);
    padding: 12px 18px 4px;
    margin-top: 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    margin: 0 8px;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    color: rgba(255,255,255,0.65);
    cursor: pointer;
    border: none;
    background: none;
    width: calc(100% - 16px);
    text-align: left;
    transition: background var(--t-fast), color var(--t-fast);
    white-space: nowrap;
    overflow: hidden;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.9);
}

.nav-item.active {
    background: rgba(201, 168, 76, 0.18);
    color: var(--accent);
    font-weight: 600;
}

.nav-item.active .nav-icon { color: var(--accent); }

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-label { flex: 1; }

.nav-badge {
    background: var(--accent);
    color: #1a1a1a;
    font-size: .65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Sidebar bottom: user info */
.sidebar-footer {
    padding: 12px 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--t-fast);
}

.sidebar-user:hover { background: rgba(255,255,255,0.08); }

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.user-info-name {
    font-size: .8rem;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info-role {
    font-size: .7rem;
    color: rgba(255,255,255,0.4);
    text-transform: capitalize;
}

/* ── Content Area ────────────────────────────────────────────────────────── */
.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* Top header bar */
.app-header {
    height: 52px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px 0 20px;
    gap: 10px;
    flex-shrink: 0;
}

.header-title {
    font-size: .95rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Notification bell */
.notif-btn {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--text-secondary);
    transition: background var(--t-fast);
}
.notif-btn:hover { background: var(--bg-hover); }

.notif-count {
    position: absolute;
    top: 3px;
    right: 3px;
    background: var(--error);
    color: #fff;
    font-size: .6rem;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}
.notif-count.visible { display: flex; }

/* User menu button in header (fallback for mobile) */
.header-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    transition: background var(--t-fast);
    font-size: .85rem;
    color: var(--text-primary);
}
.header-user-btn:hover { background: var(--bg-hover); }

/* Dropdown menu */
.dropdown {
    position: relative;
}
.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 4px 0;
    z-index: 500;
    display: none;
}
.dropdown.open .dropdown-menu { display: block; animation: fadeIn 0.15s ease; }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    font-size: .875rem;
    color: var(--text-primary);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: background var(--t-fast);
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Main Content / Tab Panels ───────────────────────────────────────────── */
.app-main {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-panel {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
.tab-panel.active { display: flex; }

/* Module toolbar — sticky at top of each panel */
.module-toolbar {
    padding: 10px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    flex-wrap: wrap;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.toolbar-separator {
    width: 1px;
    height: 22px;
    background: var(--border);
    flex-shrink: 0;
}

/* Module scrollable body */
.module-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
}

/* Panel header (title + description inside panel) */
.panel-header {
    padding: 20px 20px 0;
}
.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.panel-header p {
    font-size: .85rem;
    color: var(--text-muted);
    margin: 0;
}

/* ── Search & Filter Controls ────────────────────────────────────────────── */
.search-input {
    height: 34px;
    padding: 0 12px 0 30px;
    background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7c8e' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 9px center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: .875rem;
    color: var(--text-primary);
    width: 220px;
    transition: border-color var(--t-fast), width var(--t-fast);
}
.search-input:focus {
    outline: none;
    border-color: var(--border-focus);
    width: 260px;
}
.search-input::placeholder { color: var(--text-muted); }

.filter-select {
    height: 34px;
    padding: 0 28px 0 10px;
    background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath fill='%236b7c8e' d='M6 7L0 0h12z'/%3E%3C/svg%3E") no-repeat right 9px center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: .875rem;
    color: var(--text-primary);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color var(--t-fast);
}
.filter-select:focus {
    outline: none;
    border-color: var(--border-focus);
}

/* App-level button sizes */
.btn-sm {
    height: 34px;
    padding: 0 14px;
    font-size: .85rem;
    width: auto;
}

.btn-add {
    height: 34px;
    padding: 0 14px;
    font-size: .85rem;
    width: auto;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius);
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--t-fast);
    white-space: nowrap;
}
.btn-add:hover { background: var(--primary-dark); }
.btn-add:disabled { opacity: .55; cursor: not-allowed; }

.btn-outline {
    height: 34px;
    padding: 0 14px;
    font-size: .85rem;
    width: auto;
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--t-fast);
    white-space: nowrap;
}
.btn-outline:hover { background: var(--bg-hover); }

.btn-danger-outline {
    height: 34px;
    padding: 0 14px;
    font-size: .85rem;
    width: auto;
    background: transparent;
    color: var(--error-text);
    border: 1.5px solid var(--error);
    border-radius: var(--radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--t-fast);
    white-space: nowrap;
}
.btn-danger-outline:hover { background: var(--error-bg); }

/* ── Toast Notifications ─────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    min-width: 280px;
    max-width: 380px;
    padding: 12px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: .9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: all;
    animation: slideInRight 0.2s ease;
    border-left: 4px solid;
}

.toast-success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success);
}
.toast-error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: var(--error);
}
.toast-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-color: var(--warning);
}
.toast-info {
    background: var(--info-bg);
    color: var(--info-text);
    border-color: var(--info);
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ── Loading Overlay ─────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-page);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    transition: opacity var(--t-normal);
}
.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

.loading-text {
    font-size: .9rem;
    color: var(--text-muted);
}

/* ── Dashboard ───────────────────────────────────────────────────────────── */
.dashboard-body {
    padding: 24px 20px;
    overflow-y: auto;
    flex: 1;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-sub {
    font-size: .78rem;
    color: var(--text-muted);
}

.stat-card.accent .stat-value { color: var(--accent); }
.stat-card.success .stat-value { color: var(--success-text); }
.stat-card.info    .stat-value { color: var(--info-text); }

/* Phase progress bar on dashboard */
.phase-breakdown {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
}

.phase-breakdown h3 {
    font-size: .85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.phase-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.phase-bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: .85rem;
}

.phase-bar-label {
    width: 140px;
    flex-shrink: 0;
    color: var(--text-secondary);
    font-weight: 500;
}

.phase-bar-track {
    flex: 1;
    height: 8px;
    background: var(--bg-hover);
    border-radius: 4px;
    overflow: hidden;
}

.phase-bar-fill {
    height: 100%;
    background: var(--primary-light);
    border-radius: 4px;
    transition: width var(--t-slow);
}

.phase-bar-count {
    width: 30px;
    text-align: right;
    color: var(--text-muted);
    font-size: .8rem;
    flex-shrink: 0;
}

/* ── Mobile (≤768px) ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-sidebar {
        display: none;
    }

    .app-wrapper {
        flex-direction: column;
    }

    .app-content {
        height: 100vh;
    }

    .app-main {
        margin-bottom: 60px; /* room for bottom nav */
    }

    .bottom-nav {
        display: flex;
    }

    .search-input:focus { width: 180px; }
    .search-input { width: 140px; }
}

/* Bottom nav — mobile only */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    z-index: 300;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.bottom-nav-inner {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 4px;
    min-width: max-content;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 64px;
    height: 100%;
    padding: 0 4px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: .65rem;
    transition: color var(--t-fast);
}

.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item .bn-icon { font-size: 18px; }

/* ── Dark mode adjustments ───────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    .app-sidebar {
        background: #0f1923;
        border-right: 1px solid #1a2535;
    }

    .sidebar-brand {
        border-bottom-color: #1a2535;
    }

    .search-input {
        background-color: var(--bg-input);
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%234a5568' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
    }

    .filter-select {
        background-color: var(--bg-input);
    }
}
