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

:root {
    --primary-black: #0a0a0f;
    --primary-darker: #0d0d14;
    --accent-cyan: #22d3ee;
    --accent-magenta: #cd74d9;
    --accent-pink: #ff5fba;
    --accent-blue: #3b82f6;
    --text-primary: #e0e0e0;
    --text-secondary: #888;
    --text-muted: #666;
    --border-color: rgba(34, 211, 238, 0.2);
    --card-bg: rgba(255, 255, 255, 0.03);
    --success-bg: rgba(34, 211, 238, 0.15);
    --success-border: var(--accent-cyan);
    --error-bg: rgba(244, 67, 54, 0.15);
    --error-border: #f44336;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, var(--primary-black) 0%, var(--primary-darker) 50%, #0f1420 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

/* App Container - Split Screen Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Left Panel - Form */
.form-panel {
    flex: 1;
    width: 50%;
    padding: 20px;
    overflow-y: auto;
    max-height: 100vh;
}

/* Right Panel - Preview */
.preview-panel {
    flex: 1;
    width: 50%;
    background: linear-gradient(180deg, var(--primary-black) 0%, var(--primary-darker) 100%);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.1), rgba(205, 116, 217, 0.05));
    border-bottom: 1px solid var(--border-color);
}

.preview-header h2 {
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.preview-actions {
    display: flex;
    gap: 5px;
}

.btn-icon {
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
}

.preview-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* Invoice Paper Preview */
.invoice-paper {
    background: #fff;
    color: #333;
    width: 100%;
    max-width: 100%;
    padding: 30px;
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    font-size: 12px;
    transform-origin: top center;
    transition: transform 0.3s ease;
    min-height: fit-content;
}

.inv-header {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 3px solid var(--accent-cyan);
}

.inv-title {
    font-size: 24px;
    font-weight: bold;
    color: var(--accent-cyan);
    letter-spacing: 3px;
}

.inv-number {
    font-size: 18px;
    margin-top: 8px;
    color: #666;
}

.inv-dates {
    display: flex;
    justify-content: flex-end;
    gap: 30px;
    margin-bottom: 20px;
    font-size: 13px;
}

.inv-date-row {
    text-align: right;
}

.inv-date-row .label {
    color: #888;
}

.inv-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.inv-party {
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid var(--accent-cyan);
}

.inv-party-title {
    font-size: 11px;
    font-weight: bold;
    color: var(--accent-cyan);
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.inv-party-name {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 5px;
    word-break: break-word;
}

.inv-party-nip {
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
}

.inv-party-address {
    font-size: 12px;
    color: #666;
    word-break: break-word;
    line-height: 1.4;
}

/* Invoice Items Table */
.inv-items {
    margin-bottom: 20px;
}

.inv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.inv-table th,
.inv-table td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.inv-table th {
    background: var(--accent-cyan);
    color: #fff;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
}

.inv-table tbody tr:nth-child(even) {
    background: #f8f9fa;
}

.inv-table .empty-row td {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 25px;
}

/* Invoice Summary */
.inv-summary {
    margin-bottom: 20px;
    padding: 15px;
    background: #f0f7ff;
    border-radius: 6px;
}

.inv-summary-row {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    padding: 5px 0;
    font-size: 13px;
}

.inv-summary-row .label {
    color: #666;
}

.inv-summary-total {
    font-size: 18px;
    font-weight: bold;
    color: var(--accent-cyan);
    border-top: 2px solid var(--accent-cyan);
    margin-top: 8px;
    padding-top: 12px;
}

/* Invoice Payment */
.inv-payment {
    padding: 15px;
    background: #fff8e1;
    border-radius: 6px;
    border-left: 4px solid #ff9800;
}

.inv-payment-row {
    font-size: 12px;
    margin-bottom: 5px;
}

.inv-payment-row .label {
    color: #666;
}

/* KSeF Status Badge on Invoice */
.inv-ksef-status {
    margin-top: 15px;
    padding: 10px;
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: ksefAppear 0.5s ease;
}

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

.ksef-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    background: #4CAF50;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
}

.ksef-icon {
    font-size: 12px;
}

.ksef-number {
    font-size: 9px;
    color: #2e7d32;
    word-break: break-all;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 25px 15px;
    position: relative;
}

header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 150px;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta), var(--accent-pink));
    border-radius: 3px;
}

