:root {
    --primary-yellow: #f4c415;
    /* From style example */
    --primary-dark: #1f2022;
    /* From style example */
    --secondary-dark: #434445;
    /* From style example */
    --text-light: #ffffff;
    --text-muted: #888888;
    --border-color: #e0e0e0;
    --bg-app: #f5f7fa;
    --surface-white: #ffffff;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.05);
}

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

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

.app-container {
    display: grid;
    grid-template-columns: 350px 1fr;
    height: 100vh;
    width: 100vw;
}

@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        overflow: hidden;
    }
}

/* --- Control Panel (Sidebar / Mobile Dashboard) --- */
.control-panel {
    background-color: var(--surface-white);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    border-right: 1px solid var(--border-color);
    box-shadow: var(--shadow-soft);
    z-index: 100;
    overflow-y: auto;
}

@media (max-width: 1024px) {
    .control-panel {
        padding: 0.6rem 1rem;
        border-right: none;
        border-bottom: 2px solid var(--primary-yellow);
        height: auto;
        position: sticky;
        top: 0;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        display: flex;
        flex-direction: row;
        /* Horizontal layout for ribbons */
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
        z-index: 1000;
    }
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.brand p {
    font-size: 0.875rem;
    color: var(--secondary-dark);
}

@media (max-width: 1024px) {

    /* Ribbon 1: Brand */
    .brand {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 0.5rem;
        width: auto;
        padding-bottom: 0;
        border-bottom: none;
        order: 1;
        flex-shrink: 0;
    }

    .brand h1 {
        font-size: 0.85rem;
        margin: 0;
        white-space: nowrap;
    }

    .brand p,
    .features-list {
        display: none !important;
    }
}

/* Base Utility Classes */
.mobile-only {
    display: none !important;
}

.icon-btn-highlight {
    background-color: var(--primary-yellow);
    color: var(--primary-dark);
    border: none;
    border-radius: 6px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(244, 196, 21, 0.3);
}

.icon-btn-highlight:hover {
    background-color: #e0b20c;
    transform: scale(1.05);
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background-color: #fafafa;
    min-height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary-yellow);
    background-color: rgba(244, 196, 21, 0.05);
}

@media (max-width: 1024px) {

    /* Hide upload zone on mobile */
    .upload-zone {
        display: none !important;
    }
}

.icon-upload {
    color: var(--secondary-dark);
    margin-bottom: 0.5rem;
}

.upload-zone h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.upload-zone p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Status & Buttons */
.status-panel {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 220px;
}

@media (max-width: 1024px) {

    /* Ribbon 1: Status (Alongside Brand) */
    .status-panel {
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
        align-items: center;
        background: transparent;
        padding: 0 !important;
        gap: 0.4rem;
        order: 1;
        flex: 1;
        margin-bottom: 0;
        min-height: 0;
        min-width: 0;
    }

    .status-item {
        font-size: 0.65rem;
        background: #f1f3f5;
        padding: 4px 6px;
        border-radius: 4px;
        flex: 0 1 auto;
        display: flex;
        gap: 0.2rem;
        align-items: center;
        white-space: nowrap;
        overflow: hidden;
    }

    .status-item .label {
        font-weight: 600;
        color: var(--secondary-dark);
        display: none;
    }

    @media (min-width: 600px) {
        .status-item .label {
            display: inline;
        }
    }
}

.status-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.status-item .label {
    color: var(--secondary-dark);
}

.status-item .value.success {
    color: #28a745;
}

.status-item .value.error {
    color: #dc3545;
}

.primary-btn {
    background-color: var(--primary-yellow);
    color: var(--primary-dark);
    border: none;
    border-radius: 6px;
    padding: 0.875rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.2s, background-color 0.2s;
}

.primary-btn:hover:not(:disabled) {
    background-color: #e0b20c;
    transform: translateY(-1px);
}

