/* Dashboard Page Styles - Matches Letters/Templates Design */

.dashboard-page {
    max-width: 2500px;
    margin: 0 auto;
    outline: none;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}

.page-title h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.page-title p {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    padding: 24px;
    transition: all 0.2s ease;
}

.stat-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.stat-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-icon.blue {
    background: var(--color-primary-bg);
    color: var(--color-primary);
}

.stat-icon.green {
    background: var(--color-success-bg);
    color: var(--color-success-text);
}

/* Teal — Engage's no-token teal (matches the Internal Review badge), replaces the
   banned purple accent. */
.stat-icon.teal {
    background: #ccfbf1;
    color: #115e59;
}

.stat-icon.orange {
    background: var(--color-warning-bg);
    color: var(--color-warning-text);
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 8px;
}

/* Option B: the number itself carries the metric's accent color. */
.stat-value.blue { color: var(--color-primary-hover); }
.stat-value.green { color: var(--color-success); }
.stat-value.amber { color: var(--color-warning-text); }
.stat-value.teal { color: #115e59; }

.stat-change {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-change i {
    font-size: 12px;
}

.stat-change.positive {
    color: var(--color-success);
}

.stat-change.negative {
    color: var(--color-danger);
}

/* Content Section */
.content-section {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    margin-bottom: 24px;
    overflow: visible;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--bg-secondary);
}

.data-table th {
    padding: 14px 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    text-align: left;
    border-bottom: 1px solid var(--border-primary);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--bg-tertiary);
    transition: background 0.15s ease;
}

.data-table tbody tr:last-child {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--bg-secondary);
}

.data-table td {
    padding: 16px 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.data-table td strong {
    color: var(--text-primary);
    font-weight: 500;
}

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-badge.draft {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.status-badge.pending,
.status-badge.review {
    background: #fef3c7;
    color: #92400e;
}

.status-badge.approved,
.status-badge.complete {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.sent {
    background: #dbeafe;
    color: #1e40af;
}

.status-badge.failed {
    background: #fee2e2;
    color: #991b1b;
}

.status-badge.generating {
    background: #f1f5f9;
    color: #475569;
}

/* Action Button */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border-primary);
    background: var(--bg-primary);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--color-primary);
    border-color: var(--text-faint);
}

/* Quick Actions Grid */
.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    padding: 24px;
}

.quick-action-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
}

.quick-action-card:hover {
    background: var(--bg-primary);
    border-color: var(--color-primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
    transform: translateY(-2px);
}

.quick-action-card .icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.quick-action-card .icon-wrapper.blue {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    color: var(--color-primary);
}

.quick-action-card .icon-wrapper.green {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: var(--color-success);
}

.quick-action-card .icon-wrapper.purple {
    background: #ccfbf1;
    color: #115e59;
}

.quick-action-card .icon-wrapper.orange {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #d97706;
}

.quick-action-info h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
}

.quick-action-info p {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    text-align: center;
}

.empty-state i {
    font-size: 48px;
    color: var(--text-faint);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* Loading */
.loading-container {
    display: flex;
    justify-content: center;
    padding: 60px 0;
}

/* Buttons — see design-tokens.css for canonical button rules. */

/* Chart Container */
.chart-container {
    padding: 20px 24px;
    height: 350px;
    position: relative;
}

/* Responsive */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .quick-actions-grid {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        gap: 16px;
    }

    .section-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .chart-container {
        height: 300px;
        padding: 16px;
    }
}

/* #125: Signature Performance scorecard panel */
.sig-window {
    font-size: 12px;
    color: var(--text-muted, #6b7280);
}

.sig-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 18px;
}

.sig-metric-card {
    background: var(--bg-secondary, #f9fafb);
    border: 1px solid var(--border-primary, #e5e7eb);
    border-radius: 8px;
    padding: 14px 16px;
}

.sig-metric-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #6b7280);
}

.sig-metric-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary, #111827);
    line-height: 1.2;
    margin: 4px 0 2px;
}

