:root {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #0f172a;
    --border-color: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --font-mono: 'Fira Code', monospace;
    --font-sans: 'Inter', sans-serif;
    --radius: 8px;
    --radius-sm: 4px;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    padding: 1.5rem;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Header */
.app-header {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

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

.logo-icon {
    font-size: 2.2rem;
}

h1 {
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.header-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-badge {
    background: #4f46e5;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

.badge-tech {
    background: #1e1b4b;
    color: #a5b4fc;
    border: 1px solid #3730a3;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.card-icon {
    font-size: 1.25rem;
}

.card h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.card-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* Connection Bar */
.connection-row {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.target-fields-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.hidden {
    display: none !important;
}

.form-group-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-group-inline label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}

.form-control {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-control:focus {
    border-color: var(--primary);
}

.select-mode {
    font-weight: 600;
    color: #60a5fa;
}

.port-input {
    width: 80px;
}

/* Telemetry Card */
.telemetry-card {
    border-left: 4px solid var(--primary);
}

.telemetry-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.telemetry-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.auto-refresh-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
}

.sensors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}

.sensor-badge {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
}

.sensor-badge.ok {
    border-color: rgba(16, 185, 129, 0.4);
    background: rgba(16, 185, 129, 0.05);
}

.sensor-badge.warn {
    border-color: rgba(245, 158, 11, 0.5);
    background: rgba(245, 158, 11, 0.1);
}

.sensor-badge.danger {
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.1);
}

.sensor-icon {
    font-size: 1.5rem;
}

.sensor-info {
    display: flex;
    flex-direction: column;
}

.sensor-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sensor-val {
    font-size: 0.85rem;
    font-weight: 600;
}

.telemetry-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 0.75rem;
}

.latency-badge {
    background: #0f172a;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    border: 1px solid var(--border-color);
}

/* Modules Grid */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
}

.full-width {
    grid-column: 1 / -1;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.form-group label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.hardware-buttons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

/* Image Upload & Preview */
.image-upload-box {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--bg-input);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}

.image-buttons-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.image-preview-wrapper {
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0f172a;
    border-radius: 4px;
    padding: 0.5rem;
    overflow: hidden;
}