.primary-btn:disabled {
    background-color: #e0e0e0;
    color: #a0a0a0;
    cursor: not-allowed;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@media (max-width: 1024px) {

    /* Ribbon 2: Actions bar (occupies full width below Ribbon 1) */
    .button-group {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.4rem;
        order: 2;
        width: 100%;
        margin-top: 0;
        min-width: 0;
        padding-top: 0.5rem !important;
        border-top: 1px solid #f0f0f0;
    }

    .primary-btn {
        flex: 1 1 auto;
        height: 36px;
        padding: 0 0.5rem;
        font-size: 0.7rem;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .primary-btn svg {
        width: 14px;
        height: 14px;
    }

    .nav-controls {
        flex: 0 1 auto;
        display: flex;
        align-items: center;
        width: auto;
        gap: 0.2rem;
        min-width: 0;
    }

    .nav-controls .icon-btn {
        width: 32px;
        height: 32px;
        flex-shrink: 0;
    }
}

.secondary-btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--secondary-dark);
    border-radius: 6px;
    padding: 0.75rem;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn-outline:hover {
    background-color: #f8f9fa;
    border-color: var(--secondary-dark);
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.nav-controls .secondary-btn-outline {
    flex: 1;
}

.icon-btn {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--secondary-dark);
    border-radius: 6px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.icon-btn:hover:not(:disabled) {
    background-color: #f8f9fa;
    border-color: var(--secondary-dark);
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.value.warning {
    color: #fd7e14;
    font-weight: 600;
}

/* Features List */
.features-list h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 1rem;
}

.features-list ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.features-list li {
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--secondary-dark);
}

.features-list li svg {
    color: #28a745;
}

/* Privacy Badge */
.privacy-badge {
    background-color: rgba(40, 167, 69, 0.08);
    border: 1px solid rgba(40, 167, 69, 0.3);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    color: #1e4627;
}

.privacy-badge svg {
    color: #28a745;
}

.privacy-text {
    display: flex;
    flex-direction: column;
}

.privacy-text strong {
    font-size: 0.875rem;
}

.privacy-text span {
    font-size: 0.75rem;
    color: #666;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.footer-separator {
    color: var(--text-muted);
    font-size: 0.75rem;
    opacity: 0.5;
}

@media (max-width: 1024px) {
    .nav-controls #resetBtn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        flex: 0 1 auto;
        min-width: 65px;
        height: 32px;
        font-size: 0.7rem;
        padding: 0 10px;
        background: white;
        border: 1px solid var(--border-color);
        border-radius: 4px;
        white-space: nowrap;
    }
}

.experiment-link {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
    font-weight: 500;
}

.experiment-link:hover {
    color: var(--primary-yellow);
}

@media (max-width: 1024px) {

    /* Hide everything except the two ribbons on mobile */
    .sidebar-footer {
        display: none;
    }

    .mobile-only {
        display: flex !important;
    }
}

/* --- Preview Panel (Main Area) --- */
.preview-panel {
    background-color: var(--secondary-dark);
    padding: 3rem;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 1024px) {
    .preview-panel {
        padding: 1rem;
        background-color: #333;
    }
}

.preview-viewport {
    transform-origin: top center;
    transition: transform 0.2s ease-out;
    display: flex;
    justify-content: center;
}

/* --- A4 Invoice Styles --- */
.invoice-a4 {
    background: white;
    width: 210mm;
    min-height: 297mm;
    padding: 15mm 20mm;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    position: relative;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    color: #333;
}

/* Header */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 3rem;
    border-bottom: 2px solid var(--primary-yellow);
    padding-bottom: 1.5rem;
}

.logo-placeholder {
    width: 120px;
    height: 48px;
    background-color: var(--primary-dark);
    color: var(--primary-yellow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    letter-spacing: 2px;
}

.invoice-title {
    text-align: right;
}

.invoice-title h2 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--secondary-dark);
    letter-spacing: -1px;
    margin: 0;
    line-height: 1;
}

.invoice-number {
    font-size: 1.1rem;
    color: var(--primary-yellow);
    font-weight: 600;
    display: block;
    margin-top: 0.5rem;
}

