/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --info: #0891b2;
    --info-bg: #cffafe;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ===== NAVBAR ===== */
.navbar {
    background: var(--gray-900);
    color: white;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}
.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
}
.nav-brand {
    color: white;
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.nav-brand:hover { color: var(--gray-200); }
.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.nav-link {
    color: var(--gray-300);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: all 0.15s;
}
.nav-link:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-logout { color: #fca5a5; }
.nav-logout:hover { color: white; background: rgba(220,38,38,0.3); }
.nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
    padding-left: 1rem;
    border-left: 1px solid var(--gray-700);
}
.nav-username { color: var(--gray-300); font-size: 0.85rem; }
.nav-role-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-admin { background: #7c3aed; color: white; }
.badge-user { background: var(--gray-600); color: var(--gray-200); }
.nav-toggle { display: none; background: none; border: none; color: white; cursor: pointer; padding: 0.5rem; }

/* ===== LAYOUT ===== */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1rem; flex: 1; }

/* ===== ALERTS ===== */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}
.alert-success { background: var(--success-bg); color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: var(--danger-bg); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-bg); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--info-bg); color: #155e75; border: 1px solid #a5f3fc; }
.alert-close { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: inherit; opacity: 0.7; }
.alert-close:hover { opacity: 1; }

/* ===== CARDS ===== */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header h2 { font-size: 1.15rem; color: var(--gray-900); }
.card-body { padding: 1.25rem; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; color: white; }
.btn-outline {
    background: white;
    color: var(--gray-700);
    border-color: var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--gray-700); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
}
.form-control {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--gray-800);
    background: white;
    transition: border-color 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
textarea.form-control { min-height: 80px; resize: vertical; }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-hint { font-size: 0.8rem; color: var(--gray-500); margin-top: 0.25rem; }

/* ===== TABLES ===== */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.65rem 0.75rem; text-align: left; border-bottom: 1px solid var(--gray-200); }
th { background: var(--gray-50); font-weight: 600; font-size: 0.8rem; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.05em; }
td { font-size: 0.9rem; }
tr:hover td { background: var(--gray-50); }

/* ===== INVENTORY GRID ===== */
.inventory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.inv-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}
.inv-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.inv-card-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--gray-100);
    display: block;
}
.inv-card-img-placeholder {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    color: var(--gray-400);
    font-size: 3rem;
}
.inv-card-body { padding: 0.75rem 1rem; flex: 1; display: flex; flex-direction: column; }
.inv-card-id { font-size: 0.75rem; color: var(--gray-500); font-weight: 600; }
.inv-card-name { font-size: 1rem; font-weight: 600; color: var(--gray-900); margin: 0.15rem 0; }
.inv-card-origin { font-size: 0.8rem; color: var(--gray-500); }
.inv-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--gray-100);
    margin-top: auto;
}
.inv-card-value { font-weight: 700; color: var(--gray-900); }
.status-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
}
.status-active { background: var(--success-bg); color: #166534; }
.status-sold { background: var(--danger-bg); color: #991b1b; }
.status-archive { background: var(--gray-200); color: var(--gray-600); }

/* ===== VIEW TOGGLE ===== */
.view-toggle { font-size: 1.1rem; padding: 0.5rem 0.7rem; line-height: 1; }
.view-toggle.active { background: var(--primary); color: white; border-color: var(--primary); }
.view-toggle.active:hover { background: var(--primary-dark); color: white; }

/* ===== INVENTORY LIST ===== */
.inv-row { cursor: pointer; }
.inv-row:hover td { background: var(--primary-light); }
.inv-row-id { font-weight: 600; color: var(--gray-500); white-space: nowrap; }
.inv-row-name { font-weight: 600; color: var(--gray-900); }
.inv-row-value { font-weight: 700; white-space: nowrap; }
.inv-row-date { white-space: nowrap; color: var(--gray-500); font-size: 0.85rem; }

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    align-items: center;
}
.filter-bar .form-control { width: auto; min-width: 160px; }
.search-input { min-width: 250px !important; }

/* ===== PICTURE GALLERY ===== */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}
.gallery-item {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid var(--gray-200);
    background: var(--gray-100);
}
.gallery-item.is-default { border-color: var(--primary); }
.gallery-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    cursor: pointer;
}
.gallery-actions {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    background: white;
    justify-content: center;
}
.gallery-default-label {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-weight: 600;
}

/* ===== LOGIN PAGE ===== */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--gray-900) 0%, #1e3a5f 100%);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 2.5rem 2rem;
    margin: 1rem;
}
.login-card h1 {
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    color: var(--gray-900);
}
.login-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}
.login-btn {
    width: 100%;
    padding: 0.7rem;
    font-size: 1rem;
    justify-content: center;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.page-header h1 { font-size: 1.5rem; color: var(--gray-900); }

/* ===== DETAIL PAGE ===== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.detail-label { font-size: 0.8rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.05em; }
.detail-value { font-size: 1rem; color: var(--gray-900); margin-top: 0.15rem; }
.detail-section { margin-bottom: 1.5rem; }
.detail-main-img {
    width: 100%;
    max-height: 500px;
    object-fit: contain;
    border-radius: var(--radius);
    background: var(--gray-100);
}

/* ===== MODAL ===== */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-backdrop.active { display: flex; }
.modal-img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius); }

/* ===== PAGINATION ===== */
.pagination { display: flex; gap: 0.35rem; justify-content: center; margin-top: 1.5rem; }
.pagination a, .pagination span {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    color: var(--gray-600);
}
.pagination a:hover { background: var(--gray-100); color: var(--gray-800); }
.pagination .active { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== FOOTER ===== */
.footer {
    text-align: center;
    padding: 1rem;
    color: var(--gray-400);
    font-size: 0.8rem;
    border-top: 1px solid var(--gray-200);
    margin-top: 2rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .nav-links { 
        display: none; 
        position: absolute; 
        top: 56px; 
        left: 0; 
        right: 0; 
        background: var(--gray-900);
        flex-direction: column; 
        padding: 0.5rem; 
        border-top: 1px solid var(--gray-700);
    }
    .nav-links.active { display: flex; }
    .nav-toggle { display: block; }
    .nav-user { margin-left: 0; padding-left: 0; border-left: none; padding-top: 0.5rem; border-top: 1px solid var(--gray-700); }
    .form-row { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .filter-bar .form-control { width: 100%; }
    .search-input { min-width: auto !important; }
    .page-header { flex-direction: column; align-items: flex-start; }
}