header h1 {
    font-size: 2.2rem;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta), var(--accent-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    font-weight: 700;
}

header .subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.section-header h2 {
    font-size: 1.2rem;
    color: var(--accent-cyan);
}

.status-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.1);
}

.status-badge.success {
    background: rgba(76, 175, 80, 0.3);
    color: #81c784;
}

.status-badge.error {
    background: rgba(244, 67, 54, 0.3);
    color: #e57373;
}

.status-badge.warning {
    background: rgba(255, 193, 7, 0.3);
    color: #ffd54f;
}

/* Form Elements */
.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 100px;
}

.form-group.flex-grow {
    flex-grow: 1;
}

.form-group label {
    font-size: 0.8rem;
    color: #aaa;
}

input, select, textarea {
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    font-size: 0.9rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 2px var(--border-color);
}

input::placeholder {
    color: #666;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
    color: #000;
    font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--accent-magenta), var(--accent-pink));
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(34, 211, 238, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
}

.btn-success {
    background: #4CAF50;
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background: #45a049;
    transform: translateY(-1px);
}

.btn-small {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* GUS Button */
.input-with-button {
    display: flex;
    gap: 5px;
}

.input-with-button input {
    flex-grow: 1;
}

.btn-gus {
    background: #ff9800;
    color: #000;
    white-space: nowrap;
    font-weight: bold;
}

.btn-gus:hover:not(:disabled) {
    background: #f57c00;
}

/* Parties */
.parties-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.party-box {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 12px;
}

.party-box h3 {
    font-size: 0.95rem;
    color: var(--accent-cyan);
    margin-bottom: 12px;
}

/* Items Table */
.items-section {
    margin-bottom: 15px;
}

.items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.items-header h3 {
    font-size: 0.95rem;
    color: var(--accent-cyan);
}

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

#items-table th, #items-table td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#items-table th {
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.8rem;
    color: var(--accent-cyan);
}

#items-table input, #items-table select {
    width: 100%;
    padding: 5px 6px;
    font-size: 0.85rem;
}

#items-table .text-right {
    text-align: right;
}

.totals-row {
    background: rgba(34, 211, 238, 0.1);
}

.btn-remove-item {
    background: rgba(244, 67, 54, 0.3);
    color: #e57373;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
}

/* Payment */
.payment-section h3 {
    font-size: 0.95rem;
    color: var(--accent-cyan);
    margin-bottom: 12px;
}

/* Actions */
.actions-card {
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.05), rgba(205, 116, 217, 0.05));
    border-color: var(--border-color);
}

.actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.actions-left, .actions-right {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Result */
#result-content {
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-bottom: 12px;
}

#result-content .success-msg {
    color: #81c784;
}

#result-content .error-msg {
    color: #e57373;
}

#result-content .info-row {
    display: flex;
    gap: 15px;
    margin-top: 8px;
    flex-wrap: wrap;
}

#result-content .info-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 12px;
    border-radius: 6px;
}

#result-content .info-label {
    font-size: 0.75rem;
    color: #888;
}

#result-content .info-value {
    font-size: 1rem;
    font-weight: bold;
    color: var(--accent-cyan);
}

.result-actions {
    display: flex;
    gap: 8px;
}

/* Token */
.token-info {
    display: flex;
    gap: 15px;
    margin-top: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.token-detail {
    color: #888;
    font-size: 0.8rem;
}

.link {
    color: var(--accent-cyan);
    text-decoration: none;
}

.link:hover {
    text-decoration: underline;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-cyan);
    border-right-color: var(--accent-magenta);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading-text {
    margin-top: 15px;
    color: var(--accent-cyan);
}

/* KSeF Animation Overlay */
.ksef-animation-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.ksef-animation-content {
    text-align: center;
    max-width: 600px;
    padding: 40px;
}

/* Stages */
.ksef-animation-stages {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 50px;
    flex-wrap: wrap;
    gap: 5px;
}

.stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0.3;
    transition: all 0.5s ease;
}