.sig-metric-sub {
    font-size: 11px;
    color: var(--text-muted, #6b7280);
}

.sig-buckets {
    background: var(--bg-secondary, #f9fafb);
    border: 1px solid var(--border-primary, #e5e7eb);
    border-radius: 8px;
    padding: 14px 16px;
}

.sig-buckets-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #6b7280);
    margin-bottom: 12px;
}

/* Outstanding-by-age "risk bar": one segmented horizontal bar, green (fresh) → red (stale). */
.sig-riskbar {
    display: flex;
    height: 34px;
    border-radius: var(--radius-md, 6px);
    overflow: hidden;
    background: var(--bg-tertiary, #f3f4f6);
}

.sig-riskseg {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    transition: width 0.2s ease;
}

.sig-riskbar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 12px;
    font-size: 11px;
    color: var(--text-muted, #6b7280);
}

.sig-riskbar-legend span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.sig-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
}

.sig-riskbar-empty {
    font-size: 13px;
    color: var(--text-muted, #6b7280);
}

/* Green → red aging ramp (fresh to stale). */
.sig-age-0 { background: #059669; }
.sig-age-1 { background: #16a34a; }
.sig-age-2 { background: #f59e0b; }
.sig-age-3 { background: #d97706; }
.sig-age-4 { background: #e57373; }

@media (max-width: 720px) {
    .sig-metrics-grid {
        grid-template-columns: 1fr;
    }
}

/* #125: Most Used Clauses — design-aligned horizontal bars (top 5). */
.clause-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.clause-bar-row {
    display: grid;
    grid-template-columns: minmax(0, 200px) 1fr 36px;
    align-items: center;
    gap: 14px;
}

.clause-bar-name {
    font-size: 13px;
    color: var(--text-secondary, #374151);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.clause-bar-track {
    height: 8px;
    background: var(--bg-tertiary, #f3f4f6);
    border-radius: 9999px;
    overflow: hidden;
}

.clause-bar-fill {
    display: block;
    height: 100%;
    min-width: 4px;
    background: var(--color-primary, #2563eb);
    border-radius: 9999px;
    transition: width 0.2s ease;
}

.clause-bar-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #111827);
    text-align: right;
}

/* Most Used Clauses — doughnut + custom legend */
.clause-pie-wrap {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 8px 4px;
}

.clause-pie-canvas {
    position: relative;
    width: 200px;
    height: 200px;
    flex: 0 0 200px;
}

.clause-pie-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.clause-pie-legend li {
    display: flex;
    align-items: center;
    gap: 10px;
}

.clause-pie-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex: 0 0 12px;
}

.clause-pie-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--text-primary, #111827);
}

.clause-pie-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #374151);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
    .clause-pie-wrap { flex-direction: column; align-items: stretch; }
    .clause-pie-canvas { align-self: center; }
}

/* #126 P3: health score badge + stage-breakdown bar */
.sig-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sig-health {
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
}

.sig-health-num { font-size: 14px; }
.sig-health-max { font-size: 11px; opacity: 0.7; font-weight: 500; }
.sig-health-cap { font-size: 11px; font-weight: 500; margin-left: 4px; text-transform: uppercase; letter-spacing: 0.3px; }

.sig-health.good { background: var(--color-success-bg, #d1fae5); color: var(--color-success-text, #065f46); }
.sig-health.ok { background: var(--color-warning-bg, #fef3c7); color: var(--color-warning-text, #92400e); }
.sig-health.poor { background: var(--color-danger-bg, #fee2e2); color: #991b1b; }

.sig-stage-sent { background: var(--color-primary, #2563eb); }
.sig-stage-viewed { background: #1d9e75; }

.sig-completion {
    margin-left: auto;
    color: var(--text-secondary, #374151);
    font-weight: 500;
}

/* #126 P3 slice 2: weekly time-to-sign trend (vertical bars over time) */
.sig-trend {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    margin-top: 10px;
}

.sig-trend-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.sig-trend-track {
    width: 100%;
    height: 72px;
    display: flex;
    align-items: flex-end;
    background: var(--bg-tertiary, #f3f4f6);
    border-radius: 6px;
    overflow: hidden;
}

.sig-trend-bar {
    width: 100%;
    min-height: 3px;
    background: var(--color-primary, #2563eb);
    border-radius: 6px 6px 0 0;
    transition: height 0.2s ease;
}

.sig-trend-label {
    font-size: 11px;
    color: var(--text-tertiary, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
