/* APE Finance Viewer - External Dashboard CSS */

.ape-viewer-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    color: #1f2937;
}

/* Login */
.viewer-login {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-box {
    background: #fff;
    border-radius: 16px;
    padding: 48px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h2 {
    margin: 0 0 8px;
    font-size: 28px;
    color: #1f2937;
}

.login-header p {
    margin: 0;
    color: #6b7280;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #374151;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.btn-login {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

.login-error {
    margin-top: 16px;
    padding: 12px;
    background: #fef2f2;
    color: #dc2626;
    border-radius: 8px;
    text-align: center;
    display: none;
}

.login-error.show {
    display: block;
}

/* Dashboard */
.viewer-dashboard {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Header */
.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
}

.header-left h1 {
    margin: 0 0 4px;
    font-size: 24px;
    color: #1f2937;
}

.header-left span {
    color: #6b7280;
    font-size: 14px;
}

.btn-primary, .btn-secondary {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background: #3b82f6;
    color: #fff;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
}

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

.btn-large {
    padding: 14px 28px;
    font-size: 16px;
}

/* Stats Cards */
.viewer-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid #e5e7eb;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card.income .stat-icon {
    background: linear-gradient(135deg, #10b981, #059669);
}

.stat-card.income .stat-icon::before {
    content: "\2191";
    font-size: 20px;
    color: #fff;
}

.stat-card.expense .stat-icon {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.stat-card.expense .stat-icon::before {
    content: "\2193";
    font-size: 20px;
    color: #fff;
}

.stat-card.net .stat-icon {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.stat-card.net .stat-icon::before {
    content: "=";
    font-size: 20px;
    color: #fff;
    font-weight: bold;
}

.stat-card.count .stat-icon {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.stat-card.count .stat-icon::before {
    content: "#";
    font-size: 20px;
    color: #fff;
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: #1f2937;
}

.stat-label {
    font-size: 13px;
    color: #6b7280;
}

/* Tabs */
.viewer-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    border-radius: 8px 8px 0 0;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: #3b82f6;
    background: #f3f4f6;
}

.tab-btn.active {
    color: #3b82f6;
    background: #eff6ff;
    border-bottom: 2px solid #3b82f6;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Filters */
.viewer-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
    padding: 16px;
    background: #f9fafb;
    border-radius: 10px;
}

.viewer-filters select,
.viewer-filters input {
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    min-width: 140px;
}

.viewer-filters input[type="text"] {
    min-width: 180px;
}

/* Table */
.viewer-table-wrap {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid #e5e7eb;
}

.viewer-table {
    width: 100%;
    border-collapse: collapse;
}

.viewer-table th {
    background: #f9fafb;
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
}

.viewer-table td {
    padding: 14px 16px;
    border-bottom: 1px solid #f3f4f6;
    font-size: 14px;
}

.viewer-table tr:hover {
    background: #f9fafb;
}

.viewer-table .loading {
    text-align: center;
    padding: 40px;
    color: #9ca3af;
}

.amount-positive {
    color: #059669;
    font-weight: 600;
}

.amount-negative {
    color: #dc2626;
    font-weight: 600;
}

.account-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
}

.category-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
}

.note-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #6b7280;
    font-style: italic;
    font-size: 13px;
}

/* Pagination */
.viewer-pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 20px;
}

.viewer-pagination button {
    padding: 8px 16px;
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.viewer-pagination button:hover {
    background: #f3f4f6;
}

.viewer-pagination button.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

.viewer-pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Categories Grid */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.category-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid #e5e7eb;
    border-left: 4px solid #6b7280;
}

.category-card h4 {
    margin: 0 0 12px;
    font-size: 16px;
    color: #1f2937;
}

.category-stats {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.category-stats .income {
    color: #059669;
}

.category-stats .expense {
    color: #dc2626;
}

/* Accounts Grid */
.accounts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.account-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid #e5e7eb;
    border-left: 4px solid #3b82f6;
}

.account-card h4 {
    margin: 0 0 4px;
    font-size: 18px;
    color: #1f2937;
}

.account-card .bank {
    margin: 0 0 16px;
    color: #6b7280;
    font-size: 14px;
}

.account-card .balance {
    font-size: 24px;
    font-weight: 700;
}

.account-card .transactions-count {
    margin-top: 8px;
    font-size: 13px;
    color: #6b7280;
}

/* Export Section */
.export-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
    max-width: 900px;
    margin: 0 auto;
}

.export-section {
    padding: 30px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid #e5e7eb;
    text-align: center;
}

.export-section h3 {
    margin: 0 0 8px;
    color: #1f2937;
}

.export-section p {
    color: #6b7280;
    margin-bottom: 20px;
    font-size: 14px;
}

.export-filters {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
    text-align: left;
}

