/* ============================================================
   dashboard.css
   Shared styles for all reporting pages
   ============================================================ */

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ────────────────────────────────────────────────── */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #333;
    min-height: 100vh;
}

/* ── SPA Shell ───────────────────────────────────────────── */
.dashboard-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    grid-template-rows: 60px 1fr;
    grid-template-areas:
        "header  header"
        "sidebar content";
    min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────── */
.dashboard-header {
    grid-area: header;
    background: #2c3e50;
    color: white;
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
}

.dashboard-header .brand {
    font-size: 1.1em;
    font-weight: 700;
    margin-right: auto;
    text-decoration: none;
    color: white;
}

.dashboard-header input[type="date"] {
    padding: 4px 8px;
    border: 1px solid #4a6278;
    border-radius: 4px;
    background: #34495e;
    color: white;
    font-size: 0.85em;
    cursor: pointer;
}

.dashboard-header input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

.header-user {
    font-size: 0.85em;
    color: #bdc3c7;
    white-space: nowrap;
}

.header-role-badge {
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.header-role-badge.super_admin { background: #f39c12; color: #fff; }
.header-role-badge.analyst     { background: #2980b9; color: #fff; }
.header-role-badge.viewer      { background: #7f8c8d; color: #fff; }

.btn-logout {
    padding: 5px 14px;
    background: transparent;
    border: 1px solid #e74c3c;
    color: #e74c3c;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.btn-logout:hover { background: #e74c3c; color: white; }

/* ── Sidebar ─────────────────────────────────────────────── */
.dashboard-sidebar {
    grid-area: sidebar;
    background: white;
    border-right: 1px solid #dde1e7;
    padding: 20px 0;
    overflow-y: auto;
}

.sidebar-section-label {
    padding: 8px 20px 4px;
    font-size: 0.7em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #aab0b8;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: #444;
    text-decoration: none;
    font-size: 0.92em;
    border-left: 3px solid transparent;
    transition: background 0.15s;
    cursor: pointer;
}

.sidebar-link:hover  { background: #eaf2f8; color: #2E86C1; }
.sidebar-link.active {
    background: #eaf2f8;
    color: #2E86C1;
    border-left-color: #2E86C1;
    font-weight: 600;
}

.sidebar-divider {
    height: 1px;
    background: #eee;
    margin: 10px 16px;
}

/* ── Main content ────────────────────────────────────────── */
.dashboard-content {
    grid-area: content;
    padding: 24px;
    overflow-y: auto;
}

/* ── Page title ──────────────────────────────────────────── */
.page-title {
    font-size: 1.3em;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 4px;
}

.page-subtitle {
    font-size: 0.88em;
    color: #7f8c8d;
    margin-bottom: 24px;
}

/* ── Metric cards ────────────────────────────────────────── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.metric-label {
    font-size: 0.8em;
    color: #888;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 6px;
}

.metric-value {
    font-size: 1.9em;
    font-weight: 700;
    color: #2E86C1;
    line-height: 1;
}

/* ── Panels (chart/table containers) ────────────────────── */
.panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    padding: 24px;
    margin-bottom: 24px;
}

.panel-title {
    font-size: 1em;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid #eaf2f8;
}

/* ── Canvas charts ───────────────────────────────────────── */
.chart-wrap {
    position: relative;
    width: 100%;
}

.chart-wrap canvas {
    display: block;
    width: 100% !important;
}

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92em;
    min-width: 400px;
}

thead th {
    background: #f8f9fa;
    padding: 10px 12px;
    text-align: left;
    font-size: 0.8em;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid #dee2e6;
    white-space: nowrap;
}

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    color: #444;
}

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

.td-url {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-right { text-align: right; }

/* Slow page highlight */
.row-slow { border-left: 4px solid #e74c3c; }

/* Expandable detail row */
.detail-row td {
    background: #f8f9fa;
    font-family: monospace;
    font-size: 0.82em;
    white-space: pre-wrap;
    word-break: break-all;
    color: #555;
}

/* ── Role badges ─────────────────────────────────────────── */
.role-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 99px;
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.role-badge.super_admin { background: #fef3c7; color: #92400e; }
.role-badge.analyst     { background: #dbeafe; color: #1e40af; }
.role-badge.viewer      { background: #f3f4f6; color: #374151; }

/* Section tags (for analyst sections_allowed) */
.section-tag {
    display: inline-block;
    padding: 1px 7px;
    background: #ede9fe;
    color: #5b21b6;
    border-radius: 4px;
    font-size: 0.78em;
    font-weight: 600;
    margin-right: 3px;
}

.section-all {
    display: inline-block;
    padding: 1px 7px;
    background: #d1fae5;
    color: #065f46;
    border-radius: 4px;
    font-size: 0.78em;
    font-weight: 600;
}

/* Active/inactive dot */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}

.status-dot.active   { background: #22c55e; }
.status-dot.inactive { background: #9ca3af; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    padding: 7px 16px;
    border: none;
    border-radius: 4px;
    font-size: 0.88em;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.btn-primary   { background: #2E86C1; color: white; }
.btn-primary:hover   { background: #2471a3; }

.btn-secondary { background: #e8f0fe; color: #2E86C1; }
.btn-secondary:hover { background: #d1e8f7; }

.btn-danger    { background: #fdecea; color: #c0392b; }
.btn-danger:hover    { background: #f5c6cb; }

.btn-sm { padding: 4px 10px; font-size: 0.82em; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Analyst comments ────────────────────────────────────── */
.comments-area {
    width: 100%;
    min-height: 100px;
    padding: 10px 12px;
    border: 1px solid #dde1e7;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.92em;
    color: #333;
    resize: vertical;
    line-height: 1.5;
    transition: border-color 0.2s;
}

.comments-area:focus {
    outline: none;
    border-color: #2E86C1;
    box-shadow: 0 0 0 3px rgba(46,134,193,0.12);
}

.comments-saved {
    font-size: 0.82em;
    color: #27ae60;
    margin-top: 6px;
    display: none;
}

/* ── Skeleton loading ────────────────────────────────────── */
.skeleton-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.skeleton-card {
    height: 88px;
    background: linear-gradient(90deg, #e8eaed 25%, #f5f5f5 50%, #e8eaed 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 8px;
}

.skeleton-chart {
    height: 220px;
    background: linear-gradient(90deg, #e8eaed 25%, #f5f5f5 50%, #e8eaed 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 8px;
    margin-bottom: 24px;
}

.skeleton-table {
    height: 180px;
    background: linear-gradient(90deg, #e8eaed 25%, #f5f5f5 50%, #e8eaed 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 8px;
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Error / empty states ────────────────────────────────── */
.state-error {
    background: #fdecea;
    border-left: 4px solid #e74c3c;
    padding: 14px 16px;
    border-radius: 4px;
    color: #c0392b;
    font-size: 0.92em;
    margin-bottom: 20px;
}

.state-empty {
    text-align: center;
    padding: 40px 20px;
    color: #aaa;
    font-size: 0.92em;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
    background: white;
    border-radius: 10px;
    padding: 28px 32px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-title {
    font-size: 1.1em;
    font-weight: 700;
    margin-bottom: 20px;
    color: #2c3e50;
}

.modal-error {
    background: #fdecea;
    border: 1px solid #f5c6cb;
    color: #c0392b;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.88em;
    margin-bottom: 14px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
}

/* ── Form elements ───────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

.form-group label {
    display: block;
    font-size: 0.82em;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 0.92em;
    font-family: inherit;
    color: #333;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #2E86C1;
    box-shadow: 0 0 0 3px rgba(46,134,193,0.12);
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 4px 0;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.88em;
    color: #444;
}

/* ── Print container (hidden on screen, shown only during print) ── */
#print-container { display: none; }

/* Comments: textarea shown on screen, plain text shown in print */
.comments-print { display: none; }

/* ── Print / export styles ───────────────────────────────── */
@media print {
    .dashboard-header,
    .dashboard-sidebar,
    .btn-logout,
    .btn-primary,
    .btn-secondary,
    .comments-screen,
    .modal-backdrop,
    #app {
        display: none !important;
    }

    #print-container {
        display: block !important;
    }

    .print-section {
        padding: 20px 0;
    }

    .comments-screen { display: none !important; }
    .comments-print  { display: block !important; }

    body { background: white; }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "content";
    }

    .dashboard-sidebar { display: none; }
    .cards-grid { grid-template-columns: repeat(2, 1fr); }
    .td-url { max-width: 140px; }

    .dashboard-header .header-user { display: none; }
}
