/* ═══════════════════════════════════════════════════════════════════════
   common.css — Shared styles for phi architecture dashboards
   Used by: calendar, triage, feed, index (finance), health, marketing
   ═══════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables (Light Mode) ─────────────────────────────────────── */
:root {
    --primary-color: #333;
    --secondary-color: #666;
    --accent-color: #a67c52;
    --background-color: #f5f5f5;
    --card-color: #fff;
    --border-color: #e0e0e0;
    --green: #2e7d32;
    --red: #c62828;
    --blue: #1565c0;
    --purple: #7b1fa2;
    --orange: #e65100;
    --cyan: #00838f;
    --chart-grid: rgba(0,0,0,0.06);
    --chart-text: #666;
}

/* ── Dark Mode Variables ────────────────────────────────────────────── */
body.dark-mode {
    --primary-color: #e0e0e0;
    --secondary-color: #aaa;
    --accent-color: #d2b48c;
    --background-color: #1a1a1a;
    --card-color: #242424;
    --border-color: #333;
    --green: #3fb950;
    --red: #f85149;
    --blue: #58a6ff;
    --purple: #bc8cff;
    --orange: #d29922;
    --cyan: #39d2c0;
    --chart-grid: rgba(255,255,255,0.06);
    --chart-text: #8b949e;
}

/* ── Reset & Base ───────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Questrial', 'Futura', Arial, sans-serif; }
body {
    background-color: var(--background-color);
    color: var(--primary-color);
    line-height: 1.6;
    min-height: 100vh;
    padding-bottom: 60px;
}

/* ── Header & Nav ───────────────────────────────────────────────────── */
header {
    background-color: var(--card-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    padding: 20px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}
body.dark-mode header {
    background: #1e1e1e;
    box-shadow: 0 2px 5px rgba(0,0,0,0.4);
}
.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}
.logo {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
}
.phi-symbol {
    font-family: 'Arial', 'Helvetica', sans-serif;
}
nav ul {
    display: flex;
    list-style: none;
}
nav ul li {
    margin-left: 20px;
}
nav ul li a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 16px;
    transition: color 0.3s;
}
nav ul li a:hover,
nav ul li a.active {
    color: var(--accent-color);
    font-weight: bold;
    border-bottom: 3px solid var(--accent-color);
    padding-bottom: 2px;
}
.dark-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 2em;
    color: var(--secondary-color);
    margin-left: 20px;
    padding: 0;
    line-height: 1;
    transition: color 0.3s;
}
.dark-toggle-btn:hover {
    color: var(--accent-color);
}

/* ── Main Container ─────────────────────────────────────────────────── */
.main-container {
    max-width: 1200px;
    margin: 30px auto;
    padding: 0 20px;
}
.title-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 20px;
    flex-wrap: nowrap;
}
h1 {
    font-size: 28px;
    white-space: nowrap;
    flex-shrink: 0;
}
.page-subtitle {
    color: var(--secondary-color);
    font-size: 0.82em;
    text-align: right;
    margin-left: 20px;
    flex-shrink: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Fallback for pages that don't use .title-row yet */
h1 + .page-subtitle {
    margin-bottom: 28px;
}

/* ── Page Header Row ────────────────────────────────────────────────── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.page-header .meta {
    color: var(--secondary-color);
    font-size: 0.82em;
    display: flex;
    align-items: center;
    gap: 12px;
}
.refresh-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--accent-color);
    padding: 4px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78em;
    font-family: inherit;
    transition: all 0.15s;
}
.refresh-btn:hover {
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: #fff;
}
.refresh-spin {
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

/* ── KPI Cards ──────────────────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.kpi-grid-6 {
    grid-template-columns: repeat(6, 1fr);
}
.kpi-card {
    background: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}
.kpi-card .label {
    font-size: 0.72em;
    color: var(--secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.kpi-card .value {
    font-size: 26px;
    font-weight: 700;
}
.kpi-card .delta {
    font-size: 0.78em;
    margin-top: 4px;
}
.kpi-card .delta.pos { color: var(--green); }
.kpi-card .delta.neg { color: var(--red); }

/* ── Chart Cards ────────────────────────────────────────────────────── */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.chart-card {
    background: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}
.chart-card.full {
    grid-column: 1 / -1;
}
.chart-card h3 {
    font-size: 0.82em;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--secondary-color);
    display: inline;
}
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.chart-wrap {
    position: relative;
    width: 100%;
    height: 300px;
}
.chart-wrap.tall {
    height: 380px;
}

/* ── Time Filter Buttons ────────────────────────────────────────────── */
.time-filters {
    display: flex;
    gap: 4px;
}
.time-filter-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--secondary-color);
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.7em;
    font-family: inherit;
    transition: all 0.15s;
}
.time-filter-btn.active,
.time-filter-btn:hover {
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: #fff;
}

/* ── Tables ─────────────────────────────────────────────────────────── */
.tbl-card {
    background: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 20px;
    overflow-x: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}
.tbl-card h3 {
    font-size: 0.82em;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--secondary-color);
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}
th {
    text-align: left;
    padding: 6px 10px;
    border-bottom: 2px solid var(--border-color);
    color: var(--secondary-color);
    font-weight: 600;
    white-space: nowrap;
}
td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
tr:hover td {
    background: rgba(166,124,82,0.04);
}

/* ── Forms ───────────────────────────────────────────────────────────── */
.form-card {
    background: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}
.form-card h3 {
    font-size: 0.82em;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--secondary-color);
}

/* ── Status / Loading ───────────────────────────────────────────────── */
.loading {
    text-align: center;
    padding: 60px;
    color: var(--secondary-color);
}
.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-banner {
    background: rgba(198,40,40,0.08);
    border: 1px solid var(--red);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    color: var(--red);
    font-size: 0.88em;
}
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--secondary-color);
    font-size: 0.95em;
}

/* ── Toast Notifications ────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(46,125,50,0.92);
    color: #fff;
    padding: 12px 28px;
    border-radius: 8px;
    font-size: 0.88em;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.toast.visible { opacity: 1; }
.toast.error { background: rgba(180,30,30,0.92); }

/* ── Responsive: Header stacks on mobile ────────────────────────────── */
@media (max-width: 768px) {
    .header-container { flex-direction: column; }
    nav ul { margin-top: 15px; }
}

/* ── Responsive: Charts and KPIs ────────────────────────────────────── */
@media (max-width: 900px) {
    .chart-grid { grid-template-columns: 1fr; }
    .kpi-grid, .kpi-grid-6 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 500px) {
    .kpi-grid, .kpi-grid-6 { grid-template-columns: repeat(2, 1fr); }
}