.image-preview-wrapper img {
    max-width: 100%;
    max-height: 100px;
    object-fit: contain;
    border: 1px solid #334155;
    background: #ffffff;
    border-radius: 4px;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #334155;
    color: #ffffff;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background: #334155;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Receipt Generator Grid */
.receipt-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.items-table-wrapper {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin-bottom: 0.75rem;
}

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

.items-table th {
    background: #1e293b;
    text-align: left;
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.items-table td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.table-actions-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.receipt-totals-box {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    min-width: 240px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

.grand-total {
    font-size: 1.1rem;
    color: #4ade80;
    border-top: 1px solid var(--border-color);
    padding-top: 0.4rem;
    margin-top: 0.4rem;
}

.hardware-toggles-row {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.hardware-toggles-row label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
}

/* Terminal / Log Output */
.terminal-card {
    background: #090d16;
    border-color: #1e293b;
    padding: 0;
    overflow: hidden;
}

.terminal-header {
    background: #111827;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #1f2937;
}

.terminal-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.terminal-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.terminal-dot.red { background: #ef4444; }
.terminal-dot.yellow { background: #f59e0b; }
.terminal-dot.green { background: #10b981; }

.terminal-body {
    padding: 0.75rem 1rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.log-line {
    word-break: break-all;
}

.log-line.info { color: #60a5fa; }
.log-line.success { color: #4ade80; }
.log-line.warn { color: #fbbf24; }
.log-line.error { color: #f87171; }
.log-line.hex { color: #c084fc; }

.app-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 1rem 0;
}

/* --- BOTÓN OJO DE GATO (VISTA PREVIA) --- */
.btn-eye-preview {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-eye-preview:hover {
    background: rgba(59, 130, 246, 0.25);
    border-color: #3b82f6;
    color: #93c5fd;
    transform: translateY(-1px);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

.btn-eye-preview .eye-icon {
    stroke: currentColor;
}

/* --- MODAL DE PREVISUALIZACIÓN TÉRMICA (80mm) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 1rem;
    opacity: 1;
    transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-container {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
    animation: modalSlideUp 0.25s ease-out;
}

@keyframes modalSlideUp {
    from {
        transform: translateY(20px) scale(0.97);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #334155;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.modal-icon {
    font-size: 1.5rem;
}

.modal-header h4 {
    font-size: 1rem;
    font-weight: 600;
    color: #f8fafc;
}

.modal-subtitle {
    font-size: 0.75rem;
    color: #94a3b8;
    display: block;
}

.modal-close-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.modal-close-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    background: #0f172a;
    display: flex;
    justify-content: center;
}

.modal-footer {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid #334155;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    background: #1e293b;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

/* --- ROLLO DE PAPEL TÉRMICO REALISTA (80MM / 48 COLS) --- */
.thermal-paper-wrapper {
    width: 360px;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.5));
    display: flex;
    flex-direction: column;
}

.thermal-paper-tear-edge {
    height: 10px;
    background-color: #faf8f5;
    background-image: 
        linear-gradient(135deg, #0f172a 4px, transparent 0),
        linear-gradient(-135deg, #0f172a 4px, transparent 0);
    background-size: 8px 8px;
}

.thermal-paper-tear-edge.top {
    background-repeat: repeat-x;
    background-position: bottom;
}

.thermal-paper-tear-edge.bottom {
    background-repeat: repeat-x;
    background-position: top;
    transform: rotate(180deg);
}

.thermal-paper-sheet {
    background: #faf8f5;
    color: #1a1a1a;
    font-family: 'Consolas', 'Courier New', 'Lucida Console', monospace;
    font-size: 11.5px;
    line-height: 1.35;
    padding: 1.2rem 1rem;
    min-height: 250px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.03);
}

/* Elementos internos del recibo térmico */
.rcpt-center { text-align: center; }
.rcpt-right { text-align: right; }
.rcpt-left { text-align: left; }
.rcpt-bold { font-weight: 700; color: #000; }
.rcpt-title { font-size: 15px; font-weight: 800; letter-spacing: 0.5px; margin-bottom: 2px; }
.rcpt-subtitle { font-size: 12px; font-weight: 600; }
.rcpt-divider { border-top: 1px dashed #333; margin: 6px 0; }
.rcpt-divider-double { border-top: 2px solid #000; margin: 6px 0; }

.rcpt-inverted {
    background: #111;
    color: #fff;
    padding: 2px 6px;
    display: inline-block;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.rcpt-double-width {
    letter-spacing: 2px;
    font-size: 13px;
    font-weight: 700;
}

.rcpt-double-height {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.5;
}

.rcpt-double-both {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 1px;
    line-height: 1.6;
}

.rcpt-table {
    width: 100%;
    border-collapse: collapse;
    margin: 4px 0;
    font-size: 11px;
}

.rcpt-table th {
    border-bottom: 1px dashed #000;
    padding-bottom: 3px;
    font-weight: 700;
}

.rcpt-table td {
    padding: 2px 0;
    vertical-align: top;
}

.rcpt-totals-table {
    width: 100%;
    margin-top: 4px;
}

.rcpt-totals-table td {
    padding: 1px 0;
}

.rcpt-grand-total {
    font-size: 13px;
    font-weight: 800;
    border-top: 1px dashed #000;
    border-bottom: 1px dashed #000;
    padding: 3px 0 !important;
}

.rcpt-barcode-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 8px 0;
}

.rcpt-barcode-lines {
    height: 40px;
    width: 160px;
    background: repeating-linear-gradient(
        90deg,
        #000 0px,
        #000 2px,
        transparent 2px,
        transparent 4px,
        #000 4px,
        #000 7px,
        transparent 7px,
        transparent 9px,
        #000 9px,
        #000 10px,
        transparent 10px,
        transparent 13px
    );
}

.rcpt-qr-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 8px 0;
}

.rcpt-qr-box {
    width: 90px;
    height: 90px;
    background: #000;
    padding: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 2px;
}

.rcpt-qr-pattern {
    width: 100%;
    height: 100%;
    background-color: #fff;
    background-image: 
        radial-gradient(#000 35%, transparent 35%),
        radial-gradient(#000 35%, transparent 35%);
    background-size: 10px 10px;
    background-position: 0 0, 5px 5px;
}

.rcpt-logo-preview {
    max-width: 150px;
    max-height: 70px;
    margin: 0 auto 6px auto;
    display: block;
    filter: grayscale(100%) contrast(200%);
}

@media (max-width: 768px) {
    .modules-grid {
        grid-template-columns: 1fr;
    }
}
