/* =============================================================================
   Albaranes de Consigna — Venair
   Design System: Inter / Black-White / Trust & Authority / Minimal
   ============================================================================= */

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

/* --- Tokens --- */
:root {
    --color-black: #000000;
    --color-white: #ffffff;
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-surface-alt: #f8f9fa;
    --color-border: #e2e5e9;
    --color-border-light: #eef0f2;
    --color-text: #1a1a1a;
    --color-text-secondary: #6b7280;
    --color-text-muted: #9ca3af;
    --color-primary: #000000;
    --color-primary-hover: #1a1a1a;
    --color-accent: #2563eb;
    --color-accent-light: #eff6ff;
    --color-success: #059669;
    --color-success-light: #ecfdf5;
    --color-warning: #d97706;
    --color-danger: #dc2626;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
    --shadow-xl: 0 16px 48px rgba(0,0,0,0.10);

    --transition: 200ms ease;
    --transition-slow: 350ms ease;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    background-image: url('/static/img/background.jpg');
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 0;
}

/* --- App Container --- */
.app-container {
    width: 100%;
    max-width: 1100px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 24px;
}

/* --- Header --- */
.app-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    padding: 16px 24px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
}

.header-left { justify-self: start; }
.header-center { justify-self: center; text-align: center; }
.header-right { justify-self: end; }

.logo { height: 32px; width: auto; }

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-black);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.header-subtitle {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-weight: 400;
}

.clock {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    font-weight: 700;
    background: var(--color-black);
    color: var(--color-white);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    letter-spacing: 1.5px;
}

/* --- Steps Bar --- */
.steps-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 20px;
    padding: 16px 24px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
    transition: all var(--transition);
    cursor: default;
}

.step.active {
    color: var(--color-black);
    background: var(--color-surface-alt);
}

.step.completed {
    color: var(--color-success);
}

.step-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    border: 2px solid var(--color-border);
    color: var(--color-text-muted);
    transition: all var(--transition);
}

.step.active .step-number {
    background: var(--color-black);
    color: var(--color-white);
    border-color: var(--color-black);
}

.step.completed .step-number {
    background: var(--color-success);
    color: var(--color-white);
    border-color: var(--color-success);
}

.step-connector {
    width: 40px;
    height: 2px;
    background: var(--color-border);
    transition: background var(--transition);
}

.step-connector.active {
    background: var(--color-black);
}

/* --- Cards --- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--color-border-light);
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-black);
    letter-spacing: -0.01em;
}

.card-body {
    padding: 24px;
}

/* --- Step sections --- */
.step-section {
    display: none;
    animation: fadeSlideIn 0.35s ease;
}

.step-section.active {
    display: block;
}

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Search Box --- */
.search-box {
    position: relative;
    width: 320px;
}

.search-box-full {
    width: 100%;
    margin-bottom: 16px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--color-text-muted);
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 40px;
    font-size: 0.875rem;
    font-family: var(--font-family);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    transition: all var(--transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--color-black);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

.search-box input::placeholder {
    color: var(--color-text-muted);
}

/* --- Data Table --- */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
    background: var(--color-surface-alt);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    user-select: none;
}

.data-table th.col-right,
.data-table td.col-right {
    text-align: right;
}

.data-table th.col-check {
    width: 44px;
    text-align: center;
}

.data-table th.col-sortable {
    cursor: pointer;
    transition: color var(--transition);
}

.data-table th.col-sortable:hover {
    color: var(--color-black);
}

.sort-arrow { font-size: 0.7rem; opacity: 0.4; }
.col-sortable.asc .sort-arrow::after { content: " \u25B2"; opacity: 1; }
.col-sortable.desc .sort-arrow::after { content: " \u25BC"; opacity: 1; }

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border-light);
    color: var(--color-text);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--color-accent-light);
}

.data-table tbody tr.selected {
    background: #f0f7ff;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table.compact th,
.data-table.compact td {
    padding: 8px 12px;
    font-size: 0.8rem;
}

/* Checkbox styling */
.data-table input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-black);
    cursor: pointer;
}

.col-check { text-align: center !important; }

