/* Workspace Dashboard - Shared Styles + Master Dashboard */

/* ========================================================================
   CSS Variables & Shared Base
   ======================================================================== */

:root {
    --ws-bg: #f8fafc;
    --ws-card-bg: #ffffff;
    --ws-text: #1e293b;
    --ws-text-secondary: #64748b;
    --ws-border: #e2e8f0;
    --ws-accent: #2563eb;
    --ws-accent-light: #dbeafe;
    --ws-success: #16a34a;
    --ws-warning: #d97706;
    --ws-danger: #dc2626;
    --ws-green: #16a34a;
    --ws-red: #dc2626;
    --ws-blue: #2563eb;
    --ws-purple: #7c3aed;
    --ws-shadow: 0 1px 3px rgba(0,0,0,0.1);
    --ws-radius: 8px;
}

[data-theme="dark"] {
    --ws-bg: #0f172a;
    --ws-card-bg: #1e293b;
    --ws-text: #e2e8f0;
    --ws-text-secondary: #94a3b8;
    --ws-border: #334155;
    --ws-accent: #3b82f6;
    --ws-accent-light: rgba(59,130,246,0.15);
    --ws-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ========================================================================
   Shared Layout
   ======================================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--ws-bg);
    color: var(--ws-text);
    line-height: 1.5;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 16px 20px;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--ws-text);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ========================================================================
   Buttons
   ======================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
    font-family: inherit;
}

.btn-primary {
    background: var(--ws-accent);
    color: white;
}

.btn-primary:hover { background: #1d4ed8; }

.btn-secondary {
    background: var(--ws-card-bg);
    color: var(--ws-text);
    border: 1px solid var(--ws-border);
}

.btn-secondary:hover { background: var(--ws-accent-light); }

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 6px 8px;
}

/* ========================================================================
   Freshness Indicator
   ======================================================================== */

.freshness-indicator {
    font-size: 12px;
    color: var(--ws-text-secondary);
    padding: 4px 10px;
    background: var(--ws-card-bg);
    border: 1px solid var(--ws-border);
    border-radius: 4px;
}

.freshness-stale { color: var(--ws-warning); border-color: var(--ws-warning); }
.freshness-ok { color: var(--ws-success); }

/* ========================================================================
   KPI Cards
   ======================================================================== */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--ws-card-bg);
    border: 1px solid var(--ws-border);
    border-radius: var(--ws-radius);
    padding: 16px;
    box-shadow: var(--ws-shadow);
}

.kpi-card .kpi-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--ws-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.kpi-card .kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--ws-text);
    line-height: 1.2;
}

.kpi-card .kpi-sub {
    font-size: 12px;
    color: var(--ws-text-secondary);
    margin-top: 4px;
}

.kpi-accent { border-left: 3px solid var(--ws-accent); }
.kpi-green { border-left: 3px solid var(--ws-green); }
.kpi-red { border-left: 3px solid var(--ws-red); }
.kpi-purple { border-left: 3px solid var(--ws-purple); }
.kpi-warning { border-left: 3px solid var(--ws-warning); }

/* ========================================================================
   Tab Navigation
   ======================================================================== */

.tab-nav {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--ws-border);
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    padding: 10px 18px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ws-text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    font-family: inherit;
}

.tab-btn:hover { color: var(--ws-accent); }
.tab-btn.active {
    color: var(--ws-accent);
    border-bottom-color: var(--ws-accent);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========================================================================
   Charts
   ======================================================================== */

.chart-container {
    background: var(--ws-card-bg);
    border: 1px solid var(--ws-border);
    border-radius: var(--ws-radius);
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: var(--ws-shadow);
}

.chart-container h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--ws-text);
    margin-bottom: 12px;
}

.chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.chart-canvas-wrap {
    position: relative;
    height: 300px;
}

.chart-canvas-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ========================================================================
   Tables
   ======================================================================== */

.table-container {
    background: var(--ws-card-bg);
    border: 1px solid var(--ws-border);
    border-radius: var(--ws-radius);
    overflow: hidden;
    box-shadow: var(--ws-shadow);
    margin-bottom: 20px;
}

.table-container h3 {
    font-size: 14px;
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ws-border);
    color: var(--ws-text);
}

table.ws-table {
    width: 100%;
    border-collapse: collapse;
}

table.ws-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ws-text-secondary);
    background: var(--ws-bg);
    border-bottom: 1px solid var(--ws-border);
}

table.ws-table td {
    padding: 10px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--ws-border);
    color: var(--ws-text);
}

table.ws-table tr:last-child td { border-bottom: none; }
table.ws-table tr:hover td { background: var(--ws-accent-light); }

table.ws-table .text-right { text-align: right; }
table.ws-table .text-center { text-align: center; }
table.ws-table .mono { font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 12px; }

