/* P2P Tracker – Base Styles */
*, *::before, *::after { box-sizing: border-box; }

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

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Navigation */
.main-nav {
    background: #1e293b;
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 56px;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    margin-right: 2rem;
}

.nav-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 0.25rem;
}

.nav-links a {
    color: #94a3b8;
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: color 0.15s, background 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
    color: #fff;
    background: #334155;
}

.nav-logout {
    margin-left: auto;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

th, td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.9rem;
}

th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

/* Forms */
.upload-form {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    max-width: 500px;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: #475569;
}

.form-group select,
.form-group input[type="file"] {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: #94a3b8;
    font-size: 0.8rem;
}

.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

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

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.result-table {
    max-width: 400px;
    margin-bottom: 1rem;
}

.error-list {
    font-size: 0.85rem;
    color: #dc2626;
}

h1 {
    font-size: 1.5rem;
    margin: 0 0 1rem;
    color: #1e293b;
}

/* Filters bar */
.filters-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 1rem;
}

.filters-bar select,
.filters-bar input[type="text"] {
    padding: 0.4rem 0.6rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.85rem;
}

/* Status badge */
.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
}

/* Table sorting links */
th a {
    color: inherit;
    text-decoration: none;
}

th a:hover {
    text-decoration: underline;
}

/* Responsive table */
.table-wrap {
    overflow-x: auto;
}

/* Loan profile */
.loan-header {
    margin-bottom: 1.5rem;
}

.loan-header h1 {
    margin-bottom: 0.5rem;
}

.loan-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.9rem;
    color: #475569;
}

.meta-item strong {
    color: #1e293b;
}

/* KPI cards */
.kpi-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: #fff;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    min-width: 140px;
    flex: 1;
}

.kpi-label {
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #1e293b;
}

/* Status history row highlights */
.row-recovery td {
    background: #f0fdf4 !important;
}

.row-worsening td {
    background: #fef2f2 !important;
}

/* Notes */
.notes-textarea {
    width: 100%;
    max-width: 600px;
    padding: 0.6rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
}

h2 {
    font-size: 1.2rem;
    margin: 1.5rem 0 0.75rem;
    color: #1e293b;
}

/* Charts grid */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.chart-box {
    background: #fff;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.chart-box h2 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}
.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.chart-header h2 { margin: 0; }
.chart-toggle {
    display: flex;
    gap: 2px;
    background: #e2e8f0;
    border-radius: 6px;
    padding: 2px;
}
.toggle-btn {
    padding: 0.25rem 0.6rem;
    border: none;
    background: transparent;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    color: #64748b;
    font-weight: 500;
}
.toggle-btn.active {
    background: #fff;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chart-wide {
    grid-column: 1 / -1;
}

/* Insights */
.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.insight-card {
    background: #fff;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-left: 4px solid #2563eb;
}

.insight-card.insight-warn { border-left-color: #eab308; }
.insight-card.insight-danger { border-left-color: #ef4444; }
.insight-card.insight-good { border-left-color: #22c55e; }

.insight-title {
    font-size: 0.85rem;
    color: #64748b;
    margin-bottom: 0.25rem;
}

.insight-count {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.insight-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.85rem;
}

.insight-list li {
    padding: 0.2rem 0;
}

.insight-list a {
    color: #2563eb;
    text-decoration: none;
}

.insight-list a:hover {
    text-decoration: underline;
}

.insight-list small {
    color: #94a3b8;
    margin-left: 0.3rem;
}

/* Import progress */
.import-progress {
    background: #fff;
    padding: 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 1rem;
}

.progress-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.progress-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #e2e8f0;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.progress-spinner.spinner-done {
    border-color: #22c55e;
    animation: none;
    background: #22c55e;
}

.progress-spinner.spinner-error {
    border-color: #ef4444;
    animation: none;
    background: #ef4444;
}

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

.progress-stats {
    font-size: 0.9rem;
    color: #475569;
    margin-bottom: 0.75rem;
}

.progress-stats span {
    font-weight: 700;
    color: #1e293b;
}

.progress-bar-wrap {
    background: #e2e8f0;
    border-radius: 4px;
    height: 6px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: #2563eb;
    border-radius: 4px;
    width: 30%;
    animation: progress-pulse 1.5s ease-in-out infinite;
    transition: width 0.3s;
}

@keyframes progress-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* File hint */
.file-hint {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    color: #1e40af;
    margin-top: 0.5rem;
}

/* Settings page */
.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.inline-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #fff;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.action-info {
    font-size: 0.8rem;
    color: #64748b;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
}

/* CSV Diagnostics panel */
.diag-panel {
    background: #1e293b;
    border-radius: 8px;
    overflow: hidden;
}

.diag-toggle {
    padding: 0.75rem 1rem;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
}

.diag-toggle:hover { color: #e2e8f0; }

details[open] .diag-toggle {
    color: #38bdf8;
    border-bottom: 1px solid #334155;
}

.diag-body {
    padding: 1rem;
    color: #e2e8f0;
    font-size: 0.85rem;
}

.diag-body h3 {
    color: #38bdf8;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 1.25rem 0 0.5rem;
}

.diag-body h3:first-child { margin-top: 0; }

.diag-table {
    width: 100%;
    border-collapse: collapse;
    background: #0f172a;
    border-radius: 6px;
    overflow: hidden;
    font-size: 0.8rem;
    box-shadow: none;
}

.diag-table th,
.diag-table td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid #1e293b;
    color: #cbd5e1;
    background: transparent;
}

.diag-table th {
    background: #1e293b;
    color: #64748b;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.diag-table tr:hover td { background: #1e293b; }

.diag-table td:first-child { color: #64748b; white-space: nowrap; }
.diag-table td strong { color: #f1f5f9; }

.diag-values {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.diag-val {
    background: #334155;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.75rem;
    color: #e2e8f0;
    white-space: nowrap;
}

.diag-val small { color: #64748b; margin-left: 0.2rem; }
.diag-note { color: #64748b; display: block; margin-top: 0.25rem; }

.diag-scroll {
    overflow-x: auto;
    max-width: 100%;
}

.diag-raw td { white-space: nowrap; font-family: monospace; font-size: 0.75rem; }

.diag-export {
    width: 100%;
    background: #0f172a;
    color: #a5f3fc;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 0.75rem;
    font-family: monospace;
    font-size: 0.75rem;
    resize: vertical;
}

/* Timeline */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 2rem;
}
.timeline-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    background: #1e293b;
    border-radius: 0.5rem;
    border-left: 3px solid #3b82f6;
}
.timeline-icon { font-size: 1.1rem; }
.timeline-date {
    color: #94a3b8;
    font-size: 0.85rem;
    min-width: 6rem;
}
.timeline-label {
    flex: 1;
    color: #e2e8f0;
    font-weight: 500;
}
.timeline-amount {
    color: #22c55e;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.timeline-info {
    border-left-color: #475569;
}
.timeline-info .timeline-amount {
    color: #94a3b8;
}

@media (max-width: 768px) {
    .charts-grid { grid-template-columns: 1fr; }
    .kpi-row { flex-direction: column; }
    .insights-grid { grid-template-columns: 1fr; }
    .timeline-item { flex-wrap: wrap; }
}