/* Meta Grid */
.invoice-meta-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    margin-bottom: 3rem;
}

/* Tablet & Mobile Grid Stacking */
@media (max-width: 768px) {
    .invoice-meta-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

@media (min-width: 769px) and (max-width: 1100px) {
    .invoice-meta-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.meta-block h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.highlight-text {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary-dark);
    margin-bottom: 0.25rem;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 0.25rem;
}

.meta-row .label {
    color: var(--secondary-dark);
    font-weight: 500;
}

.meta-row .val {
    font-weight: 600;
}

.meta-row .val small {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.85em;
    margin-left: 0.25rem;
}

/* Table Container for Responsiveness */
.invoice-body {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 3rem;
}

/* Table */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 3rem;
}

.items-table th {
    text-align: left;
    padding: 1rem 0.5rem;
    background-color: var(--primary-dark);
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
}

.items-table th:first-child {
    border-radius: 4px 0 0 4px;
    padding-left: 1rem;
}

.items-table th:last-child {
    border-radius: 0 4px 4px 0;
    padding-right: 1rem;
    text-align: right;
}

.items-table td {
    padding: 1rem 0.5rem;
    border-bottom: 1px solid #eee;
}

.items-table td:first-child {
    padding-left: 1rem;
}

.items-table td:last-child {
    padding-right: 1rem;
    text-align: right;
    font-weight: 600;
}

.col-qty,
.col-unit,
.col-tax {
    width: 10%;
    text-align: center !important;
}

.col-total {
    width: 15%;
}

/* Footer Grid */
.invoice-footer-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
    margin-top: auto;
    align-items: flex-start;
}

@media (max-width: 850px) {
    .invoice-footer-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .barcode-container {
        width: 100%;
        max-width: 250px;
    }

    .totals-block {
        width: 100%;
    }
}

.payment-section {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    align-items: flex-start;
}

.payment-info {
    background-color: #f9f9f9;
    padding: 1.5rem;
    border-radius: 8px;
    border-left: 4px solid var(--primary-yellow);
    flex: 1;
}

.barcode-container {
    background: white;
    padding: 0.5rem;
    border: 1px solid #eee;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 200px;
    /* Fixed width for standard HUB3 size visualization */
}

.barcode-container canvas {
    max-width: 100%;
}

.barcode-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    text-transform: uppercase;
}

.detail-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.detail-row span:first-child {
    font-weight: 600;
    min-width: 80px;
}

.totals-block {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    font-size: 0.95rem;
}

.total-row.grand-total {
    border-top: 2px solid var(--primary-dark);
    margin-top: 0.5rem;
    padding-top: 1rem;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary-yellow);
    background-color: var(--primary-dark);
    padding: 1rem;
    border-radius: 4px;
}

/* --- Final Audit & UI Polish Updates --- */

.invoice-id-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.icon-btn-tiny {
    background: #f0f0f0;
    border: none;
    border-radius: 4px;
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--secondary-dark);
}

.icon-btn-tiny:hover {
    background: var(--primary-yellow);
    color: var(--primary-dark);
}

.audit-badge {
    margin-top: 0.75rem;
    font-size: 0.65rem;
    font-weight: 700;
    color: #4CAF50;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    letter-spacing: 0.5px;
}

.audit-badge .dot {
    width: 6px;
    height: 6px;
    background: #4CAF50;
    border-radius: 50%;
    display: inline-block;
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

@media (max-width: 1024px) {
    .sidebar-footer {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    .audit-badge {
        margin-top: 0;
    }
}

.legal-footer {
    margin-top: 3rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.7rem;
    border-top: 1px solid #eee;
    padding-top: 1rem;
}

/* WEB-010: Touch optimization for mobile buttons */
button,
.primary-btn,
.icon-btn,
.secondary-btn-outline,
.icon-btn-tiny {
    touch-action: manipulation;
}

/* WEB-009: Respect user's reduced motion preferences for accessibility */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}