/* styles.css */
@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400;1,700&family=Inter:wght@300;400;500;600;700&family=Playfair+Display:ital,wght@0,600;1,600&display=swap');

:root {
    --bg-gradient: radial-gradient(circle at top right, #0f172a, #020617);
    --primary: #8b5cf6;
    --primary-glow: rgba(139, 92, 246, 0.15);
    --secondary: #10b981;
    --secondary-glow: rgba(16, 185, 129, 0.15);
    --dark-panel: rgba(30, 41, 59, 0.45);
    --dark-panel-hover: rgba(30, 41, 59, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-focus: rgba(139, 92, 246, 0.4);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dark: #0f172a;
    --danger: #ef4444;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

/* App Layout Grid */
.app-container {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
    max-height: 100vh;
}

/* Navigation / Header */
header {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 2.2rem;
    height: 2.2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.logo-icon svg {
    color: #fff;
    width: 1.25rem;
    height: 1.25rem;
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(to right, #ffffff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text span {
    font-size: 0.75rem;
    color: var(--secondary);
    font-weight: 500;
    display: block;
    margin-top: -2px;
}

/* Main Workspace */
main {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    overflow: hidden;
}

@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
        overflow-y: auto;
    }
    .app-container {
        height: auto;
        max-height: none;
    }
}

/* Left Section: Controls and Uploader */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* Scrollbar Styles */
.left-panel::-webkit-scrollbar,
.editor-form::-webkit-scrollbar {
    width: 6px;
}
.left-panel::-webkit-scrollbar-track,
.editor-form::-webkit-scrollbar-track {
    background: transparent;
}
.left-panel::-webkit-scrollbar-thumb,
.editor-form::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
.left-panel::-webkit-scrollbar-thumb:hover,
.editor-form::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Card Styling (Glassmorphism) */
.glass-card {
    background: var(--dark-panel);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(16px);
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.glass-card:hover {
    background: var(--dark-panel-hover);
    border-color: rgba(255, 255, 255, 0.12);
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #f1f5f9;
}

.panel-title svg {
    color: var(--primary);
    width: 1.1rem;
    height: 1.1rem;
}

/* Drag-and-Drop Area */
.uploader-box {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    background: rgba(15, 23, 42, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.uploader-box.dragover {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.08);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.15);
}

.uploader-box input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.upload-icon-wrapper {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
}

.uploader-box:hover .upload-icon-wrapper {
    transform: translateY(-4px);
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.2);
}

.upload-icon-wrapper svg {
    width: 2rem;
    height: 2rem;
    color: var(--primary);
}

.upload-text {
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: #e2e8f0;
}

.upload-subtext {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Editor Form */
.editor-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-height: 450px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.form-group-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-field input,
.form-field select,
.form-field textarea {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    color: #fff;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

/* Items List Editor */
.items-editor-header {
    display: grid;
    grid-template-columns: 2.5fr 1fr 1.2fr 1.2fr 40px;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    padding: 0 0.25rem;
}

.item-row {
    display: grid;
    grid-template-columns: 2.5fr 1fr 1.2fr 1.2fr 40px;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}

.item-row input {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    color: #fff;
    font-size: 0.8rem;
}

.item-row input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-icon-danger {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--danger);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    color: #e2e8f0;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

/* History list */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    background: rgba(15, 23, 42, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: rgba(15, 23, 42, 0.5);
    border-color: var(--primary);
}

.history-item-details {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.history-item-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
}

.history-item-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.history-item-price {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--secondary);
}

/* Right Section: Simulator and controls */
.right-panel {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 1.5rem;
    height: 100%;
    overflow: hidden;
}

.controls-card {
    padding: 1.25rem;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.settings-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: #e2e8f0;
}

.settings-toggle input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

/* Preview Simulator Area */
.preview-container {
    background: #090d16;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 1.5rem;
    position: relative;
    overflow-y: auto;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.8);
}

/* Thermal POS Receipt Design */
.ticket-wrapper {
    position: relative;
    margin-bottom: 2rem;
}

/* 107mm Physical Boundary Marker (visual guide only) */
.height-marker {
    position: absolute;
    left: -20px;
    right: -20px;
    top: 107mm;
    border-top: 1.5px dashed var(--danger);
    opacity: 0.7;
    z-index: 5;
    pointer-events: none;
    transition: all 0.3s ease;
}

.height-marker::after {
    content: "Límite 107mm";
    position: absolute;
    right: 0;
    top: -16px;
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    font-family: inherit;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 600;
}

.ticket {
    background: #fdfdfd;
    color: #111;
    width: 58mm;
    min-height: 107mm;
    padding: 4mm 3mm;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0,0,0,0.1);
    border-radius: 2px;
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-size: 9pt;
    line-height: 1.25;
    position: relative;
    transition: font-size 0.2s ease, padding 0.2s ease, line-height 0.2s ease;
}

/* Custom fonts styling in ticket */
.ticket h2 {
    font-family: 'Courier Prime', monospace;
    font-size: 11pt;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.ticket h3 {
    font-family: 'Courier Prime', monospace;
    font-size: 10pt;
    font-weight: 700;
    text-align: center;
    margin: 4px 0;
}

.ticket p {
    margin: 2px 0;
}

.ticket-divider {
    border-top: 1px dashed #444;
    margin: 6px 0;
}

.ticket-double-divider {
    border-top: 1px double #444;
    border-bottom: 1px double #444;
    height: 3px;
    margin: 6px 0;
}

.ticket-center {
    text-align: center;
}

.ticket-right {
    text-align: right;
}

.ticket-bold {
    font-weight: 700;
}

/* Columns / Grid inside ticket */
.ticket-grid {
    display: flex;
    justify-content: space-between;
}

.ticket-table {
    width: 100%;
    border-collapse: collapse;
    margin: 6px 0;
}

.ticket-table th {
    text-align: left;
    border-bottom: 1px dashed #444;
    padding-bottom: 3px;
    font-weight: 700;
}

.ticket-table td {
    padding: 3px 0;
    vertical-align: top;
}

.ticket-table .col-cant {
    width: 15%;
    text-align: center;
}
.ticket-table .col-desc {
    width: 50%;
}
.ticket-table .col-total {
    width: 35%;
    text-align: right;
}

.ticket-table-sub {
    font-size: 0.85em;
    color: #444;
    display: block;
    margin-top: 1px;
}

/* QR Code center styling */
.ticket-qr-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 8px 0;
}

.ticket-qr-canvas {
    width: 35mm !important;
    height: 35mm !important;
    background: #fff;
    padding: 1mm;
}

.ticket-cufe-txt {
    font-size: 6.5pt;
    word-break: break-all;
    text-align: center;
    margin-top: 4px;
    color: #444;
    line-height: 1.1;
    padding: 0 2mm;
}

/* Receipt adjustments */
.ticket.size-small {
    font-size: 7.5pt;
    line-height: 1.15;
}
.ticket.size-medium {
    font-size: 8.5pt;
    line-height: 1.25;
}
.ticket.size-large {
    font-size: 9.5pt;
    line-height: 1.35;
}

.ticket.compact {
    padding: 2.5mm 2mm;
    line-height: 1.15;
}
.ticket.compact .ticket-divider, 
.ticket.compact .ticket-double-divider {
    margin: 4px 0;
}
.ticket.compact .ticket-table td {
    padding: 1.5px 0;
}
.ticket.compact .ticket-qr-canvas {
    width: 25mm !important;
    height: 25mm !important;
}

/* Floating Actions Bar */
.actions-card {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.7);
    border-top: 1px solid var(--glass-border);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #a78bfa);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0.8rem 2rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
    filter: brightness(1.05);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Loading Overlay inside Card */
.loader-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    border-radius: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loader-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 3rem;
    height: 3rem;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-text {
    font-weight: 600;
    font-size: 0.95rem;
    color: #fff;
}

.loader-subtext {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* CSS Print Stylesheet */
@media print {
    /* Set page margins to zero for POS thermal roll */
    @page {
        size: auto;
        margin: 0;
    }

    body, html {
        background: #fff !important;
        color: #000 !important;
        height: auto !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 58mm !important;
        overflow: visible !important;
    }
    
    /* Reset wrappers layout for print */
    .app-container,
    main,
    .right-panel,
    .preview-container,
    .ticket-wrapper {
        display: block !important;
        background: #fff !important;
        color: #000 !important;
        width: 58mm !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
    }
    
    /* Hide everything that is NOT the ticket */
    header,
    .left-panel,
    .controls-card,
    .actions-card,
    .height-marker {
        display: none !important;
    }
    
    /* Format the ticket for the physical paper */
    .ticket {
        display: block !important;
        background: #fff !important;
        color: #000 !important;
        width: 58mm !important;
        padding: 2mm 1mm !important;
        margin: 0 !important;
        border: none !important;
        box-shadow: none !important;
        page-break-inside: avoid;
    }
    
    /* QR Canvas adjustment for printing contrast */
    .ticket-qr-canvas {
        background: #fff !important;
        image-rendering: pixelated;
    }
}
