/* ============================================
   Design System — 2026ingreso
   Modern Pharmacy Product Management
   ============================================ */

/* --- CSS Variables --- */
:root {
    /* Primary palette */
    --primary: #0f1b4c;
    --primary-light: #1a2d7a;
    --primary-dark: #080e2a;
    --primary-glow: rgba(15, 27, 76, 0.3);

    /* Accent colors */
    --accent-blue: #3b82f6;
    --accent-green: #10b981;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
    --accent-cyan: #06b6d4;

    /* Neutrals */
    --bg-body: #f0f2f7;
    --bg-card: #ffffff;
    --bg-card-alt: #f8fafc;
    --bg-hover: #f1f5f9;
    --bg-input: #f8fafc;
    --border: #e2e8f0;
    --border-focus: var(--accent-blue);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-on-dark: #ffffff;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

    /* Transitions */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --duration: 200ms;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* --- Glass Card --- */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: box-shadow var(--duration) var(--ease);
}

/* --- Header --- */
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, #2c3e8c 100%);
    padding: var(--space-md) var(--space-xl);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(15, 27, 76, 0.3);
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.header-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: var(--accent-cyan);
    backdrop-filter: blur(10px);
}

.header-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-on-dark);
    letter-spacing: -0.3px;
}

.header-subtitle {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
    font-weight: 400;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-blue) 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

.btn-glow {
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3); }
    50% { box-shadow: 0 2px 20px rgba(59, 130, 246, 0.5); }
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-danger-ghost {
    background: transparent;
    color: var(--accent-red);
    border: none;
    padding: 2px 4px;
    font-size: 0.75rem;
}

.btn-danger-ghost:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* --- Main Content --- */
.main-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--space-lg) var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* --- Context Bar --- */
.context-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-md) var(--space-lg);
}

.context-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.context-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.context-label i {
    color: var(--primary);
}

.context-info {
    margin-left: auto;
}

.input-with-btn {
    display: flex;
    gap: 4px;
}

/* --- Inputs --- */
.input-text,
.input-select {
    font-family: inherit;
    font-size: 0.85rem;
    padding: var(--space-sm) 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    transition: all var(--duration) var(--ease);
    outline: none;
    width: 100%;
}

.input-text:focus,
.input-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
    background: white;
}

.input-with-prefix {
    display: flex;
    align-items: stretch;
}

.input-prefix {
    display: flex;
    align-items: center;
    padding: 0 10px;
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.input-with-prefix .input-text {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

textarea.input-text {
    resize: vertical;
    min-height: 60px;
}

.text-center {
    text-align: center;
}

/* --- Search --- */
.search-container {
    display: flex;
    align-items: center;
    padding: 6px var(--space-md);
    gap: var(--space-sm);
}

.search-icon {
    color: var(--text-muted);
    font-size: 1rem;
}

.search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    padding: var(--space-sm) 0;
    color: var(--text-primary);
    outline: none;
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-spinner {
    color: var(--accent-blue);
    font-size: 1rem;
}

/* --- Badge --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-info {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-green);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent-orange);
}

/* --- Product Table --- */
.products-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.product-table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
}

.product-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    table-layout: fixed;
}

