/* ==========================================================================
   Base styles & Variables
   ========================================================================== */
   :root {
    /* Brand Colors */
    --primary: #007AFF;
    --primary-hover: #0056b3;
    --secondary: #5AC8FA;
    --dark: #1C1C1E;
    --bg-color: #F7F9FC;
    --sidebar-bg: #FFFFFF;
    --content-bg: #FFFFFF;
    
    /* Typography */
    --text-main: #333333;
    --text-muted: #8E8E93;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    
    /* Effects */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.08);
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    /* Layout */
    --sidebar-width: 250px;
    --sidebar-collapsed: 80px;
    --header-height: 70px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    overflow: hidden; /* Stop whole body scrolling, scroll in main-content instead */
}

/* ==========================================================================
   Layout Shell
   ========================================================================== */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid rgba(0,0,0,0.03);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
}

.logo ion-icon {
    font-size: 1.75rem;
    padding: 6px;
    background: rgba(0, 122, 255, 0.1);
    border-radius: var(--radius-md);
}

.nav-links {
    list-style: none;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.nav-links a ion-icon {
    font-size: 1.4rem;
}

.nav-links a:hover {
    background-color: rgba(0, 122, 255, 0.05);
    color: var(--primary);
    transform: translateX(4px);
}

.nav-links a.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.sidebar-footer {
    padding: 24px 16px;
    border-top: 1px solid rgba(0,0,0,0.03);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.user-chip:hover {
    background: rgba(0,0,0,0.03);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.user-grade {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background-color: var(--bg-color);
}

.top-header {
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    z-index: 10;
}

.top-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark);
}

.header-actions {
    display: flex;
    gap: 16px;
}

.icon-btn {
    background: white;
    border: 1px solid rgba(0,0,0,0.05);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-main);
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.icon-btn:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
    border-color: var(--primary);
}

.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    /* Smooth fade in for views */
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Component: Cards & Grids
   ========================================================================== */
.view-title {
    margin-bottom: 24px;
    font-size: 1.2rem;
    color: var(--text-muted);
    font-weight: 500;
}

.grid-layout {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.card {
    background: var(--content-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
    border: 1px solid rgba(0,0,0,0.03);
    cursor: pointer;
}

.card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-md);
}

.card-img {
    width: 100%;
    height: 180px;
    background-color: var(--bg-color);
    position: relative;
    overflow: hidden;
}

.card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.card:hover .card-img img {
    transform: scale(1.05);
}

.card-body {
    padding: 20px;
}

.card-title {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--dark);
}

.card-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-exchange {
    background: rgba(0, 122, 255, 0.1);
    color: var(--primary);
}

.badge-complete {
    background: rgba(52, 199, 89, 0.1);
    color: #34C759;
}

/* Common Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 122, 255, 0.3);
}

/* Split View (Chat) */
.split-view {
    display: flex;
    background: var(--content-bg);
    border-radius: var(--radius-lg);
    height: calc(100vh - var(--header-height) - 64px);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.05);
}

.split-list {
    width: 320px;
    border-right: 1px solid rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

.split-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #FAFAFA;
}

/* Responsive */
@media (max-width: 768px) {
    .app-layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        position: fixed;
        bottom: 0;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid rgba(0,0,0,0.05);
        padding: 0;
        z-index: 1000;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .sidebar-header, .sidebar-footer { display: none; }
    .nav-links {
        flex-direction: row;
        padding: 10px;
        justify-content: space-around;
    }
    .nav-links a {
        flex-direction: column;
        gap: 4px;
        font-size: 0.7rem;
        padding: 8px;
    }
    .nav-links a.active {
        box-shadow: none;
        background: transparent;
        color: var(--primary);
    }
    .nav-links a:hover {
        transform: none;
    }
    .main-content {
        height: 100vh;
        padding-bottom: 70px;
    }
    .top-header {
        padding: 0 20px;
    }
    .view-container {
        padding: 20px;
    }
    .grid-layout {
        grid-template-columns: 1fr;
    }
    .split-view {
        flex-direction: column;
    }
    .split-list { width: 100%; height: 30%; border-right: none; border-bottom: 1px solid #eee; }
    .split-detail { height: 70%; }
}

/* ==========================================================================
   Modals & Toasts
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-md);
    transform: translateY(20px);
    animation: slideUp 0.3s forwards;
}

@keyframes slideUp {
    to { transform: translateY(0); }
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: var(--radius-md);
    outline: none;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
}

.toast-container {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--dark);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transform: translateY(20px);
    animation: toastIn 0.3s forwards, toastOut 0.3s forwards 2.7s;
}

@keyframes toastIn {
    to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateY(-20px); }
}