.stage.active {
    opacity: 1;
    transform: scale(1.1);
}

.stage.completed {
    opacity: 1;
}

.stage.completed .stage-icon {
    background: #4CAF50;
}

.stage-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 8px;
    transition: all 0.3s ease;
}

.stage.active .stage-icon {
    background: var(--accent-cyan);
    box-shadow: 0 0 20px rgba(34, 211, 238, 0.5);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.stage-label {
    font-size: 11px;
    color: #888;
    max-width: 80px;
    text-align: center;
}

.stage.active .stage-label,
.stage.completed .stage-label {
    color: #fff;
}

.stage-connector {
    width: 30px;
    height: 2px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 5px 25px 5px;
}

.stage-progress {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: 5px;
    overflow: hidden;
}

.stage.active .stage-progress::after {
    content: '';
    display: block;
    height: 100%;
    background: var(--accent-cyan);
    animation: progressBar 2s ease-in-out infinite;
}

@keyframes progressBar {
    0% { width: 0%; }
    50% { width: 100%; }
    100% { width: 0%; }
}

/* Flying Invoice Animation */
.ksef-animation-info {
    position: relative;
    height: 100px;
    margin-bottom: 30px;
}

.flying-invoice {
    position: absolute;
    left: 50px;
    top: 50%;
    transform: translateY(-50%);
    transition: all 2s ease-in-out;
}

.flying-invoice.flying {
    left: calc(100% - 100px);
    animation: flyingPaper 2s ease-in-out;
}

@keyframes flyingPaper {
    0% { transform: translateY(-50%) rotate(0deg) scale(1); }
    25% { transform: translateY(-80%) rotate(10deg) scale(1.1); }
    50% { transform: translateY(-50%) rotate(-5deg) scale(1); }
    75% { transform: translateY(-30%) rotate(5deg) scale(0.9); }
    100% { transform: translateY(-50%) rotate(0deg) scale(0.8); }
}

.invoice-icon {
    font-size: 40px;
    filter: drop-shadow(0 0 10px rgba(34, 211, 238, 0.5));
}

.ksef-server {
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    text-align: center;
}

.server-icon {
    font-size: 50px;
}

.server-label {
    font-size: 14px;
    font-weight: bold;
    color: var(--accent-cyan);
    margin-top: 5px;
}

.ksef-animation-status {
    font-size: 18px;
    color: var(--accent-cyan);
    animation: fadeInOut 1.5s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Success State */
.ksef-animation-overlay.success .ksef-animation-status {
    color: #4CAF50;
    animation: none;
    font-size: 24px;
}

.ksef-animation-overlay.error .ksef-animation-status {
    color: #f44336;
    animation: none;
}

.hidden {
    display: none !important;
}

/* Intro Section - SEO Content */
.intro-section {
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.08), rgba(205, 116, 217, 0.05));
    border: 1px solid rgba(34, 211, 238, 0.2);
}