/* ========================================================================
   Service Cards Grid (Master Dashboard)
   ======================================================================== */

.service-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.service-card {
    background: var(--ws-card-bg);
    border: 1px solid var(--ws-border);
    border-radius: var(--ws-radius);
    padding: 20px;
    text-decoration: none;
    color: var(--ws-text);
    transition: all 0.2s;
    box-shadow: var(--ws-shadow);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.service-card:hover {
    border-color: var(--ws-accent);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
    transform: translateY(-2px);
}

.service-card .sc-icon {
    font-size: 28px;
    line-height: 1;
}

.service-card .sc-title {
    font-size: 16px;
    font-weight: 600;
}

.service-card .sc-desc {
    font-size: 13px;
    color: var(--ws-text-secondary);
}

.service-card .sc-stat {
    font-size: 22px;
    font-weight: 700;
    color: var(--ws-accent);
}

/* ========================================================================
   Loading Spinner
   ======================================================================== */

.loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--ws-text-secondary);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--ws-border);
    border-top-color: var(--ws-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================================================
   Status Badges
   ======================================================================== */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-green { background: #dcfce7; color: #15803d; }
.badge-red { background: #fef2f2; color: #b91c1c; }
.badge-yellow { background: #fefce8; color: #a16207; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: #f1f5f9; color: #475569; }

[data-theme="dark"] .badge-green { background: rgba(22,163,74,0.2); color: #4ade80; }
[data-theme="dark"] .badge-red { background: rgba(220,38,38,0.2); color: #f87171; }
[data-theme="dark"] .badge-yellow { background: rgba(217,119,6,0.2); color: #fbbf24; }
[data-theme="dark"] .badge-blue { background: rgba(37,99,235,0.2); color: #60a5fa; }
[data-theme="dark"] .badge-gray { background: rgba(100,116,139,0.2); color: #94a3b8; }

/* ========================================================================
   Search & Filters
   ======================================================================== */

.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-bar input,
.search-bar select {
    padding: 8px 12px;
    border: 1px solid var(--ws-border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    background: var(--ws-card-bg);
    color: var(--ws-text);
}

.search-bar input { min-width: 250px; flex: 1; }
.search-bar input:focus,
.search-bar select:focus {
    outline: none;
    border-color: var(--ws-accent);
    box-shadow: 0 0 0 2px var(--ws-accent-light);
}

/* ========================================================================
   Refresh Overlay
   ======================================================================== */

.refresh-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.refresh-overlay.active { display: flex; }

.refresh-modal {
    background: var(--ws-card-bg);
    border-radius: 12px;
    padding: 32px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.refresh-modal h3 { margin-bottom: 16px; }

.progress-bar {
    height: 8px;
    background: var(--ws-border);
    border-radius: 4px;
    overflow: hidden;
    margin: 16px 0;
}

.progress-bar-fill {
    height: 100%;
    background: var(--ws-accent);
    border-radius: 4px;
    transition: width 0.3s;
    width: 0%;
}

.refresh-status {
    font-size: 13px;
    color: var(--ws-text-secondary);
    margin-top: 8px;
}

/* ========================================================================
   User Photo
   ======================================================================== */

.user-photo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    vertical-align: middle;
    margin-right: 8px;
}

.user-photo-placeholder {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ws-accent-light);
    color: var(--ws-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    vertical-align: middle;
    margin-right: 8px;
}

/* ========================================================================
   Responsive
   ======================================================================== */

@media (max-width: 768px) {
    .container { padding: 12px; }
    .header h1 { font-size: 18px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .chart-row { grid-template-columns: 1fr; }
    .service-grid { grid-template-columns: repeat(2, 1fr); grid-auto-rows: auto; }
    .service-card { overflow: visible; min-height: auto; height: auto; }
    .tab-btn { padding: 8px 12px; font-size: 12px; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .service-grid { grid-template-columns: 1fr; }
}

/* ========================================================================
   DataTables Overrides
   ======================================================================== */

.dataTables_wrapper .dataTables_filter input {
    background: var(--ws-card-bg);
    color: var(--ws-text);
    border: 1px solid var(--ws-border);
    border-radius: 4px;
    padding: 4px 8px;
}

.dataTables_wrapper .dataTables_length select {
    background: var(--ws-card-bg);
    color: var(--ws-text);
    border: 1px solid var(--ws-border);
    border-radius: 4px;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-theme="dark"] .dataTables_wrapper .dataTables_length label,
[data-theme="dark"] .dataTables_wrapper .dataTables_filter label {
    color: var(--ws-text-secondary) !important;
}

[data-theme="dark"] table.dataTable tbody tr {
    background: var(--ws-card-bg) !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover {
    background: var(--ws-accent-light) !important;
}

[data-theme="dark"] table.dataTable thead th {
    background: var(--ws-bg) !important;
    color: var(--ws-text-secondary) !important;
    border-bottom-color: var(--ws-border) !important;
}

[data-theme="dark"] table.dataTable tbody td {
    color: var(--ws-text) !important;
    border-bottom-color: var(--ws-border) !important;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
    color: var(--ws-text-secondary) !important;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--ws-accent) !important;
    color: white !important;
    border-color: var(--ws-accent) !important;
}

/* ========================================================================
   Utility
   ======================================================================== */

.text-muted { color: var(--ws-text-secondary); }
.text-success { color: var(--ws-success); }
.text-danger { color: var(--ws-danger); }
.text-warning { color: var(--ws-warning); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex-center { display: flex; align-items: center; gap: 8px; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--ws-text-secondary);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; }

/* ========================================================================
   Health Score Gauge (Dashboard)
   ======================================================================== */

.health-score-section {
    margin-bottom: 24px;
}

.health-score-section h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--ws-text);
    margin-bottom: 16px;
}

.health-score-row {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.health-gauge-wrap {
    position: relative;
    width: 160px;
    height: 160px;
    flex-shrink: 0;
}

.health-gauge-wrap svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.health-gauge-bg {
    fill: none;
    stroke: var(--ws-border);
    stroke-width: 10;
}

.health-gauge-fill {
    fill: none;
    stroke-width: 10;
    stroke-linecap: round;
    transition: stroke-dasharray 0.8s ease;
}

.health-gauge-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.health-gauge-score {
    font-size: 36px;
    font-weight: 800;
    line-height: 1;
}

.health-gauge-grade {
    font-size: 13px;
    font-weight: 600;
    margin-top: 2px;
}

.health-gauge-green .health-gauge-fill { stroke: var(--ws-green); }
.health-gauge-green .health-gauge-score { color: var(--ws-green); }
.health-gauge-green .health-gauge-grade { color: var(--ws-green); }

.health-gauge-blue .health-gauge-fill { stroke: var(--ws-accent); }
.health-gauge-blue .health-gauge-score { color: var(--ws-accent); }
.health-gauge-blue .health-gauge-grade { color: var(--ws-accent); }

.health-gauge-warning .health-gauge-fill { stroke: var(--ws-warning); }
.health-gauge-warning .health-gauge-score { color: var(--ws-warning); }
.health-gauge-warning .health-gauge-grade { color: var(--ws-warning); }

.health-gauge-red .health-gauge-fill { stroke: var(--ws-red); }
.health-gauge-red .health-gauge-score { color: var(--ws-red); }
.health-gauge-red .health-gauge-grade { color: var(--ws-red); }

.health-sub-scores {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    flex: 1;
}

.health-sub-card {
    background: var(--ws-card-bg);
    border: 1px solid var(--ws-border);
    border-radius: var(--ws-radius);
    padding: 14px;
    box-shadow: var(--ws-shadow);
}

.health-sub-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ws-text-secondary);
    margin-bottom: 6px;
}

.health-sub-score {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.health-sub-bar {
    height: 4px;
    background: var(--ws-border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.health-sub-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s ease;
}

.health-sub-weight {
    font-size: 10px;
    color: var(--ws-text-secondary);
    margin-top: 4px;
}

/* ========================================================================
   Activity Heatmap (Dashboard)
   ======================================================================== */

.heatmap-section {
    margin-bottom: 24px;
}

.heatmap-section h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--ws-text);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.heatmap-grid {
    display: grid;
    grid-template-columns: 50px repeat(24, 1fr);
    gap: 2px;
    margin-bottom: 12px;
}

.heatmap-hour-label {
    font-size: 10px;
    color: var(--ws-text-secondary);
    text-align: center;
    padding: 2px 0;
}

.heatmap-day-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--ws-text-secondary);
    display: flex;
    align-items: center;
    padding-right: 8px;
}

.heatmap-cell {
    aspect-ratio: 1;
    min-height: 16px;
    border-radius: 3px;
    cursor: default;
    transition: transform 0.1s;
}

.heatmap-cell:hover {
    transform: scale(1.3);
    z-index: 1;
    position: relative;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--ws-text-secondary);
}

.heatmap-legend-gradient {
    width: 100px;
    height: 10px;
    border-radius: 3px;
    background: linear-gradient(to right, rgba(37,99,235,0.05), rgba(37,99,235,0.9));
}

.heatmap-stats {
    display: flex;
    gap: 20px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--ws-text-secondary);
}

.heatmap-stats strong {
    color: var(--ws-text);
}

/* Dark mode heatmap */
[data-theme="dark"] .heatmap-legend-gradient {
    background: linear-gradient(to right, rgba(59,130,246,0.08), rgba(59,130,246,0.9));
}