.product-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.product-table th {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 8px;
    border-bottom: 2px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.product-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-table tbody tr {
    transition: background var(--duration) var(--ease);
}

.product-table tbody tr:nth-child(even) {
    background: var(--bg-card-alt);
}

.product-table tbody tr:hover {
    background: #e8f4fd !important;
}

/* Column classes */
.col-lugar { width: 100px; }
.col-codigo { width: 90px; }
.col-producto { width: 230px; white-space: normal !important; }
.col-pres { width: 40px; text-align: center; }
.col-costo { width: 72px; text-align: center; }
.col-precio { width: 72px; text-align: center; }
.col-fecha { width: 80px; text-align: center; }
.col-stock { width: 60px; text-align: center; }
.col-iva { width: 35px; text-align: center; }
.col-acc { width: 38px; text-align: center; }

/* Cost/price column backgrounds */
th.bg-cost, td.bg-cost { background: rgba(219, 234, 254, 0.4) !important; }
th.bg-price, td.bg-price { background: rgba(220, 252, 231, 0.4) !important; }
th.bg-pres, td.bg-pres { background: rgba(248, 250, 252, 0.8) !important; }

/* --- Location Badge (in table) --- */
.lugar-badge {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 6px;
    margin-bottom: 3px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
}

.lugar-badge:hover {
    background: #e0e7ff;
    border-color: var(--accent-blue);
}

.lugar-badge.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.lugar-badge .lugar-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.lugar-badge .lugar-remove {
    color: var(--accent-red);
    cursor: pointer;
    padding: 0 2px;
    font-size: 0.65rem;
    opacity: 0.5;
    transition: opacity var(--duration);
}

.lugar-badge .lugar-remove:hover {
    opacity: 1;
}

.lugar-badge.active .lugar-remove {
    color: #fca5a5;
}

/* --- Inline Editable --- */
.cell-editable {
    cursor: pointer;
    position: relative;
    transition: background var(--duration) var(--ease);
    border-radius: 3px;
    padding: 2px 4px;
}

.cell-editable:hover {
    background: rgba(59, 130, 246, 0.06);
}

.cell-editable:hover::after {
    content: "✎";
    position: absolute;
    right: 2px;
    top: 1px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.inline-input {
    width: 100%;
    padding: 4px 6px;
    border: 2px solid var(--accent-blue);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
    background: white;
    animation: input-appear 150ms var(--ease);
}

@keyframes input-appear {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* Cost / price inputs in table */
.table-input {
    width: 100%;
    padding: 3px 4px;
    font-size: 0.82rem;
    font-family: inherit;
    border: 1px solid #ced4da;
    border-radius: 4px;
    text-align: center;
    outline: none;
    transition: all var(--duration) var(--ease);
    background: white;
}

.table-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* Disabled cost inputs (no location selected) */
.table-input.cost-input:disabled {
    background: repeating-linear-gradient(
        -45deg,
        #f8fafc,
        #f8fafc 3px,
        #f1f5f9 3px,
        #f1f5f9 6px
    );
    opacity: 0.5;
    cursor: not-allowed;
    color: var(--text-muted);
    border-color: #e2e8f0;
}

/* Presentation toggle */
.pres-toggle {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-green);
}

.units-input {
    width: 36px !important;
    padding: 2px !important;
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
    margin-top: 3px;
}

/* IVA toggle */
.iva-toggle {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-green);
}

/* Date cells */
.date-cell {
    font-size: 0.75rem;
    text-align: center;
}

.date-ingreso {
    background: #fff7ed;
    padding: 3px 4px;
    border-radius: 3px;
    margin-bottom: 2px;
    cursor: pointer;
    transition: background var(--duration);
}

.date-ingreso:hover { background: #fed7aa; }

.date-vencimiento {
    background: #fef2f2;
    padding: 3px 4px;
    border-radius: 3px;
    cursor: pointer;
    transition: background var(--duration);
}

.date-vencimiento:hover { background: #fecaca; }

/* Stock cell */
.stock-cell {
    font-weight: 700;
    color: var(--primary);
}

.stock-detail {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Product info */
.product-name {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.88rem;
    line-height: 1.3;
}

.product-generic {
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin-top: 2px;
}

.product-lab {
    display: inline-block;
    background: #e0e7ff;
    color: var(--primary-light);
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 600;
    margin-top: 3px;
}

.product-funcion {
    display: inline-block;
    background: #f3e8ff;
    color: var(--accent-purple);
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 20px;
    margin-top: 3px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Pagination --- */
.pagination-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) 0;
}

.page-btn {
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
}

.page-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.page-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 0 var(--space-sm);
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--space-xl) var(--space-md);
    overflow-y: auto;
    animation: fade-in 200ms var(--ease);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-container {
    width: 100%;
    max-width: 720px;
    border-radius: var(--radius-xl);
    animation: slide-up 300ms var(--ease);
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    color: white;
}

.modal-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.modal-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    font-size: 1.4rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration);
}

.modal-close:hover {
    background: rgba(255,255,255,0.25);
}

.modal-body {
    padding: var(--space-lg) var(--space-xl);
    max-height: 65vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    border-top: 1px solid var(--border);
}

/* --- Form Sections --- */
.form-section {
    margin-bottom: var(--space-lg);
}

.form-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-md);
    border-bottom: 2px solid #e0e7ff;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.form-grid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.form-grid.cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.span-2 {
    grid-column: span 2;
}

.form-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-label.required::after {
    content: " *";
    color: var(--accent-red);
}

.checkbox-group {
    display: flex;
    align-items: flex-end;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.cost-preview {
    background: #f0f4ff;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: auto;
}

.cost-preview i {
    color: var(--accent-orange);
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    min-width: 280px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    box-shadow: var(--shadow-lg);
    animation: toast-in 300ms var(--ease);
}

.toast.toast-out {
    animation: toast-out 300ms var(--ease) forwards;
}

.toast-success { background: var(--accent-green); }
.toast-error { background: var(--accent-red); }
.toast-info { background: var(--accent-blue); }
.toast-warning { background: var(--accent-orange); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* --- Loading State --- */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
    gap: var(--space-md);
}

.loading-state i {
    font-size: 2rem;
    color: var(--accent-blue);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
    gap: var(--space-sm);
}

.empty-state i {
    font-size: 2.5rem;
    color: var(--border);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .main-content {
        padding: var(--space-md);
    }

    .context-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .context-info {
        margin-left: 0;
    }

    .form-grid,
    .form-grid.cols-3,
    .form-grid.cols-4 {
        grid-template-columns: 1fr;
    }

    .form-group.span-2 {
        grid-column: span 1;
    }

    .modal-container {
        max-width: 100%;
    }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Row saving animation */
.row-saving {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.row-saved {
    animation: flash-green 600ms var(--ease);
}

@keyframes flash-green {
    0% { background: rgba(16, 185, 129, 0.2) !important; }
    100% { background: transparent; }
}

/* --- Product Update Status Highlighting --- */
/* Updated products (dates >= 2025): pastel orange */
.row-updated,
.row-updated td {
    background-color: #FFE0B2 !important;
}

.row-updated td input.table-input {
    background-color: #FFF3E0 !important;
}

/* Not updated products (no dates or dates < 2025): pastel blue */
.row-not-updated,
.row-not-updated td {
    background-color: #BBDEFB !important;
}

.row-not-updated td input.table-input {
    background-color: #E3F2FD !important;
}
