/* ── InvenFact v2 - Apple Design System Styles ──────────────────── */
:root {
    --primary: #007AFF;
    --primary-dark: #0062CC;
    --primary-light: #E8F0FE;
    --success: #34C759;
    --success-dark: #248A3D;
    --warning: #FF9500;
    --warning-dark: #C77800;
    --danger: #FF3B30;
    --danger-dark: #C62828;
    --gray-50: #FBFBFD;
    --gray-100: #F5F5F7;
    --gray-200: #E8E8ED;
    --gray-300: #D2D2D7;
    --gray-400: #AEAEB2;
    --gray-500: #8E8E93;
    --gray-600: #636366;
    --gray-700: #48484A;
    --gray-800: #3A3A3C;
    --gray-900: #1D1D1F;
    --sidebar-width: 260px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-input: 10px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Screens ─────────────────────────────────────────────────────── */
.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* ── Login ────────────────────────────────────────────────────────── */
#login-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #F5F5F7 0%, #E8E8ED 100%);
}

.login-container {
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 44px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06), 0 0 0 0.5px rgba(0,0,0,0.05);
}

.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo h1 { font-size: 26px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.3px; }
.login-logo h1 span { color: var(--gray-500); font-weight: 400; font-size: 16px; }
.login-logo p { color: var(--gray-500); margin-top: 6px; font-size: 14px; }

.login-form .form-group { margin-bottom: 18px; }
.login-links { text-align: center; margin-top: 14px; }
.login-links a { color: var(--primary); text-decoration: none; font-size: 13px; font-weight: 500; }
.login-links a:hover { text-decoration: underline; }
.login-divider { text-align: center; margin: 24px 0; position: relative; }
.login-divider::before { content: ''; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--gray-200); }
.login-divider span { background: rgba(255,255,255,0.92); padding: 0 16px; position: relative; color: var(--gray-400); font-size: 13px; }

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--gray-900);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
    border-right: 1px solid var(--gray-200);
}

.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-width)); }

.sidebar-header {
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-header h2 { font-size: 17px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.2px; }

.sidebar-toggle {
    background: none; border: none; color: var(--gray-600); font-size: 20px; cursor: pointer;
    display: none;
}

.nav-menu {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 4px 12px;
}

.nav-menu a {
    display: block;
    padding: 8px 12px;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
    border-radius: 8px;
    margin-bottom: 2px;
}

.nav-menu a:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-menu a.active { background: var(--primary); color: white; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--gray-700);
}

/* ── Content ──────────────────────────────────────────────────────── */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
    background: var(--gray-100);
}

/* ── Forms ────────────────────────────────────────────────────────── */
label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--gray-600);
}

input, select, textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-input);
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
    background: white;
    color: var(--gray-900);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
}

input::placeholder, textarea::placeholder {
    color: var(--gray-400);
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    letter-spacing: -0.1px;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: var(--success-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: var(--warning-dark); }
.btn-outline { background: white; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; justify-content: center; }

.btn-google {
    background: white;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
    border-radius: var(--radius-input);
}
.btn-google:hover { background: var(--gray-50); }

.btn-group { display: flex; gap: 4px; flex-wrap: nowrap; white-space: nowrap; }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
    background: white;
    border-radius: var(--radius);
    border: none;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header h3 { font-size: 15px; font-weight: 600; color: var(--gray-900); letter-spacing: -0.1px; }

/* ── Stats Grid ──────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    border: none;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
}

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card .stat-label { font-size: 12px; color: var(--gray-500); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.3px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.5px; }
.stat-card .stat-sub { font-size: 12px; color: var(--gray-400); margin-top: 4px; }
.stat-card.warning { border-left: 4px solid var(--warning); }
.stat-card.success { border-left: 4px solid var(--success); }
.stat-card.primary { border-left: 4px solid var(--primary); }

/* ── Tables ──────────────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    padding: 10px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    color: var(--gray-500);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
    color: var(--gray-800);
}

tr:hover { background: var(--gray-50); }

/* ── Badge ────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.2px;
}

.badge-admin { background: #FFF3CD; color: #856404; }
.badge-usuario { background: var(--primary-light); color: var(--primary-dark); }
.badge-entrada { background: #D1F2E0; color: #1B7A3D; }
.badge-salida { background: #FFE0DE; color: #C62828; }
.badge-ajuste { background: #E0E7FF; color: #3730A3; }

/* ── Page Header ──────────────────────────────────────────────────── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h2 { font-size: 24px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.4px; }

/* ── Filters ──────────────────────────────────────────────────────── */
.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: end;
}

.filters .form-group { margin-bottom: 0; }
.filters input, .filters select { min-width: 180px; }

/* ── Upload Zone ──────────────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--gray-50);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: rgba(0,122,255,0.04);
}

.upload-zone input[type="file"] { display: none; }
.upload-zone p { color: var(--gray-500); margin-top: 8px; font-size: 14px; }

/* ── Image Preview ────────────────────────────────────────────────── */
.img-preview {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 1px solid var(--gray-200);
}

.img-thumb {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    object-fit: cover;
}

/* ── Modal ────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 80px rgba(0,0,0,0.16), 0 0 0 0.5px rgba(0,0,0,0.06);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.modal-close {
    background: var(--gray-100);
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--gray-500);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.modal-close:hover { background: var(--gray-200); }

.modal-body { padding: 24px; }
.modal-body .form-group { margin-bottom: 18px; }

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

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    animation: slideIn 0.3s ease;
    max-width: 400px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.toast-success { background: rgba(52,199,89,0.95); }
.toast-error { background: rgba(255,59,48,0.95); }
.toast-warning { background: rgba(255,149,0,0.95); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Pagination ──────────────────────────────────────────────────── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
}

.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--gray-200);
    background: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
    transition: all 0.15s ease;
}

.pagination button:hover { background: var(--gray-50); }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination span { font-size: 13px; color: var(--gray-500); }

/* ── AI Results ──────────────────────────────────────────────────── */
.ai-result {
    border: none;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    background: white;
    box-shadow: var(--shadow-sm);
}

.ai-result h4 { margin-bottom: 8px; font-weight: 600; letter-spacing: -0.1px; }
.ai-result a { color: var(--primary); word-break: break-all; font-weight: 500; }

/* ── Empty State ──────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 15px; color: var(--gray-500); }

/* ── Loading ──────────────────────────────────────────────────────── */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--gray-400);
}

.spinner {
    width: 28px; height: 28px;
    border: 2.5px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar-toggle { display: block; }
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 100;
        margin-left: calc(-1 * var(--sidebar-width));
    }
    .sidebar.open { margin-left: 0; }
    .content { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .filters { flex-direction: column; }
    .filters input, .filters select { min-width: 100%; }
    .mobile-menu-btn {
        position: fixed;
        top: 12px; left: 12px;
        z-index: 99;
        background: white;
        color: var(--gray-900);
        border: 1px solid var(--gray-200);
        border-radius: var(--radius-sm);
        padding: 8px 12px;
        font-size: 18px;
        cursor: pointer;
        box-shadow: var(--shadow-sm);
    }
}

/* ── Form grid ────────────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
}

/* ── Misc ─────────────────────────────────────────────────────────── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.money { font-family: 'SF Mono', ui-monospace, 'Menlo', monospace; letter-spacing: -0.3px; }