.intro-content h2 {
    font-size: 1.3rem;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.intro-content > p {
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.7;
}

.intro-content strong {
    color: var(--text-primary);
}

.intro-features {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.intro-feature {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex: 1;
    min-width: 200px;
}

.feature-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
    color: var(--primary-black);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.feature-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.feature-text strong {
    color: var(--text-primary);
    display: block;
}

.intro-details {
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
}

.intro-details summary {
    cursor: pointer;
    color: var(--accent-cyan);
    font-weight: 500;
    padding: 8px 0;
    transition: color 0.2s;
}

.intro-details summary:hover {
    color: var(--accent-magenta);
}

.intro-details[open] summary {
    margin-bottom: 15px;
}

.details-content {
    padding-left: 15px;
    border-left: 2px solid var(--border-color);
}

.details-content p {
    margin-bottom: 15px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.details-content p strong {
    color: var(--accent-cyan);
}

.details-content a {
    color: var(--accent-magenta);
    text-decoration: none;
}

.details-content a:hover {
    text-decoration: underline;
}

.intro-notice {
    background: rgba(255, 152, 0, 0.1);
    border-left: 3px solid #ff9800;
    padding: 10px 15px;
    margin-top: 10px;
    border-radius: 0 6px 6px 0;
    color: #ffd180 !important;
}

/* Footer */
footer {
    text-align: center;
    padding: 15px;
    color: #666;
    font-size: 0.85rem;
}

footer a {
    color: var(--accent-cyan);
    text-decoration: none;
}

/* Responsive */
@media (max-width: 1200px) {
    .app-container {
        flex-direction: column;
    }

    .form-panel {
        width: 100%;
        max-width: 100%;
        max-height: none;
    }

    .preview-panel {
        width: 100%;
        flex: none;
        height: auto;
        min-height: 500px;
        position: relative;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
}

@media (max-width: 768px) {
    body {
        font-size: 14px;
    }

    header {
        padding: 15px 10px;
        margin-bottom: 15px;
    }

    header h1 {
        font-size: 1.4rem;
    }

    header .subtitle {
        font-size: 0.85rem;
    }

    .card {
        padding: 15px;
        border-radius: 12px;
        margin-bottom: 12px;
    }

    .form-panel {
        padding: 10px;
    }

    /* Form rows stack vertically */
    .form-row {
        flex-direction: column;
        gap: 8px;
    }

    .form-group {
        min-width: 100%;
    }

    /* Parties side by side on tablet, stacked on phone */
    .parties-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .party-box {
        padding: 10px;
    }

    .party-box h3 {
        font-size: 0.9rem;
        margin-bottom: 10px;
    }

    /* Actions buttons */
    .actions-card {
        padding: 12px;
    }

    .actions-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .actions-left, .actions-right {
        flex-direction: column;
        gap: 8px;
    }

    .actions-left .btn,
    .actions-right .btn {
        width: 100%;
        justify-content: center;
        padding: 12px 16px;
    }

    /* Invoice items table - mobile card layout */
    .items-section {
        overflow-x: visible;
    }

    .items-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .items-header .btn {
        width: 100%;
    }

    #items-table {
        display: block;
        font-size: 0.85rem;
    }

    #items-table thead {
        display: none;
    }

    #items-table tbody {
        display: block;
    }

    #items-table tr {
        display: block;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 8px;
        padding: 12px;
        margin-bottom: 10px;
        border: 1px solid var(--border-color);
    }

    #items-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    #items-table td::before {
        content: attr(data-label);
        font-weight: 500;
        color: var(--accent-cyan);
        font-size: 0.75rem;
        flex-shrink: 0;
        margin-right: 10px;
    }

    #items-table td:last-child {
        border-bottom: none;
        justify-content: center;
        padding-top: 10px;
    }

    #items-table td input,
    #items-table td select {
        width: auto;
        flex: 1;
        max-width: 150px;
        text-align: right;
    }

    #items-table tfoot {
        display: block;
    }

    #items-table tfoot tr {
        background: rgba(34, 211, 238, 0.1);
    }

    #items-table tfoot td {
        display: flex;
        justify-content: space-between;
    }

    #items-table tfoot td[colspan] {
        display: none;
    }

    .totals-row {
        display: flex !important;
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 12px !important;
    }

    /* Payment section */
    .payment-section .form-row {
        gap: 10px;
    }

    /* Preview panel mobile */
    .preview-panel {
        min-height: auto;
        max-height: none;
    }

    .preview-header {
        padding: 12px 15px;
    }

    .preview-header h2 {
        font-size: 1rem;
    }

    .preview-content {
        padding: 10px;
    }

    .invoice-paper {
        padding: 15px;
        font-size: 10px;
    }

    .inv-header {
        margin-bottom: 15px;
        padding-bottom: 12px;
    }

    .inv-title {
        font-size: 18px;
        letter-spacing: 2px;
    }

    .inv-number {
        font-size: 14px;
    }

    .inv-dates {
        flex-direction: column;
        gap: 5px;
        font-size: 11px;
    }

    .inv-parties {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .inv-party {
        padding: 10px;
    }

    .inv-party-name {
        font-size: 12px;
    }

    .inv-table th,
    .inv-table td {
        padding: 6px 4px;
        font-size: 9px;
    }

    .inv-summary {
        padding: 10px;
    }

    .inv-summary-row {
        font-size: 11px;
        gap: 8px;
    }

    .inv-summary-total {
        font-size: 14px;
    }

    .inv-payment {
        padding: 10px;
    }

    .inv-payment-row {
        font-size: 10px;
    }

    /* Token section */
    .token-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    /* Intro section mobile */
    .intro-content h2 {
        font-size: 1.1rem;
    }

    .intro-features {
        flex-direction: column;
        gap: 12px;
    }

    .intro-feature {
        min-width: 100%;
    }

    .feature-text {
        font-size: 0.85rem;
    }

    /* Result section */
    #result-content .info-row {
        flex-direction: column;
        gap: 8px;
    }

    .result-actions {
        flex-direction: column;
        gap: 8px;
    }

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

    /* KSeF Animation mobile */
    .ksef-animation-content {
        padding: 20px;
        width: 100%;
    }

    .ksef-animation-stages {
        flex-direction: column;
        gap: 8px;
        margin-bottom: 30px;
    }

    .stage {
        flex-direction: row;
        gap: 12px;
        width: 100%;
        justify-content: flex-start;
        padding: 8px 0;
    }

    .stage-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
        margin-bottom: 0;
    }

    .stage-label {
        max-width: none;
        text-align: left;
        font-size: 12px;
    }

    .stage-connector {
        display: none;
    }

    .stage-progress {
        display: none;
    }

    .ksef-animation-info {
        height: 80px;
        margin-bottom: 20px;
    }

    .flying-invoice {
        left: 30px;
    }

    .flying-invoice.flying {
        left: calc(100% - 80px);
    }

    .invoice-icon {
        font-size: 30px;
    }

    .ksef-server {
        right: 30px;
    }

    .server-icon {
        font-size: 35px;
    }

    .server-label {
        font-size: 12px;
    }

    .ksef-animation-status {
        font-size: 14px;
    }
}

