@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #dc2626;
    --primary-hover: #b91c1c;
    --bg-main: #f9fafb;
    --bg-card: #ffffff;
    --sidebar-bg: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --radius: 10px;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
}

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar SaaS Style */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 1.5rem 0;
    flex-shrink: 0;
    z-index: 1001;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 0 1.5rem 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-header h2 {
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    border: none;
    margin: 0;
}

.sidebar-header span {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 0.75rem;
}

.nav-link {
    text-decoration: none;
    color: #4b5563;
    font-weight: 500;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 0.925rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-link:hover {
    background-color: #f3f4f6;
    color: var(--text-main);
}

.nav-link.active {
    background-color: #fef2f2;
    color: var(--primary);
    font-weight: 600;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2.5rem;
    overflow-y: auto;
}

.page-header {
    margin-bottom: 2.5rem;
}

.page-header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.page-header p {
    color: var(--text-muted);
    font-size: 1rem;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 2rem;
}

h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 1.25rem;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

/* Dynamic Items Section Redesign */
.items-section {
    margin-top: 1.5rem;
}

.items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.items-header label {
    margin-bottom: 0;
}

.card-inner {
    background: #ffffff;
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.item-row-grid {
    display: grid;
    grid-template-columns: 1.5fr 90px 2fr 130px auto;
    gap: 1rem;
    align-items: flex-end;
}

.no-margin {
    margin-bottom: 0 !important;
}

.unit-label {
    position: absolute;
    right: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
}

.file-upload-wrapper {
    position: relative;
}

.item-photo {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}

.file-upload-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-style: dashed !important;
}

.action-cell {
    display: flex;
    align-items: flex-end;
    padding-bottom: 2px;
}

@media (max-width: 900px) {
    .item-row-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .action-cell {
        justify-content: flex-end;
    }

    .app-layout {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        padding: 1rem;
        padding-top: 4.5rem;
        /* Space for mobile header */
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Adjust charts container for mobile */
    .card[style*="grid-template-columns: 1fr 1fr;"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
}

/* Mobile Header & Overlay injected via JS */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}

.mobile-header h2 {
    margin: 0;
    color: var(--primary);
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.05em;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.mobile-menu-btn:hover {
    background-color: #f3f4f6;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1000;
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 900px) {
    .mobile-header {
        display: flex;
    }

    /* Make the pie charts and bar charts stack on mobile in index.html */
    div[style*="display: grid; grid-template-columns: 1fr 1fr;"] {
        grid-template-columns: 1fr !important;
    }
}

.message {
    padding: 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    margin-top: 1rem;
    display: none;
}

.message.success {
    background-color: #dcfce7;
    color: #166534;
    display: block;
}

.message.error {
    background-color: #fee2e2;
    color: #991b1b;
    display: block;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.stat-title {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    display: block;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: #374151;
}

input,
textarea,
select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    background-color: #fff;
    transition: border-color 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    padding: 0;
    margin: 0;
    cursor: pointer;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    gap: 8px;
    border: 1px solid transparent;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-outline {
    background-color: white;
    color: #374151;
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background-color: #f9fafb;
    border-color: #d1d5db;
}

.btn-danger {
    background-color: #fee2e2;
    color: #b91c1c;
}

.btn-danger:hover {
    background-color: #fecaca;
}

.btn-process {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.btn-process:hover {
    background-color: #bfdbfe;
    color: #1e3a8a;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

/* Tables */
.table-container {
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

th {
    background: #f9fafb;
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #4b5563;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #fdfdfd;
}

/* Status Badges */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-pendiente {
    background-color: #fef3c7;
    color: #92400e;
}

.status-aprobado {
    background-color: #dcfce7;
    color: #166534;
}

.status-rechazado {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-en-proceso {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-completado {
    background-color: #f3f4f6;
    color: #374151;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1050;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    overflow-y: auto;
}

.modal-content {
    background: white;
    margin: 3rem auto;
    padding: 2rem;
    border-radius: 12px;
    width: 95%;
    max-width: 1000px;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 768px) {
    .modal-content {
        margin: 1rem auto;
        padding: 1rem;
        width: 98%;
    }
}

.close-btn {
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    font-size: 1.5rem;
    color: #9ca3af;
    cursor: pointer;
}

.close-btn:hover {
    color: #4b5563;
}

.modal-header {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.modal-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    background: #f9fafb;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.modal-meta p {
    font-size: 0.85rem;
}

.modal-meta strong {
    color: #6b7280;
    font-size: 0.7rem;
    text-transform: uppercase;
    display: block;
    margin-bottom: 2px;
}

.thumbnail {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
}

.modal-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    text-align: right;
}

/* Modal Styles for User Management */
.modal.active {
    display: flex !important;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 0;
}

/* Badge Styles for Roles */
.badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

/* Countdown Styles */
.countdown-danger {
    color: #dc2626;
    font-weight: 700;
    background: #fee2e2;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.countdown-normal {
    color: #166534;
    font-weight: 600;
    background: #dcfce7;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* Modal Table Inputs */
.compras-table input,
.compras-table select {
    padding: 4px 8px;
    font-size: 0.85rem;
}

#projectsTable {
    min-width: 1200px;
}

/* Welcome Menu */
.welcome-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.welcome-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
}

.welcome-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.welcome-card .icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: #fef2f2;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

.welcome-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}

/* =========================================================
   MODAL SELECTOR DE TIPO DE INSUMO
   ========================================================= */
.modal-tipo-insumo {
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.68);
    backdrop-filter: blur(6px);
    z-index: 1200;
}

.modal-tipo-insumo-content {
    max-width: 680px;
    width: 92%;
    margin: auto;
    padding: 2.25rem;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(226, 232, 240, 0.9);
    position: relative;
    animation: modalPopIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPopIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.tipo-modal-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.tipo-modal-icon-badge {
    width: 54px;
    height: 54px;
    background: #eff6ff;
    color: #2563eb;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.85rem;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.tipo-modal-icon-badge i {
    width: 28px;
    height: 28px;
}

.tipo-modal-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 0.4rem;
    letter-spacing: -0.02em;
}

.tipo-modal-header p {
    font-size: 0.875rem;
    color: #64748b;
    max-width: 520px;
    margin: 0 auto;
    line-height: 1.45;
}

.tipo-insumo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.85rem;
    max-height: 52vh;
    overflow-y: auto;
    padding: 4px;
    margin-bottom: 1.5rem;
}

.tipo-card {
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 1rem 1.1rem;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    position: relative;
    user-select: none;
}

.tipo-card:hover {
    border-color: #93c5fd;
    background-color: #f8fafc;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.08);
}

.tipo-card.selected {
    border-color: #2563eb;
    background-color: #eff6ff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.tipo-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tipo-card-body {
    flex: 1;
    min-width: 0;
}

.tipo-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: #1e293b;
    margin-bottom: 3px;
}

.tipo-card-desc {
    font-size: 0.775rem;
    color: #64748b;
    line-height: 1.35;
}

.tipo-card-check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    margin-top: 2px;
}

.tipo-card.selected .tipo-card-check {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}

.tipo-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1.25rem;
    border-top: 1px solid #f1f5f9;
    flex-wrap: wrap;
    gap: 12px;
}

.tipo-modal-hint {
    font-size: 0.8rem;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tipo-insumo-banner {
    border-radius: 12px;
    padding: 0.9rem 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    transition: all 0.2s ease;
}

@media (max-width: 640px) {
    .modal-tipo-insumo-content {
        padding: 1.5rem 1.25rem;
    }
    .tipo-insumo-grid {
        grid-template-columns: 1fr;
        max-height: 50vh;
    }
    .tipo-modal-footer {
        flex-direction: column-reverse;
        align-items: stretch;
    }
    .tipo-modal-footer > div:last-child {
        display: flex;
        flex-direction: column;
    }
}