.export-filters .form-group {
    margin: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .ape-viewer-container {
        padding: 12px;
    }

    .login-box {
        padding: 32px 24px;
    }

    .viewer-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    .viewer-filters {
        flex-direction: column;
    }

    .viewer-filters select,
    .viewer-filters input {
        width: 100%;
    }

    .viewer-stats {
        grid-template-columns: 1fr 1fr;
    }

    .viewer-tabs {
        overflow-x: auto;
    }

    .tab-btn {
        white-space: nowrap;
    }
}

/* ==========================================
   REQUESTS (Richieste chiarimento)
   ========================================== */

/* Badge in tab */
.requests-badge {
    display: inline-block;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 4px;
    min-width: 16px;
    text-align: center;
    vertical-align: middle;
}

/* Request info button */
.request-info-btn {
    background: transparent;
    border: 1px solid #d1d5db;
    color: #9ca3af;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s;
    padding: 0;
    line-height: 20px;
    text-align: center;
    vertical-align: middle;
}

.request-info-btn:hover {
    background: #f59e0b;
    border-color: #f59e0b;
    color: #fff;
}

.viewer-table td:last-child {
    text-align: center;
    padding: 8px 4px;
}

/* Request cards */
.requests-section {
    padding: 20px;
}

.requests-list {
    max-height: 600px;
    overflow-y: auto;
}

.request-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    transition: box-shadow 0.2s;
}

.request-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.request-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.request-tx-info strong {
    font-size: 14px;
    color: #1f2937;
}

.request-tx-info small {
    color: #6b7280;
}

.request-status {
    color: #fff;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

.request-message {
    background: #fef3c7;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    border-left: 3px solid #f59e0b;
}

.request-message small {
    color: #92400e;
    font-weight: 600;
}

.request-response {
    background: #ecfdf5;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    border-left: 3px solid #10b981;
}

.request-response small {
    color: #059669;
    font-weight: 600;
}

.request-footer {
    color: #9ca3af;
}

/* Request Modal */
.viewer-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.viewer-modal.active {
    display: flex;
}

.viewer-modal .modal-content {
    background: #fff;
    border-radius: 12px;
    max-width: 500px;
    width: 95%;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

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

.viewer-modal .modal-header h3 {
    margin: 0;
    color: #1f2937;
}

.viewer-modal .modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #6b7280;
    line-height: 1;
    padding: 0;
}

.viewer-modal .modal-close:hover {
    color: #1f2937;
}

.request-tx-info {
    background: #f3f4f6;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.viewer-modal .form-group {
    margin-bottom: 16px;
}

.viewer-modal .form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #374151;
}

.viewer-modal textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
}

.viewer-modal textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.viewer-modal .modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Corrispettivi & IVA Section */
.corrispettivi-section {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
}

.corrispettivi-section h3 {
    margin: 0 0 8px;
    color: #1f2937;
}

.corr-filters {
    background: #f9fafb;
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 24px;
}

.corr-filters .form-group {
    margin-bottom: 0;
}

.corr-filters select {
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    min-width: 140px;
}

.vat-summary-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.vat-card {
    padding: 16px;
    border-radius: 10px;
    color: #fff;
}

@media (max-width: 900px) {
    .vat-summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 500px) {
    .vat-summary-cards {
        grid-template-columns: 1fr;
    }
}

/* Corrispettivi Sub-Tabs */
.viewer-corr-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 20px;
}

.viewer-corr-tab {
    padding: 10px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    color: #6b7280;
    font-size: 14px;
    transition: all 0.2s;
}

.viewer-corr-tab:hover {
    color: #3b82f6;
}

.viewer-corr-tab.active {
    border-bottom-color: #2563eb;
    color: #2563eb;
}

/* ==========================================
   RECONCILIATION (Riconciliazione)
   ========================================== */

.reconciliation-section {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
}

/* Flow cards */
.recon-flow {
    margin-bottom: 24px;
}

.flow-card {
    transition: transform 0.2s;
}

.flow-card:hover {
    transform: translateY(-2px);
}

.flow-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 24px;
}

/* Source comparison table */
#viewer-recon-source-body tr {
    transition: background 0.2s;
}

#viewer-recon-source-body tr:hover {
    background: #f8fafc;
}

/* B2B section */
#viewer-b2b-total {
    font-size: 15px;
}

#viewer-b2b-body td {
    font-size: 12px;
    padding: 8px 12px;
}

#viewer-b2b-body td:nth-child(2) {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Unmatched payouts */
#viewer-unmatched-body td {
    font-size: 12px;
    padding: 8px 12px;
}

/* Reconciliation status alerts */
.recon-status {
    border-radius: 8px;
    padding: 16px;
}

/* Notes section */
#viewer-recon-notes li {
    margin-bottom: 6px;
}

/* Responsive reconciliation */
@media (max-width: 900px) {
    .reconciliation-section .recon-flow {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .flow-arrow {
        transform: rotate(90deg);
        padding: 8px 0;
    }

    .reconciliation-section > div[style*="grid-template-columns: 1fr 1fr"],
    .reconciliation-section > div[style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}