/* Qty input in stock table */
.qty-input {
    width: 64px;
    padding: 4px 8px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    border: 2px solid var(--color-black);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    color: var(--color-text);
    transition: all var(--transition);
}

.qty-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}

/* Hide spinner arrows */
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.qty-input { -moz-appearance: textfield; }

/* --- Loader --- */
.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-black);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px;
    color: var(--color-text-muted);
}

.empty-state svg {
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.9rem;
}

/* --- Selection Bar --- */
.selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    margin-top: 16px;
    background: var(--color-black);
    color: var(--color-white);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    animation: fadeSlideIn 0.25s ease;
}

.selection-bar strong {
    font-weight: 700;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--color-white);
    color: var(--color-black);
}

.btn-primary:hover {
    background: var(--color-surface-alt);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.btn-ghost:hover {
    background: var(--color-surface-alt);
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
    border-radius: var(--radius-md);
    background: var(--color-black);
    color: var(--color-white);
}

.btn-lg:hover {
    background: #1a1a1a;
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

/* --- Supplier Grid --- */
.prov-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.prov-card {
    padding: 16px;
    border: 2px solid var(--color-border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    background: var(--color-surface);
}

.prov-card:hover {
    border-color: var(--color-text-muted);
    box-shadow: var(--shadow-sm);
}

.prov-card.selected {
    border-color: var(--color-black);
    background: var(--color-surface-alt);
    box-shadow: 0 0 0 1px var(--color-black);
}

.prov-card-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-text);
    margin-bottom: 4px;
}

.prov-card-id {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-family: 'Courier New', monospace;
}

.prov-card-address {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin-top: 6px;
}

/* --- Summary Grid --- */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--color-surface-alt);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    border: 1px solid var(--color-border-light);
}

.summary-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    font-weight: 600;
    margin-bottom: 6px;
}

.summary-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}

/* --- Preview Section --- */
.preview-section {
    margin-bottom: 20px;
}

.preview-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
}

/* --- Form --- */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--font-family);
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    resize: vertical;
    transition: all var(--transition);
}

.form-group textarea:focus {
    outline: none;
    border-color: var(--color-black);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

.form-group textarea::placeholder,
.form-group input::placeholder {
    color: var(--color-text-muted);
}

.form-group input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    font-family: var(--font-family);
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    transition: all var(--transition);
}

.form-group input[type="text"]:focus {
    outline: none;
    border-color: var(--color-black);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

.form-section {
    margin-bottom: 24px;
    padding: 20px;
    background: var(--color-surface-alt);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-light);
}

.form-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

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

/* --- Generate Actions --- */
.generate-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 8px;
}

/* --- Footer --- */
.app-footer {
    text-align: center;
    padding: 16px;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: auto;
}

/* --- Toast / notification --- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    background: var(--color-black);
    color: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 1000;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3.5s forwards;
}

.toast.toast-error {
    background: var(--color-danger);
}

.toast.toast-success {
    background: var(--color-success);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(8px); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-container { padding: 12px; }

    .app-header {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 8px;
    }
    .header-left, .header-center, .header-right { justify-self: center; }

    .steps-bar { gap: 0; padding: 12px 16px; }
    .step span { display: none; }
    .step-connector { width: 24px; }

    .card-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    .search-box { width: 100%; }

    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .prov-grid { grid-template-columns: 1fr; }

    .selection-bar {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .generate-actions {
        flex-direction: column;
    }

    .generate-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

/* --- Login Screen --- */
.login-screen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    background-image: url('/static/img/background.jpg');
    background-size: cover;
    background-position: center;
}

.login-screen.hidden { display: none; }

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 48px 40px;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.login-logo {
    height: 36px;
    margin-bottom: 24px;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-black);
    margin-bottom: 8px;
}

.login-card p {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    margin-bottom: 24px;
}

.login-card .btn-lg {
    width: 100%;
    justify-content: center;
}

/* --- User Bar --- */
.user-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* --- Notes section --- */
.notes-section {
    margin-bottom: 20px;
}

.notes-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.notes-textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--color-text);
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    resize: vertical;
    transition: border-color 0.15s;
    outline: none;
}

.notes-textarea:focus {
    border-color: var(--color-primary);
    background: var(--color-surface);
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
