/* Xero Analytics Styles */

/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f1f5f9;
    color: #1e293b;
    line-height: 1.5;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 16px;
    flex-wrap: wrap;
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    color: #0f172a;
}

.back-link {
    font-size: 13px;
    color: #13b5ea;
    text-decoration: none;
}
.back-link:hover {
    text-decoration: underline;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary { background: #13b5ea; color: white; }
.btn-primary:hover { background: #0ea5e0; }

/* Freshness indicator */
.freshness-indicator {
    font-size: 12px;
    color: #64748b;
    background: #f8fafc;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.freshness-fresh { color: #16a34a; border-color: #bbf7d0; background: #f0fdf4; }
.freshness-stale { color: #d97706; border-color: #fde68a; background: #fffbeb; }
.freshness-old { color: #dc2626; border-color: #fecaca; background: #fef2f2; }
.freshness-none { color: #94a3b8; }

/* Tab Navigation */
.tab-nav {
    display: flex;
    gap: 2px;
    background: #e2e8f0;
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
    white-space: nowrap;
    min-width: 100px;
    text-align: center;
}

.tab-btn:hover {
    color: #1e293b;
    background: rgba(255,255,255,0.5);
}

.tab-btn.active {
    background: white;
    color: #13b5ea;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.tab-separator { width: 1px; background: #cbd5e1; margin: 6px 4px; flex-shrink: 0; }
.tab-link { text-decoration: none; color: #64748b; }

.tab-nav + .sub-tab-nav { margin-top: -16px; }
.sub-tab-nav {
    display: flex;
    gap: 2px;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 20px;
    margin-left: 24px;
    overflow-x: auto;
}
.sub-tab-nav .tab-btn {
    flex: 0;
    padding: 8px 16px;
    font-size: 13px;
    min-width: auto;
}

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

/* KPI Cards */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
    word-break: break-word;
}

.kpi-subtitle {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 4px;
}

/* Color accents for KPI cards */
.kpi-green { border-left: 4px solid #22c55e; }
.kpi-red { border-left: 4px solid #ef4444; }
.kpi-blue { border-left: 4px solid #13b5ea; }
.kpi-orange { border-left: 4px solid #f97316; }
.kpi-purple { border-left: 4px solid #8b5cf6; }

/* Charts */
.chart-container {
    background: white;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    margin-bottom: 24px;
    height: 400px;
    position: relative;
}

.chart-container.chart-tall {
    height: 500px;
}

.chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.chart-half {
    background: white;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e2e8f0;
}

/* Aging Table */
.aging-table-wrap {
    background: white;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    margin-bottom: 24px;
    overflow-x: auto;
}

.aging-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.aging-table th {
    text-align: left;
    padding: 10px 12px;
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
    font-weight: 600;
    color: #475569;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.aging-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
}

.aging-table td.money {
    font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
    text-align: right;
}

.aging-table th:nth-child(n+2) {
    text-align: right;
}

.aging-table td:nth-child(n+2) {
    text-align: right;
}

.aging-table .total-row {
    background: #f8fafc;
    border-top: 2px solid #e2e8f0;
}

/* Data Tables */
.data-table-wrap {
    background: white;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    margin-bottom: 24px;
    overflow-x: auto;
}

.data-table-wrap table.dataTable {
    width: 100% !important;
}

/* Overdue severity */
.severity-critical { }
.severity-high { }
.severity-medium { }
.severity-low { }

.days-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

.days-badge.severity-critical {
    background: #fef2f2;
    color: #991b1b;
}
.days-badge.severity-high {
    background: #fff7ed;
    color: #9a3412;
}
.days-badge.severity-medium {
    background: #fffbeb;
    color: #92400e;
}
.days-badge.severity-low {
    background: #f0fdf4;
    color: #166534;
}

/* Pipeline */
.pipeline-tables {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.pipeline-half {
    background: white;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e2e8f0;
}

.pipeline-half h3 {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 12px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.status-draft { background: #f1f5f9; color: #64748b; }
.status-submitted { background: #eef2ff; color: #4338ca; }
.status-authorised { background: #ecfeff; color: #0e7490; }
.status-paid { background: #f0fdf4; color: #16a34a; }
.status-voided { background: #fff7ed; color: #c2410c; }
.status-deleted { background: #fef2f2; color: #dc2626; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
    font-size: 16px;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #64748b;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #13b5ea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

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

/* Error */
.error-message {
    text-align: center;
    padding: 40px;
    color: #dc2626;
    background: #fef2f2;
    border-radius: 10px;
    border: 1px solid #fecaca;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
    .container { padding: 12px; }

    .header h1 { font-size: 20px; }

    .kpi-row {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .kpi-card { padding: 14px; }
    .kpi-value { font-size: 18px; }

    .chart-row,
    .pipeline-tables {
        grid-template-columns: 1fr;
    }

    .chart-container { height: 300px; }
    .chart-container.chart-tall { height: 350px; }

    .tab-btn {
        padding: 8px 10px;
        font-size: 12px;
        min-width: 70px;
    }
}

@media (max-width: 480px) {
    .kpi-row {
        grid-template-columns: 1fr;
    }
}

/* Refresh Banner */
.xero-refresh-banner {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
    border-radius: 8px;
    margin: 0 0 0 0;
}

.xero-refresh-banner.xrb-visible {
    max-height: 80px;
    margin: 0 0 12px 0;
}

.xrb-inner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    min-height: 56px;
    border-radius: 8px;
}

.xrb-icon {
    font-size: 22px;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.xrb-body { flex: 1; min-width: 0; }
.xrb-title { font-size: 15px; font-weight: 600; line-height: 1.3; }
.xrb-step { font-size: 13px; opacity: 0.85; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xrb-progress { flex-shrink: 0; width: 180px; }
.xrb-bar { height: 8px; background: rgba(255,255,255,0.3); border-radius: 4px; overflow: hidden; }
.xrb-fill { height: 100%; border-radius: 4px; transition: width 0.5s; width: 0; background: rgba(255,255,255,0.8); }

.xrb-dismiss {
    flex-shrink: 0; background: none; border: none; font-size: 22px;
    cursor: pointer; opacity: 0.6; padding: 4px 8px; line-height: 1; color: inherit;
}
.xrb-dismiss:hover { opacity: 1; }

.xrb-running .xrb-inner { background: linear-gradient(135deg, #0369a1, #0ea5e9); color: white; }
.xrb-running .xrb-icon { animation: xrb-spin 1.2s linear infinite; }
@keyframes xrb-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.xrb-complete .xrb-inner { background: linear-gradient(135deg, #15803d, #22c55e); color: white; }
.xrb-complete .xrb-fill { background: rgba(255,255,255,0.5); }
.xrb-failed .xrb-inner { background: linear-gradient(135deg, #991b1b, #dc2626); color: white; }
.xrb-failed .xrb-fill { background: rgba(255,255,255,0.3); }

@media (max-width: 600px) {
    .xrb-progress { display: none; }
    .xrb-step { white-space: normal; }
}

/* ========================================
   Dark Mode - [data-theme="dark"]
   ======================================== */

[data-theme="dark"] body {
    background: #0f172a;
    color: #e2e8f0;
}

[data-theme="dark"] .header h1 {
    color: #f1f5f9;
}
[data-theme="dark"] .btn-primary { background: #38bdf8; color: #0c4a6e; }
[data-theme="dark"] .btn-primary:hover { background: #7dd3fc; }

[data-theme="dark"] .freshness-indicator {
    background: #1e293b;
    border-color: #334155;
    color: #94a3b8;
}

[data-theme="dark"] .freshness-fresh { color: #4ade80; border-color: #166534; background: #14532d33; }
[data-theme="dark"] .freshness-stale { color: #fbbf24; border-color: #92400e; background: #78350f33; }
[data-theme="dark"] .freshness-old { color: #f87171; border-color: #991b1b; background: #7f1d1d33; }

/* Tabs dark */
[data-theme="dark"] .tab-nav {
    background: #1e293b;
}

[data-theme="dark"] .tab-btn {
    color: #94a3b8;
}

[data-theme="dark"] .tab-btn:hover {
    color: #e2e8f0;
    background: rgba(255,255,255,0.05);
}

[data-theme="dark"] .tab-btn.active {
    background: #334155;
    color: #38bdf8;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

[data-theme="dark"] .sub-tab-nav {
    background: #0f172a;
}

/* KPI cards dark */
[data-theme="dark"] .kpi-card {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .kpi-label {
    color: #94a3b8;
}

[data-theme="dark"] .kpi-value {
    color: #f1f5f9;
}

[data-theme="dark"] .kpi-subtitle {
    color: #64748b;
}

/* Chart containers dark */
[data-theme="dark"] .chart-container,
[data-theme="dark"] .chart-half {
    background: #1e293b;
    border-color: #334155;
}

/* Aging table dark */
[data-theme="dark"] .aging-table-wrap {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .aging-table th {
    background: #0f172a;
    border-color: #334155;
    color: #94a3b8;
}

[data-theme="dark"] .aging-table td {
    border-color: #1e293b;
    color: #cbd5e1;
}

[data-theme="dark"] .aging-table .total-row {
    background: #0f172a;
    border-color: #334155;
}

/* Data tables dark */
[data-theme="dark"] .data-table-wrap {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .data-table-wrap table.dataTable thead th {
    background: #0f172a;
    color: #94a3b8;
    border-color: #334155;
}

[data-theme="dark"] .data-table-wrap table.dataTable tbody td {
    color: #cbd5e1;
    border-color: #1e293b;
}

[data-theme="dark"] .data-table-wrap table.dataTable tbody tr:hover {
    background: #334155 !important;
}

[data-theme="dark"] .data-table-wrap .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .data-table-wrap .dataTables_wrapper .dataTables_length select {
    background: #0f172a;
    border: 1px solid #334155;
    color: #e2e8f0;
    border-radius: 4px;
    padding: 4px 8px;
}

[data-theme="dark"] .data-table-wrap .dataTables_wrapper .dataTables_info,
[data-theme="dark"] .data-table-wrap .dataTables_wrapper .dataTables_filter label,
[data-theme="dark"] .data-table-wrap .dataTables_wrapper .dataTables_length label {
    color: #94a3b8;
}

[data-theme="dark"] .data-table-wrap .dataTables_wrapper .dataTables_paginate .paginate_button {
    color: #94a3b8 !important;
}

[data-theme="dark"] .data-table-wrap .dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: #334155 !important;
    border-color: #475569 !important;
    color: #e2e8f0 !important;
}

/* Days badge dark */
[data-theme="dark"] .days-badge.severity-critical {
    background: #7f1d1d;
    color: #fca5a5;
}
[data-theme="dark"] .days-badge.severity-high {
    background: #7c2d12;
    color: #fdba74;
}
[data-theme="dark"] .days-badge.severity-medium {
    background: #78350f;
    color: #fde68a;
}
[data-theme="dark"] .days-badge.severity-low {
    background: #14532d;
    color: #86efac;
}

/* Pipeline dark */
[data-theme="dark"] .pipeline-half {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .pipeline-half h3 {
    color: #f1f5f9;
}

[data-theme="dark"] .status-draft { background: #334155; color: #94a3b8; }
[data-theme="dark"] .status-submitted { background: #312e81; color: #a5b4fc; }
[data-theme="dark"] .status-authorised { background: #164e63; color: #67e8f9; }
[data-theme="dark"] .status-paid { background: #14532d; color: #86efac; }
[data-theme="dark"] .status-voided { background: #7c2d12; color: #fdba74; }
[data-theme="dark"] .status-deleted { background: #7f1d1d; color: #fca5a5; }

/* Empty/loading/error dark */
[data-theme="dark"] .loading {
    color: #94a3b8;
}

[data-theme="dark"] .loading-spinner {
    border-color: #334155;
    border-top-color: #38bdf8;
}

[data-theme="dark"] .empty-state {
    color: #64748b;
}

[data-theme="dark"] .error-message {
    background: #7f1d1d33;
    border-color: #991b1b;
    color: #f87171;
}

[data-theme="dark"] .tab-separator { background: #475569; }
[data-theme="dark"] .tab-link { color: #94a3b8; }

[data-theme="dark"] .xrb-running .xrb-inner {
    background: linear-gradient(135deg, #0c4a6e, #075985);
}

[data-theme="dark"] .xrb-complete .xrb-inner {
    background: linear-gradient(135deg, #14532d, #166534);
}

[data-theme="dark"] .xrb-failed .xrb-inner {
    background: linear-gradient(135deg, #7f1d1d, #991b1b);
}