/* Extra small devices (phones in portrait) */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.2rem;
    }

    header .subtitle {
        font-size: 0.8rem;
    }

    .card {
        padding: 12px;
        border-radius: 10px;
    }

    .section-header h2 {
        font-size: 1rem;
    }

    .status-badge {
        font-size: 0.7rem;
        padding: 4px 8px;
    }

    input, select, textarea {
        padding: 10px 12px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .btn {
        padding: 12px 16px;
        font-size: 0.9rem;
    }

    .btn-small {
        padding: 8px 12px;
    }

    /* GUS button inline */
    .input-with-button {
        flex-direction: column;
        gap: 8px;
    }

    .input-with-button .btn-gus {
        width: 100%;
    }

    /* Invoice paper extra small */
    .invoice-paper {
        padding: 10px;
        font-size: 8px;
    }

    .inv-title {
        font-size: 14px;
        letter-spacing: 1px;
    }

    .inv-number {
        font-size: 11px;
    }

    .inv-table th,
    .inv-table td {
        padding: 4px 2px;
        font-size: 7px;
    }

    .inv-summary-total {
        font-size: 12px;
    }

    /* Hide some columns on very small screens */
    .inv-table th:nth-child(4),
    .inv-table td:nth-child(4),
    .inv-table th:nth-child(6),
    .inv-table td:nth-child(6) {
        display: none;
    }

    /* Intro section */
    .intro-content > p {
        font-size: 0.85rem;
    }

    .feature-icon {
        width: 24px;
        height: 24px;
        font-size: 0.75rem;
    }

    .details-content {
        padding-left: 10px;
    }

    .details-content p {
        font-size: 0.8rem;
    }

    /* Footer */
    footer {
        font-size: 0.75rem;
        padding: 10px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .preview-panel {
        min-height: 400px;
    }

    .ksef-animation-stages {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .stage {
        flex-direction: column;
        width: auto;
    }

    .stage-connector {
        display: block;
        width: 20px;
        height: 2px;
        margin: 0 5px 20px 5px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
    }

    input, select {
        min-height: 44px;
    }

    .btn-remove-item {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }

    .btn-icon {
        width: 44px;
        height: 44px;
    }
}
