/* ==========================================================================
   Rich Roofing Dashboard — Stylesheet
   ========================================================================== */

/* --- Custom Properties --------------------------------------------------- */
:root {
    --color-primary: #1a365d;
    --color-primary-light: #2b6cb0;
    --color-accent-blue: #3182ce;
    --color-accent-green: #38a169;
    --color-accent-orange: #dd6b20;
    --color-accent-purple: #805ad5;
    --color-bg: #f7fafc;
    --color-surface: #ffffff;
    --color-text: #2d3748;
    --color-text-muted: #718096;
    --color-border: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .1);
    --radius: 10px;
}

/* --- Reset & Base -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

/* --- Dashboard Container ------------------------------------------------- */
.dashboard {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* --- Header -------------------------------------------------------------- */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-content h1 {
    font-size: 1.75rem;
    color: var(--color-primary);
    font-weight: 700;
}

.subtitle {
    color: var(--color-text-muted);
    font-size: .9rem;
    margin-top: .25rem;
}

/* --- Refresh Button ------------------------------------------------------ */
.refresh-form { display: inline-block; }

.btn-refresh {
    background: var(--color-primary-light);
    color: #fff;
    border: none;
    padding: .65rem 1.4rem;
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, opacity .2s;
}

.btn-refresh:hover:not(:disabled) { background: var(--color-primary); }
.btn-refresh:disabled { opacity: .5; cursor: default; }

/* --- Alerts -------------------------------------------------------------- */
.alert {
    padding: .75rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.alert-success { background: #c6f6d5; color: #22543d; }
.alert-error   { background: #fed7d7; color: #742a2a; }

/* --- KPI Grid ------------------------------------------------------------ */
.kpi-grid {
    display: grid;
    /* min(…,100%) so a track never demands more than the container on narrow screens (prevents
       cards from overflowing to the right and looking misaligned vs. the other widgets). */
    grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid transparent;
    min-width: 0; /* allow the grid item to shrink below its content's intrinsic width */
}

.kpi-pipeline { border-left-color: var(--color-accent-blue); }
.kpi-won      { border-left-color: var(--color-accent-green); }
.kpi-receivables { border-left-color: var(--color-accent-orange); }
.kpi-quotes   { border-left-color: var(--color-accent-purple); }

.kpi-icon { font-size: 2rem; flex-shrink: 0; }

.kpi-content { display: flex; flex-direction: column; gap: .15rem; }

.kpi-label {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-text-muted);
    font-weight: 600;
}

.kpi-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1.2;
}

.kpi-subtitle {
    font-size: .78rem;
    color: var(--color-text-muted);
}

/* --- Charts Grid --------------------------------------------------------- */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    min-width: 0; /* let the card shrink so the Chart.js canvas can't force it past the container */
}

.chart-card h2 {
    font-size: 1.05rem;
    color: var(--color-primary);
    margin-bottom: 1rem;
    font-weight: 600;
}

.chart-card canvas { max-height: 340px; max-width: 100%; }

/* --- Tables Grid --------------------------------------------------------- */
.tables-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(480px, 100%), 1fr));
    gap: 1.5rem;
}

.table-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.table-card h2 {
    font-size: 1.05rem;
    color: var(--color-primary);
    margin-bottom: 1rem;
    font-weight: 600;
}

/* --- Data Table ---------------------------------------------------------- */
.table-wrapper { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.data-table thead th {
    text-align: left;
    padding: .6rem .75rem;
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-size: .72rem;
    border-bottom: 2px solid var(--color-border);
}

.data-table tbody td {
    padding: .65rem .75rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.data-table tbody tr:hover { background: #ebf4ff; }

.amount-cell { font-weight: 600; color: var(--color-primary); white-space: nowrap; }

/* Right-aligned numeric column (e.g. Days in Stage) so values don't crowd the prior cell. */
.num-cell { text-align: right; white-space: nowrap; padding-right: 1.25rem; font-variant-numeric: tabular-nums; }
.data-table thead th.num-cell { text-align: right; }

/* --- Badges -------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 4px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.badge-warning { background: #fefcbf; color: #975a16; }
.badge-info    { background: #bee3f8; color: #2a4365; }
.badge-success { background: #c6f6d5; color: #22543d; }

/* --- Empty State --------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 768px) {
    .dashboard { padding: 1.25rem 1rem; }
    .dashboard-header { flex-direction: column; align-items: flex-start; }
    .kpi-grid,
    .charts-grid,
    .tables-grid { grid-template-columns: 1fr; }
    .kpi-value { font-size: 1.3rem; }
    /* Tighter card padding so content isn't crammed into a narrow column. */
    .kpi-card, .chart-card, .table-card { padding: 1.1rem; }
}
