:root {
    --bg-app: #f8fafc;
    --bg-panel: #ffffff;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-dark: #1d4ed8;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    /* Paper Dimensions */
    --paper-width: 80mm;

    /* Brand Colors */
    --brand-primary: #3b82f6;
    --brand-secondary: #64748b;
}

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

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

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.app-header {
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.25rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.logo-image {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.logo-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.logo-link {
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.logo-link:hover {
    opacity: 0.8;
}

.logo-link:hover .logo-image,
.logo-link:hover .logo-icon {
    transform: scale(1.05);
}

.logo-text {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: #f97316;
    letter-spacing: -0.02em;
}

.logo-divider {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 1.25rem;
}

.logo-page {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-muted);
}

.header-title {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

/* Controls */
.control-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.segmented-control {
    background: var(--bg-app);
    padding: 4px;
    border-radius: 8px;
    display: flex;
    gap: 4px;
}

.segment {
    border: none;
    background: transparent;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.segment:hover {
    color: var(--text-main);
}

.segment.active {
    background: var(--bg-panel);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Workspace - The "Desk" */
.editor-workspace {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    padding: 2rem 1rem;
    background: var(--bg-app);
    gap: 6rem;
}

.paper-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.paper-shadow {
    position: relative;
    background: #ffffff;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-xl);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.thermal-paper {
    width: var(--paper-width);
    min-height: 150mm;
    background: #ffffff;
    padding: 5mm;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    color: black;
    outline: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.thermal-paper:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Ruler underneath to show size context */
.paper-ruler {
    width: var(--paper-width);
    height: 20px;
    border-top: 1px solid var(--text-muted);
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
    position: relative;
    transition: width 0.3s ease;
}

.paper-ruler::before {
    content: '0mm';
}

.paper-ruler::after {
    content: attr(data-width);
}


/* Footer */
.app-footer {
    background: #ffffff;
    border-top: 1px solid var(--border);
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.footer-credits {
    position: absolute;
    left: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.footer-developer {
    color: var(--text-muted);
}

.developer-link {
    color: var(--brand-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.developer-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.footer-buttons {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.primary-button {
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    padding: 0.875rem 2rem;
    border-radius: 10px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
    transition: all 0.2s ease;
}

.primary-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.45);
}

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

.secondary-button {
    background: #ffffff;
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 0.875rem 1.5rem;
    border-radius: 10px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.secondary-button:hover {
    background: var(--bg-app);
    border-color: var(--text-muted);
    transform: translateY(-1px);
}

.secondary-button:active {
    transform: translateY(0);
}

/* History Panel */
.history-panel {
    width: 320px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: var(--shadow-xl);
    padding: 1.5rem;
    height: fit-content;
    max-height: calc(100vh - 8rem);
    overflow-y: auto;
    flex-shrink: 0;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.history-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

.history-header-actions {
    display: flex;
    gap: 0.5rem;
}

.toggle-values-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-values-btn:hover {
    background: var(--bg-app);
    color: var(--text-main);
}

.toggle-values-btn.active {
    color: var(--brand-primary);
}

.summary-btn {
    background: transparent;
    border: none;
    color: var(--brand-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.summary-btn:hover {
    background: var(--bg-app);
    color: var(--primary-hover);
}

.clear-history-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-history-btn:hover {
    background: var(--bg-app);
    color: #ef4444;
}

.history-summary {
    background: var(--bg-app);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.summary-item:last-child {
    border-bottom: none;
}

.delivery-summary {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.summary-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

.summary-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.empty-history {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 2rem 0;
    margin: 0;
}

.history-item {
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.history-item:hover {
    border-color: var(--brand-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.history-item-content {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

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

.history-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.history-item-date {
    font-weight: 500;
}

.history-item-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.reprint-history-item {
    background: transparent;
    border: none;
    color: var(--brand-primary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.reprint-history-item:hover {
    background: rgba(59, 130, 246, 0.1);
}

.delete-history-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.delete-history-item:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.payment-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.payment-badge.pix {
    background: rgba(59, 130, 246, 0.1);
    color: var(--brand-primary);
}

.payment-badge.card {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.payment-badge.cash {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

/* RESPONSIVE STYLES */
@media (max-width: 1024px) {
    .header-content {
        padding: 1rem 1.5rem;
    }

    .logo-brand {
        font-size: 1.125rem;
    }

    .logo-page {
        font-size: 1rem;
    }

    .footer-buttons {
        gap: 0.5rem;
    }

    .primary-button,
    .secondary-button {
        padding: 0.75rem 1.25rem;
        font-size: 0.875rem;
    }

    .history-panel {
        width: 280px;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .logo-area {
        width: 100%;
        justify-content: center;
    }

    .controls {
        width: 100%;
    }

    .control-group {
        width: 100%;
    }

    .segmented-control {
        width: 100%;
        justify-content: space-between;
    }

    .segment {
        flex: 1;
        padding: 6px 8px;
        font-size: 0.8125rem;
    }

    .editor-workspace {
        padding: 1rem;
        flex-direction: column;
        align-items: center;
    }

    .paper-shadow {
        padding: 1rem;
    }

    .thermal-paper {
        font-size: 12px;
    }

    .history-panel {
        width: 100%;
        max-width: 100%;
    }

    .footer-buttons {
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }

    .primary-button,
    .secondary-button {
        width: 100%;
        justify-content: center;
    }

    .app-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }

    .footer-credits {
        position: static;
        width: 100%;
        justify-content: center;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .logo-icon {
        width: 36px;
        height: 36px;
    }

    .logo-icon svg {
        width: 20px;
        height: 20px;
    }

    .logo-brand {
        font-size: 1rem;
    }

    .logo-page {
        font-size: 0.875rem;
    }

    .logo-divider {
        font-size: 1rem;
    }

    .thermal-paper {
        font-size: 11px;
        padding: 4mm;
    }
}

/* PRINT STYLES - CRITICAL */
@media print {
    @page {
        margin: 0;
        size: auto;
        /* Allow printer driver to handle size or auto */
    }

    body * {
        visibility: hidden;
    }

    .thermal-paper,
    .thermal-paper * {
        visibility: visible;
    }

    .thermal-paper {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        /* Printer driver usually handles the exact width cutoff, but we set 100% of the printable area */
        max-width: var(--paper-width);
        /* Enforce the visual width constraint */
        margin: 0;
        padding: 0;
        box-shadow: none;
        overflow: visible;
    }

    /* Hide shadows and styling extras */
    .app-header,
    .app-footer {
        display: none;
    }

    .editor-workspace {
        background: none;
        padding: 0;
        margin: 0;
        /* Do NOT hide this, acts as parent */
    }

    .paper-shadow {
        box-shadow: none;
    }

    .paper-ruler {
        display: none;
    }

    /* Force black text for pasted content */
    .thermal-paper {
        color: black !important;
        text-shadow: none !important;
    }
}