/* Fakturační aplikace - styly */

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; color: #333; line-height: 1.4; }

/* Header */
.header { background: #fff; border-bottom: 1px solid #ddd; padding: 10px 20px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.header h1 { font-size: 18px; color: #0088cc; margin-right: auto; }
.header button { padding: 8px 16px; border: 1px solid #ddd; background: #fff; border-radius: 4px; cursor: pointer; font-size: 14px; }
.header button:hover { background: #f0f0f0; }
.header button.primary { background: #0088cc; color: #fff; border-color: #0088cc; }
.header button.primary:hover { background: #006699; }
.header .status { font-size: 12px; color: #666; padding: 5px 10px; background: #f0f0f0; border-radius: 4px; }
.header .status.connected { background: #d4edda; color: #155724; }

/* Main layout */
.main { display: flex; gap: 20px; padding: 20px; max-width: 1400px; margin: 0 auto; }
@media (max-width: 1000px) { .main { flex-direction: column; } }

/* Form panel */
.form-panel { flex: 0 0 400px; background: #fff; border-radius: 8px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); max-height: calc(100vh - 100px); overflow-y: auto; }
@media (max-width: 1000px) { .form-panel { flex: none; max-height: none; } }

.form-section { margin-bottom: 15px; background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; overflow: hidden; }
.form-section-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 15px; background: #f8f9fa; cursor: pointer; user-select: none;
    border-bottom: 1px solid #e0e0e0; transition: background 0.2s;
}
.form-section-header:hover { background: #e8f4fc; }
.form-section-header h3 { color: #0088cc; font-size: 14px; margin: 0; display: flex; align-items: center; gap: 8px; }
.section-icon { width: 16px; height: 16px; stroke: #0088cc; flex-shrink: 0; }
.form-section-header .toggle-icon { font-size: 12px; color: #666; transition: transform 0.3s; }
.form-section.collapsed .toggle-icon { transform: rotate(-90deg); }
.form-section-content { padding: 15px; }
.form-section.collapsed .form-section-content { display: none; }
.form-section.collapsed .form-section-header { border-bottom: none; }

.form-row { margin-bottom: 10px; }
.form-row label { display: block; font-size: 12px; color: #666; margin-bottom: 3px; }
.form-row input, .form-row select, .form-row textarea { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: #0088cc; }

.form-row-inline { display: flex; gap: 10px; }
.form-row-inline .form-row { flex: 1; }

/* Položky */
.polozky-list { border: 1px solid #eee; border-radius: 4px; margin-bottom: 10px; }
.polozka-item { padding: 10px; border-bottom: 1px solid #eee; position: relative; }
.polozka-item:last-child { border-bottom: none; }
.polozka-item .remove-btn { position: absolute; top: 5px; right: 5px; background: none; border: none; color: #cc0000; cursor: pointer; font-size: 18px; padding: 0 5px; }

.add-polozka-btn { width: 100%; padding: 10px; border: 1px dashed #0088cc; background: #f8fcff; color: #0088cc; border-radius: 4px; cursor: pointer; font-size: 14px; }
.add-polozka-btn:hover { background: #e8f4fc; }

/* Preview panel */
.preview-panel { flex: 1; background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); overflow: hidden; }
.preview-header { background: #f8f8f8; padding: 10px 20px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }
.preview-header h2 { font-size: 14px; color: #666; }
.preview-content { padding: 30px; min-height: 800px; }

/* Faktura preview */
.faktura { max-width: 210mm; min-height: 297mm; margin: 0 auto; padding: 15mm; font-family: 'Segoe UI', Roboto, sans-serif; font-size: 12px; color: #333; display: flex; flex-direction: column; box-sizing: border-box; background: #fff; }
.faktura-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.faktura-header h1 { color: #333; font-size: 24px; font-weight: normal; text-align: right; flex-grow: 1; }

.faktura-strany { display: flex; gap: 40px; margin-bottom: 30px; }
.faktura-strana { flex: 1; }
.faktura-strana h2 { color: #0088cc; font-size: 14px; font-style: italic; margin-bottom: 10px; }
.faktura-strana .jmeno { font-weight: bold; margin-bottom: 5px; }
.faktura-strana .adresa { margin-bottom: 10px; }
.faktura-strana .detail { font-size: 11px; color: #666; }
.faktura-strana .kontakt-label { color: #0088cc; font-size: 11px; margin-top: 10px; margin-bottom: 5px; }

.faktura-platba { background: #f8f8f8; padding: 15px; margin-bottom: 30px; display: flex; align-items: flex-start; gap: 30px; }
.faktura-platba-info { flex: 1; }
.faktura-platba-info h3 { color: #0088cc; font-size: 12px; margin-bottom: 10px; }
.faktura-platba-grid { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 5px 15px; font-size: 11px; }
.faktura-platba-grid .label { color: #666; }
.faktura-platba-grid .value { font-weight: bold; }

.faktura-qr { text-align: center; }
.faktura-qr canvas, .faktura-qr img, .faktura-qr svg { width: 100px !important; height: 100px !important; }
.faktura-qr-label { font-size: 10px; color: #0088cc; margin-top: 5px; }

.faktura-polozky { margin-bottom: 30px; }
.faktura-polozky table { width: 100%; border-collapse: collapse; }
.faktura-polozky th { text-align: left; padding: 8px; border-bottom: 2px solid #333; font-size: 11px; }
.faktura-polozky td { padding: 8px; border-bottom: 1px solid #eee; }
/* Zarovnání se řídí inline styly v JS pro flexibilitu s DPH sloupcem */

.faktura-celkem { text-align: right; padding: 20px; background: #f8f8f8; }
.faktura-celkem-label { color: #0088cc; font-size: 16px; font-weight: bold; margin-right: 20px; }
.faktura-celkem-value { font-size: 24px; font-weight: bold; color: #333; }

/* Modal */
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.modal.active { display: flex; }
.modal-content { background: #fff; border-radius: 8px; padding: 20px; max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { font-size: 18px; color: #0088cc; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: #999; }

/* Historie */
.historie-list { max-height: 400px; overflow-y: auto; }
.historie-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #eee; transition: background 0.2s; }
.historie-item:hover { background: #f8f8f8; }
.historie-item.overdue { background: #fff5f5; border-left: 3px solid #dc3545; }
.historie-item.overdue:hover { background: #ffebeb; }
.historie-item.paid { background: #f0fff4; border-left: 3px solid #28a745; }
.historie-item.paid:hover { background: #e6ffe6; }
.historie-item-info { cursor: pointer; flex: 1; }
.historie-item-cislo { font-weight: bold; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.historie-item-odberatel { font-size: 12px; color: #555; }
.historie-item-castka { font-weight: bold; color: #0088cc; margin-right: 10px; }
.historie-item-delete { background: none; border: none; color: #dc3545; cursor: pointer; font-size: 16px; transition: transform 0.2s; }
.historie-item-delete:hover { transform: scale(1.2); }

/* Badges pro stav faktur */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 10px; font-weight: 600; text-transform: uppercase; }
.badge-paid { background: #d4edda; color: #155724; }
.badge-overdue { background: #f8d7da; color: #721c24; }
.badge-warning { background: #fff3cd; color: #856404; }

/* Statistiky */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 20px; }
.stats-card { background: #f8f8f8; padding: 15px; border-radius: 8px; text-align: center; }
.stats-label { font-size: 12px; color: #666; margin-bottom: 5px; }
.stats-value { font-size: 24px; font-weight: bold; color: #0088cc; }
.stats-sub { font-size: 11px; color: #999; margin-top: 5px; }

.stats-chart { display: flex; gap: 5px; height: 120px; align-items: flex-end; padding: 10px; background: #f8f8f8; border-radius: 8px; }
.stats-bar-container { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.stats-bar { width: 100%; background: linear-gradient(to top, #0088cc, #00aaff); border-radius: 3px 3px 0 0; min-height: 2px; transition: height 0.3s; }
.stats-bar-label { font-size: 9px; color: #666; margin-top: 5px; text-align: center; }

.stats-table { background: #f8f8f8; border-radius: 8px; padding: 10px; }
.stats-row { display: flex; align-items: center; padding: 8px; border-bottom: 1px solid #eee; }
.stats-row:last-child { border-bottom: none; }
.stats-rank { width: 25px; color: #0088cc; font-weight: bold; }
.stats-name { flex: 1; }
.stats-amount { font-weight: bold; color: #0088cc; margin-right: 10px; }
.stats-count { font-size: 11px; color: #999; }

/* Šablony */
.sablona-item { display: flex; align-items: center; padding: 12px; border-bottom: 1px solid #eee; }
.sablona-item:hover { background: #f8f8f8; }
.sablona-info { flex: 1; cursor: pointer; }
.sablona-nazev { font-weight: bold; }
.sablona-popis { font-size: 12px; color: #666; }
.sablona-delete { background: none; border: none; color: #cc0000; cursor: pointer; font-size: 20px; padding: 5px 10px; }

/* Témata faktur */
.faktura.theme-classic .faktura-strana h2,
.faktura.theme-classic .faktura-platba-info h3,
.faktura.theme-classic .faktura-celkem-label,
.faktura.theme-classic .faktura-qr-label { color: #0088cc; }
.faktura.theme-classic .faktura-platba,
.faktura.theme-classic .faktura-celkem { background: #f8f8f8; }

.faktura.theme-modern .faktura-header h1 { color: #1a1a2e; }
.faktura.theme-modern .faktura-strana h2,
.faktura.theme-modern .faktura-platba-info h3,
.faktura.theme-modern .faktura-celkem-label,
.faktura.theme-modern .faktura-qr-label { color: #e94560; }
.faktura.theme-modern .faktura-platba,
.faktura.theme-modern .faktura-celkem { background: #fff0f3; }
.faktura.theme-modern .faktura-polozky th { border-bottom-color: #e94560; }

.faktura.theme-elegant .faktura-header h1 { color: #2c3e50; }
.faktura.theme-elegant .faktura-strana h2,
.faktura.theme-elegant .faktura-platba-info h3,
.faktura.theme-elegant .faktura-celkem-label,
.faktura.theme-elegant .faktura-qr-label { color: #27ae60; }
.faktura.theme-elegant .faktura-platba,
.faktura.theme-elegant .faktura-celkem { background: #f0fff4; }
.faktura.theme-elegant .faktura-polozky th { border-bottom-color: #27ae60; }

.faktura.theme-minimal .faktura-header h1 { color: #000; font-weight: 300; }
.faktura.theme-minimal .faktura-strana h2,
.faktura.theme-minimal .faktura-platba-info h3,
.faktura.theme-minimal .faktura-celkem-label,
.faktura.theme-minimal .faktura-qr-label { color: #666; font-style: normal; }
.faktura.theme-minimal .faktura-platba,
.faktura.theme-minimal .faktura-celkem { background: #fafafa; border: 1px solid #eee; }
.faktura.theme-minimal .faktura-polozky th { border-bottom: 1px solid #ccc; }

.faktura.theme-corporate .faktura-header h1 { color: #003366; }
.faktura.theme-corporate .faktura-strana h2,
.faktura.theme-corporate .faktura-platba-info h3,
.faktura.theme-corporate .faktura-celkem-label,
.faktura.theme-corporate .faktura-qr-label { color: #0066cc; }
.faktura.theme-corporate .faktura-platba { background: linear-gradient(135deg, #f5f8fa 0%, #e8f4fc 100%); }
.faktura.theme-corporate .faktura-celkem { background: #003366; color: #fff; }
.faktura.theme-corporate .faktura-celkem-label { color: #99ccff; }
.faktura.theme-corporate .faktura-celkem-value { color: #fff; }
.faktura.theme-corporate .faktura-polozky th { border-bottom-color: #003366; }

/* Mobile responsive */
@media (max-width: 768px) {
    .header { padding: 10px; }
    .header h1 { font-size: 14px; width: 100%; margin-bottom: 10px; }
    .header button { padding: 6px 10px; font-size: 12px; }
    .header .status { font-size: 10px; order: -1; width: 100%; text-align: center; margin-bottom: 10px; }

    .main { padding: 10px; gap: 10px; }
    .form-panel { padding: 15px; }
    .preview-content { padding: 15px; }

    /* Faktura náhled - zachovat desktop layout i na mobilu */
    .faktura { font-size: 10px; min-height: auto; }
    .faktura-header h1 { font-size: 16px; }
    /* Strany a platba zůstávají v řádku - pouze menší mezery */
    .faktura-strany { gap: 15px; }
    .faktura-platba { gap: 15px; padding: 10px; }
    .faktura-polozky { overflow-x: auto; }
    .faktura-polozky table { min-width: 350px; font-size: 9px; }
    .faktura-polozky th, .faktura-polozky td { padding: 5px; }

    .stats-grid { grid-template-columns: 1fr; }
    .stats-chart { height: 80px; }
    .stats-bar-label { font-size: 8px; }

    .modal-content { width: 95%; padding: 15px; max-height: 90vh; }
}

@media (max-width: 480px) {
    .header button { padding: 5px 8px; font-size: 11px; }
    .form-row-inline { flex-direction: column; gap: 0; }
    .faktura-celkem-value { font-size: 18px; }
}

/* Print styles */
@media print {
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; box-sizing: border-box; }

    html, body {
        width: 210mm;
        height: 297mm;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }

    .header, .form-panel, .preview-header, .modal { display: none !important; }

    .main {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100% !important;
    }

    .preview-panel {
        box-shadow: none !important;
        border-radius: 0 !important;
        background: #fff !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .preview-content {
        padding: 0 !important;
        min-height: auto !important;
    }

    .faktura {
        width: 210mm !important;
        max-width: 210mm !important;
        min-height: auto !important;
        padding: 15mm !important;
        margin: 0 !important;
        font-size: 10pt;
        page-break-inside: avoid;
        box-sizing: border-box !important;
    }

    .faktura-header { margin-bottom: 15px; }
    .faktura-header h1 { font-size: 18pt; }

    .faktura-strany {
        display: flex !important;
        flex-direction: row !important;
        gap: 20px !important;
        margin-bottom: 15px;
    }
    .faktura-strana { flex: 1; }
    .faktura-strana h2 { font-size: 11pt; }

    .faktura-platba {
        display: flex !important;
        flex-direction: row !important;
        padding: 10px !important;
        margin-bottom: 15px !important;
        gap: 15px !important;
    }
    .faktura-platba-info { flex: 1; }
    .faktura-platba-grid {
        display: grid !important;
        grid-template-columns: auto 1fr auto 1fr !important;
    }

    .faktura-qr { text-align: center; }
    .faktura-qr canvas, .faktura-qr img, .faktura-qr svg { width: 70px !important; height: 70px !important; }

    .faktura-polozky { margin-bottom: 15px; }
    .faktura-polozky table { width: 100% !important; }
    .faktura-polozky th, .faktura-polozky td { padding: 5px; font-size: 9pt; }
    .faktura-polozky thead { display: table-row-group; }

    .faktura-celkem { padding: 10px; }
    .faktura-celkem-value { font-size: 16pt; }

    /* Barvy při tisku */
    .faktura-platba, .faktura-celkem { background: #f0f0f0 !important; }
}

@page {
    size: A4 portrait;
    margin: 10mm 0;
}

/* Toast notifikace */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: #333;
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.3s ease;
    pointer-events: auto;
    max-width: 350px;
}

.toast.success { background: #28a745; }
.toast.error { background: #dc3545; }
.toast.warning { background: #ffc107; color: #333; }
.toast.info { background: #0088cc; }

.toast.hiding {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.8);
    z-index: 1500;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 15px;
}

.loading-overlay.active { display: flex; }

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #eee;
    border-top-color: #0088cc;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: #666;
    font-size: 14px;
}

/* Klávesové zkratky hint */
.keyboard-hint {
    font-size: 10px;
    color: #999;
    margin-left: 5px;
}

.header button .keyboard-hint {
    opacity: 0.7;
}

/* Validace polí */
.form-row input.invalid,
.form-row select.invalid,
.form-row textarea.invalid {
    border-color: #dc3545;
    background: #fff8f8;
}

.form-row .validation-error {
    color: #dc3545;
    font-size: 11px;
    margin-top: 3px;
}

/* Inline loading */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.btn-loading::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Tlačítka v dialogu */
.btn-primary { background: #0088cc; color: #fff; border: none; }
.btn-primary:hover { background: #006699; }
.btn-secondary { background: #fff; color: #333; border: 1px solid #ddd; }
.btn-secondary:hover { background: #f5f5f5; }
.btn-danger { background: #dc3545; color: #fff; border: none; }
.btn-danger:hover { background: #c82333; }

/* Logo ve faktuře */
.faktura-logo { margin-bottom: 10px; }
.faktura-logo img { max-width: 120px; max-height: 60px; object-fit: contain; }

/* DPH souhrn */
.faktura-dph-souhrn { margin-bottom: 15px; padding: 10px; background: #f8f8f8; border-radius: 4px; }
.faktura-dph-souhrn table { font-size: 11px; }
.faktura-dph-souhrn td { padding: 3px 10px; }

/* Lepší kontrast pro texty */
.form-row label { color: #444; }
.historie-item-odberatel { color: #555; }
.faktura-strana .detail { color: #555; }
.stats-label { color: #555; }
.stats-sub { color: #777; }

/* Focus styly pro přístupnost */
button:focus, input:focus, select:focus, textarea:focus {
    outline: 2px solid #0088cc;
    outline-offset: 2px;
}

.modal-close:focus {
    outline: 2px solid #0088cc;
    outline-offset: 2px;
}

/* Skip link pro přístupnost */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0088cc;
    color: #fff;
    padding: 8px 16px;
    z-index: 9999;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* Animace pro hover efekty */
.header button {
    transition: background 0.2s, transform 0.1s;
}

.header button:active {
    transform: scale(0.98);
}

/* Vylepšené styly pro modály */
.modal-content {
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Indikátor neuložených změn */
.header .unsaved-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #ffc107;
    border-radius: 50%;
    margin-left: 5px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
