@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700;800;900&display=swap');

:root {
    --bg-base: #f8fafc;
    --bg-card: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --border-color: rgba(15, 23, 42, 0.08);
    --accent: #4f46e5;
    --accent-glow: rgba(79, 70, 229, 0.25);
    --gold: #f59e0b;
    --green: #10b981;
    --red: #ef4444;
    --shadow-sm: 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── LOGIN SCREEN ── */
#login-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-top: 4px solid var(--accent);
    border-radius: 28px;
    padding: 48px 36px;
    width: 100%;
    max-width: 420px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
}
.login-card h1 { font-size: 36px; font-weight: 900; letter-spacing: -1.5px; }
.login-card h1 span { color: var(--accent); }
.login-card p { color: var(--text-muted); font-size: 14px; margin: 8px 0 32px; letter-spacing: 2px; font-weight: 700; text-transform: uppercase; }
.inp {
    width: 100%;
    padding: 18px 20px;
    background: #f1f5f9;
    border: 1.5px solid transparent;
    border-radius: 16px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
    outline: none;
    margin-bottom: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.inp::placeholder { color: #94a3b8; }
.inp:focus { 
    background: #ffffff; 
    border-color: var(--accent); 
    box-shadow: 0 0 0 4px var(--accent-glow); 
}
.btn-primary {
    width: 100%;
    padding: 18px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 16px;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px var(--accent-glow);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 16px var(--accent-glow); }
.btn-primary:active { transform: translateY(0) scale(0.98); }

/* ── APP LAYOUT ── */
#app {
    display: none;
    height: 100vh;
    flex-direction: column;
}

header {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}
.hdr-left { display: flex; align-items: center; gap: 12px; }
.hdr-back {
    background: #f1f5f9; border: none; color: var(--text-primary); font-size: 24px; cursor: pointer;
    display: none; width: 40px; height: 40px; border-radius: 12px; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.hdr-back:active { transform: scale(0.92); background: #e2e8f0; }
.hdr-title { font-size: 20px; font-weight: 800; display: none; color: var(--text-primary); }
.brand h1 { font-size: 22px; font-weight: 900; letter-spacing: -1px; }
.brand h1 span { color: var(--accent); }
.btn-logout { 
    background: #f1f5f9; border: none; font-size: 20px; color: var(--text-primary); cursor: pointer; 
    width: 44px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.btn-logout:active { transform: scale(0.92); background: #e2e8f0; }

.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-base);
}

/* ── NAVIGATION BAR ── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 9999;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
    flex-shrink: 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.03);
}
.nav-item {
    flex: 1;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-item i { font-size: 24px; margin-bottom: 4px; transition: transform 0.3s; }
.nav-item.active { color: var(--accent); }
.nav-item.active i { transform: translateY(-2px); }

/* ── SCREENS ── */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.screen.active { display: flex; animation: fadeIn 0.4s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 140px;
}
.pg-title { font-weight: 900; font-size: 24px; margin-bottom: 20px; color: var(--text-primary); letter-spacing: -0.5px; }

/* ── LIST CARDS ── */
.list-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 20px 24px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.list-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--border-color); }
.list-card:active { transform: translateY(0) scale(0.98); box-shadow: var(--shadow-sm); border-color: var(--accent); }
.lc-title { font-size: 18px; font-weight: 800; color: var(--text-primary); }
.lc-meta { font-size: 13px; color: var(--text-muted); margin-top: 6px; font-weight: 500; }
.badge {
    background: var(--accent-glow); color: var(--accent); font-size: 13px; font-weight: 800;
    padding: 6px 14px; border-radius: 20px; text-align: center;
}

/* ── ASSIGNMENT GROUPS (OLD) & GRID (NEW) ── */
.assign-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    align-content: start;
    padding-bottom: 20px;
}
.assign-card {
    background: var(--bg-card);
    border-radius: 20px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    height: max-content;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.assign-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.assign-card:active { border-color: var(--accent); transform: translateY(0) scale(0.96); }
.ac-img-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 5;
    background: #e2e8f0;
}
.assign-card img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.ac-info { padding: 12px 10px; text-align: center; }
.ac-title { display: block; font-size: 13px; font-weight: 800; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.ac-sub { font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.ac-summary { font-size: 10px; color: var(--accent); font-weight: 800; background: var(--accent-glow); padding: 4px; border-radius: 6px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.assign-group {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    margin-bottom: 20px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.ag-hdr {
    display: flex; align-items: center; gap: 16px; padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: #f8fafc;
}
.ag-img { width: 60px; height: 72px; border-radius: 12px; object-fit: cover; background: #e2e8f0; box-shadow: var(--shadow-sm); }
.ag-title { font-weight: 800; font-size: 18px; color: var(--text-primary); }
.ag-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; font-weight: 600; }
.ag-body { display: flex; flex-wrap: wrap; gap: 12px; padding: 20px; }
.sz-pill {
    background: #ffffff; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
    border-radius: 16px; padding: 12px 16px; display: flex; flex-direction: column; gap: 6px;
    flex: 1; min-width: 120px;
}
.sz-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; }
.sz-val { font-weight: 900; font-size: 18px; color: var(--text-primary); }
.sz-lim { font-size: 13px; color: var(--accent); font-weight: 800; background: var(--accent-glow); padding: 4px 10px; border-radius: 12px;}
.sz-del { background: #fee2e2; border: none; color: var(--red); font-size: 18px; cursor: pointer; padding: 6px; border-radius: 8px; transition: all 0.2s; display: flex; align-items: center; justify-content: center; }
.sz-del:active { transform: scale(0.9); }

/* ── FAB ── */
.fab {
    position: fixed;
    bottom: 96px; /* above bottom nav */
    right: 24px;
    width: 64px; height: 64px;
    background: var(--accent);
    color: #fff;
    border-radius: 20px;
    display: none;
    align-items: center; justify-content: center;
    font-size: 32px;
    box-shadow: 0 12px 24px var(--accent-glow);
    cursor: pointer;
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.fab:hover { transform: translateY(-4px) scale(1.02); box-shadow: 0 16px 32px var(--accent-glow); }
.fab:active { transform: translateY(0) scale(0.95); }
.fab.visible { display: flex; }

/* ── MODALS (FULL SCREEN) ── */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: var(--bg-base); z-index: 15000; flex-direction: column;
}
.modal-hdr {
    background: var(--bg-glass); backdrop-filter: blur(12px); padding: 16px 20px; display: flex; align-items: center; gap: 16px;
    border-bottom: 1px solid var(--border-color); flex-shrink: 0; box-shadow: var(--shadow-sm);
}
.btn-close { 
    background: #f1f5f9; border: none; color: var(--text-primary); font-size: 24px; cursor: pointer; 
    width: 44px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center; transition: all 0.2s;
    flex-shrink: 0;
}
.btn-close:active { transform: scale(0.92); background: #e2e8f0; }

.search-bar { 
    flex: 1; padding: 14px 20px; background: #ffffff; border: 1.5px solid var(--border-color); 
    border-radius: 16px; color: var(--text-primary); font-size: 16px; font-weight: 500; outline: none; 
    transition: all 0.3s; box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}
.search-bar::placeholder { color: #94a3b8; }
.search-bar:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow); }

.filter-btn {
    padding: 8px 16px;
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}
.filter-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 12px var(--accent-glow);
}
.filter-btn:active { transform: scale(0.96); }

/* ── CRITICAL: GALLERY GRID RULE ── */
.gal-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    align-content: start;
}
.gal-card {
    background: var(--bg-card);
    border-radius: 20px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    height: max-content; /* CRITICAL */
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.gal-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.gal-card:active { border-color: var(--accent); transform: translateY(0) scale(0.96); }
.gal-card img {
    width: 100%;
    aspect-ratio: 4 / 5; /* CRITICAL */
    object-fit: cover;
}
.gal-info { padding: 12px 10px; text-align: center; }
.gal-info b { display: block; font-size: 14px; font-weight: 800; margin-bottom: 4px; white-space: normal; line-height: 1.2; color: var(--text-primary); }
.gal-info span { font-size: 12px; color: var(--text-muted); font-weight: 600; }

/* ── BOTTOM SHEET MODAL ── */
.sheet-overlay {
    display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px); z-index: 18000; align-items: flex-end;
}
.sheet-content {
    background: var(--bg-card); border-radius: 32px 32px 0 0; padding: 32px 24px; width: 100%;
    padding-bottom: env(safe-area-inset-bottom, 32px);
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sz-hdr { display: flex; align-items: center; gap: 20px; margin-bottom: 32px; }
.sz-hdr img { width: 72px; height: 90px; border-radius: 16px; object-fit: cover; box-shadow: var(--shadow-md); }
.sz-hdr h3 { font-size: 24px; font-weight: 900; color: var(--text-primary); margin-bottom: 4px; }
.sz-hdr p { font-size: 15px; font-weight: 600; color: var(--text-muted); }

.size-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 32px; max-height: 45vh; overflow-y: auto; padding-right: 4px; }
.size-grid::-webkit-scrollbar { width: 6px; }
.size-grid::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
.sz-btn {
    padding: 16px; border: 2px solid #e2e8f0; background: #f8fafc;
    border-radius: 20px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.sz-btn.selected { border-color: var(--accent); background: var(--accent-glow); box-shadow: 0 4px 12px var(--accent-glow); }
.sz-lbl { font-size: 20px; font-weight: 800; color: var(--text-primary); }
.sz-btn.selected .sz-lbl { color: var(--accent); }

.qty-ctrl { display: none; align-items: center; gap: 8px; }
.sz-btn.selected .qty-ctrl { display: flex; }
.qty-ctrl button { background: #ffffff; color: var(--accent); border: 1.5px solid var(--accent); width: 32px; height: 32px; border-radius: 10px; font-weight: 900; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center; }
.qty-ctrl button:active { transform: scale(0.9); background: var(--accent); color: #fff; }
.qty-ctrl input { width: 40px; background: #ffffff; border: 1.5px solid transparent; color: var(--text-primary); font-weight: 900; font-size: 18px; text-align: center; outline: none; border-radius: 10px; height: 32px; }
.qty-ctrl input:focus { border-color: var(--accent); }

.btn-row { display: flex; gap: 16px; }
.btn-outline { flex: 1; padding: 18px; background: #f8fafc; border: 2px solid #e2e8f0; color: var(--text-primary); border-radius: 16px; font-weight: 800; font-size: 16px; cursor: pointer; transition: all 0.2s; }
.btn-outline:active { background: #e2e8f0; transform: scale(0.98); }
.btn-solid { flex: 2; padding: 18px; background: var(--accent); color: #fff; border: none; border-radius: 16px; font-weight: 800; font-size: 16px; cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 12px var(--accent-glow); }
.btn-solid:active { transform: scale(0.98); box-shadow: 0 2px 6px var(--accent-glow); }

/* ── LOADING & TOAST ── */
.loading { padding: 40px; text-align: center; color: var(--text-muted); font-weight: 700; font-size: 15px; }
#toast { position: fixed; top: 40px; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: #fff; padding: 14px 28px; border-radius: 30px; font-weight: 700; font-size: 15px; z-index: 30000; box-shadow: 0 10px 24px rgba(0,0,0,0.2); display: none; }
