/* ========================================
   LAYOUT & NAVIGATION
   ======================================== */

/* ---------- APP CONTAINER ---------- */
#app {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

#main-content {
    flex: 1;
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
    animation: fadeIn var(--transition-slow) ease;
}

/* ---------- PAGE LAYOUTS ---------- */
.page {
    padding: var(--space-4);
    max-width: var(--max-content-width);
    margin: 0 auto;
}

.page-header {
    margin-bottom: var(--space-6);
}

.page-title {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    margin-bottom: var(--space-1);
    word-break: break-word;
    overflow-wrap: break-word;
}

.page-subtitle {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

/* ---------- HEADER ---------- */
.header {
    height: var(--header-height);
    padding: 0 var(--space-4);
    padding-top: var(--safe-top);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.header-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ---------- BOTTOM NAVIGATION ---------- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    padding-bottom: var(--safe-bottom);
    background: var(--color-bg-elevated);
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: stretch;
    z-index: var(--z-sticky);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    transition: all var(--transition-fast);
    position: relative;
}

.nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 48px;
    height: 3px;
    background: var(--gradient-primary);
    border-radius: 0 0 var(--radius-full) var(--radius-full);
    transition: transform var(--transition-base);
}

.nav-item:hover {
    color: var(--color-text-secondary);
}

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

.nav-item.active::before {
    transform: translateX(-50%) scaleX(1);
}

.nav-icon {
    width: 24px;
    height: 24px;
    stroke-width: 1.5;
}

/* ---------- LOADER ---------- */
.loader-container {
    position: fixed;
    inset: 0;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
}

.loader-content {
    text-align: center;
}

.loader-logo {
    margin-bottom: var(--space-4);
    color: var(--color-primary);
}

.loader-text {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    margin-bottom: var(--space-1);
}

.loader-subtext {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

/* ---------- TOAST NOTIFICATIONS ---------- */
.toast-container {
    position: fixed;
    top: calc(var(--safe-top) + var(--space-4));
    left: var(--space-4);
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    box-shadow: var(--shadow-lg);
    animation: slideUp var(--transition-spring) ease;
    pointer-events: auto;
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: var(--font-medium);
    margin-bottom: var(--space-1);
}

.toast-message {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
}

.toast-close {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    cursor: pointer;
    flex-shrink: 0;
}

.toast-close:hover {
    color: var(--color-text);
}

.toast.success { border-left: 3px solid var(--color-success); }
.toast.success .toast-icon { color: var(--color-success); }

.toast.error { border-left: 3px solid var(--color-error); }
.toast.error .toast-icon { color: var(--color-error); }

.toast.warning { border-left: 3px solid var(--color-warning); }
.toast.warning .toast-icon { color: var(--color-warning); }

.toast.info { border-left: 3px solid var(--color-info); }
.toast.info .toast-icon { color: var(--color-info); }

/* ---------- MODALS ---------- */
.modal-container {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-4);
    padding-bottom: var(--safe-bottom);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal {
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    background: var(--color-bg-elevated);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    overflow: hidden;
    animation: slideUp var(--transition-spring) ease;
}

@media (min-width: 640px) {
    .modal-container {
        align-items: center;
    }
    
    .modal {
        border-radius: var(--radius-2xl);
    }
}

.modal-header {
    padding: var(--space-5) var(--space-5) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 0;
}

.modal-body {
    padding: var(--space-5);
    overflow-y: auto;
    max-height: calc(90vh - 140px);
}

.modal-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

/* ---------- OFFLINE INDICATOR ---------- */
.offline-indicator {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + var(--space-4));
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-warning-muted);
    color: var(--color-warning);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-sticky);
    animation: slideUp var(--transition-spring) ease;
}

/* ---------- GRID LAYOUTS ---------- */
.grid {
    display: grid;
    gap: var(--space-4);
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 640px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---------- FLEX UTILITIES ---------- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.flex-1 { flex: 1; }

/* ---------- SPACING UTILITIES ---------- */
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

/* ---------- TEXT UTILITIES ---------- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--text-sm); }
.text-lg { font-size: var(--text-lg); }
.text-muted { color: var(--color-text-muted); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
