/* ============================================
   NAS 2024 Listing Progress Dashboard — Theme
   Premium dark-green government dashboard
   ============================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- CSS Variables --- */
:root {
    --primary: #2d5a27;
    --primary-dark: #1a3a18;
    --primary-darker: #0f2a0d;
    --primary-light: #4a7c44;
    --primary-lighter: #6b9e64;
    --accent: #c41e3a;
    --accent-light: #e8394f;
    --bg: #f0f2f5;
    --bg-dark: #e4e7eb;
    --card: #ffffff;
    --card-hover: #f8faf8;
    --text: #1a1a2e;
    --text-secondary: #5a6270;
    --text-light: #8c939e;
    --text-on-primary: #ffffff;
    --success: #28a745;
    --success-light: #e8f5e9;
    --warning: #f59e0b;
    --warning-light: #fff8e1;
    --danger: #dc3545;
    --danger-light: #fce4ec;
    --info: #0ea5e9;
    --border: #e2e6ea;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --shadow-xl: 0 12px 40px rgba(0,0,0,0.15);
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 230px;
    --header-height: 80px;
}

/* --- Base --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--primary-light); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ==========================================
   HEADER
   ========================================== */
.dashboard-header {
    background: linear-gradient(135deg, var(--primary-darker) 0%, var(--primary-dark) 40%, var(--primary) 100%);
    color: var(--text-on-primary);
    padding: 0 32px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-logo {
    height: 56px;
    width: auto;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
    transition: var(--transition);
}
.header-logo:hover { transform: scale(1.05); }

.header-title-block {
    display: flex;
    flex-direction: column;
}

.header-org {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.8;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.header-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
    line-height: 1.2;
    text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.header-updated {
    font-size: 11px;
    opacity: 0.7;
    font-weight: 400;
}

.header-timestamp {
    font-size: 13px;
    font-weight: 600;
    background: rgba(255,255,255,0.15);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    backdrop-filter: blur(4px);
}

/* ── Mobile filter toggle button — hidden on desktop ── */
.filter-toggle-btn {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    backdrop-filter: blur(4px);
}

.filter-toggle-btn:hover {
    background: rgba(255,255,255,0.25);
}

.filter-toggle-btn .btn-icon {
    font-size: 16px;
    line-height: 1;
}

/* ==========================================
   MAIN LAYOUT
   ========================================== */
.main-container {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

/* ==========================================
   SIDEBAR
   ========================================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary-darker) 100%);
    color: var(--text-on-primary);
    padding: 20px 14px;
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    overflow-y: auto;
    z-index: 900;
    box-shadow: 4px 0 16px rgba(0,0,0,0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.filter-section {
    margin-bottom: 20px;
}

.filter-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,0.6);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-title::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 14px;
    background: var(--accent);
    border-radius: 2px;
}

/* Checklist styling */
.sidebar .dash-checklist label {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    margin: 1px 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-size: 11.5px;
    font-weight: 400;
    color: rgba(255,255,255,0.85);
    gap: 6px;
}

.sidebar .dash-checklist label:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
}

.sidebar .dash-checklist input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    cursor: pointer;
    flex-shrink: 0;
}

.select-all-label {
    font-weight: 600 !important;
    color: #fff !important;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 6px !important;
    margin-bottom: 4px !important;
}

.filter-scroll {
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}

/* ==========================================
   CONTENT AREA
   ========================================== */
.content-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 20px 24px 40px;
    min-width: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================
   KPI CARDS
   ========================================== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.kpi-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: var(--radius) var(--radius) 0 0;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
}

.kpi-card.accent::before { background: linear-gradient(90deg, var(--accent), var(--accent-light)); }
.kpi-card.warning::before { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.kpi-card.info::before { background: linear-gradient(90deg, var(--info), #38bdf8); }

.kpi-label {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--primary-dark);
    line-height: 1.1;
    font-family: 'JetBrains Mono', 'Inter', monospace;
}

.kpi-value.small { font-size: 20px; }

.kpi-sub {
    font-size: 10px;
    color: var(--text-light);
    margin-top: 4px;
    font-weight: 500;
}

.kpi-card.date-card {
    display: flex;
    flex-direction: column;
}

.date-values {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.date-val { text-align: center; }

.date-val .date {
    font-size: 15px;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

.date-val .date.avg { color: var(--warning); }
.date-val .date.recent { color: var(--success); }

.date-val .date-sub {
    font-size: 9px;
    color: var(--text-light);
    font-weight: 500;
}

/* ==========================================
   TABLES
   ========================================== */
.tables-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    margin-bottom: 18px;
}

.table-container {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--border);
}

.table-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--text-on-primary);
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.table-body {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
}

.summary-table thead th {
    background: var(--primary-dark);
    color: var(--text-on-primary);
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid var(--primary);
    white-space: nowrap;
}

.summary-table thead th:last-child { text-align: center; }

.summary-table tbody td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    font-weight: 400;
    vertical-align: middle;
}

.summary-table tbody tr { transition: var(--transition); }
.summary-table tbody tr:hover { background: var(--card-hover); }
.summary-table tbody tr:nth-child(even) { background: #f8faf8; }
.summary-table tbody tr:nth-child(even):hover { background: #eef4ee; }

.summary-table tbody tr.ea-completed-row td {
    background: #e8f5e9 !important;
    color: #155724 !important;
    font-weight: 700 !important;
}

.summary-table .province-group-header td {
    background: linear-gradient(135deg, #e8f0e6, #dce8da) !important;
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 11.5px;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--primary-light);
    padding: 8px 10px;
}

.summary-table .grand-total td {
    background: linear-gradient(135deg, var(--primary), var(--primary-light)) !important;
    color: var(--text-on-primary) !important;
    font-weight: 700;
    font-size: 12px;
    border-top: 2px solid var(--primary-dark);
}

.progress-cell {
    display: flex;
    align-items: center;
    gap: 6px;
}

.progress-bar-bg {
    flex: 1;
    height: 16px;
    background: #e9ecef;
    border-radius: 8px;
    overflow: hidden;
    min-width: 60px;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 8px;
    transition: width 0.8s ease;
    background: linear-gradient(90deg, var(--success), #34d058);
}

.progress-bar-fill.warning { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.progress-bar-fill.danger { background: linear-gradient(90deg, var(--danger), #f56565); }

.progress-text {
    font-weight: 700;
    font-size: 11px;
    min-width: 42px;
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
}

.progress-text.success { color: var(--success); }
.progress-text.warning { color: #d97706; }
.progress-text.danger { color: var(--danger); }

.num-cell {
    text-align: left;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 500;
}

.last7-table thead th {
    text-align: center;
    white-space: nowrap;
    font-size: 10px;
    padding: 8px 6px;
}
.last7-table thead th:first-child { text-align: left; }
.last7-table tbody td,
.last7-table tbody td.num-cell {
    text-align: center !important;
    padding: 6px 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}
.last7-table tbody td:first-child {
    text-align: left;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
}
.last7-table tbody td:last-child {
    font-weight: 700;
    background: rgba(45, 90, 39, 0.06);
}

/* ==========================================
   CHART CONTAINERS
   ========================================== */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    margin-bottom: 18px;
}

.chart-container {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    border: 1px solid var(--border);
    transition: var(--transition);
}

.chart-container:hover { box-shadow: var(--shadow-lg); }
.chart-container.full-width { grid-column: 1 / -1; }

.chart-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--border);
}

/* ==========================================
   LOADING / NO DATA
   ========================================== */
.no-data-msg {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
    font-size: 14px;
}
.no-data-msg h3 { color: var(--text-secondary); margin-bottom: 8px; }

/* ==========================================
   ANIMATIONS
   ========================================== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.kpi-card { animation: fadeInUp 0.5s ease forwards; }
.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }
.kpi-card:nth-child(5) { animation-delay: 0.25s; }
.kpi-card:nth-child(6) { animation-delay: 0.3s; }
.chart-container { animation: fadeInUp 0.6s ease forwards; }
.table-container { animation: fadeInUp 0.5s ease forwards; }

/* ==========================================
   RESPONSIVE — TABLET (max 1200px)
   ========================================== */
@media (max-width: 1200px) {
    .tables-row, .charts-row { grid-template-columns: 1fr; }
    :root { --sidebar-width: 200px; }
}

@media (max-width: 900px) {
    :root { --sidebar-width: 180px; --header-height: 65px; }
    .header-title { font-size: 16px; }
    .kpi-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
    .kpi-value { font-size: 22px; }
    .content-area { padding: 14px; }
}

/* ==========================================
   RESPONSIVE — MOBILE (max 768px)
   ========================================== */
@media (max-width: 768px) {
    :root {
        --header-height: 60px;
        --sidebar-width: 260px;
    }

    /* Header */
    .dashboard-header {
        padding: 0 12px;
        height: var(--header-height);
    }

    .header-logo { height: 34px; }
    .header-org { display: none; }
    .header-title { font-size: 12px; font-weight: 700; }
    .header-timestamp { font-size: 10px; padding: 3px 8px; }
    .header-updated { display: none; }

    /* Show filter toggle button on mobile */
    .filter-toggle-btn {
        display: flex;
    }

    /* Sidebar — slides in from left as a drawer */
    .main-container {
        flex-direction: row;
        margin-top: var(--header-height);
    }

    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        width: var(--sidebar-width);
        z-index: 1100;
        transform: translateX(-100%); /* hidden by default */
        overflow-y: auto;
        padding: 16px 14px;
    }

    /* When sidebar has 'open' class — slide in */
    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    /* Overlay behind open sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1050;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.overlay-visible {
        display: block;
    }

    /* Content — full width, no left margin */
    .content-area {
        margin-left: 0;
        padding: 12px;
        width: 100%;
    }

    /* KPI — 2 per row */
    .kpi-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 12px;
    }

    .kpi-card { padding: 12px; }
    .kpi-value { font-size: 20px; }
    .kpi-value.small { font-size: 16px; }
    .kpi-label { font-size: 9.5px; }

    .date-values { flex-direction: column; gap: 4px; }
    .date-val .date { font-size: 13px; }

    /* Tables stack + scroll */
    .tables-row { grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }
    .table-body { max-height: 280px; }
    .summary-table { min-width: 400px; }
    .last7-table { min-width: 600px; }
    .progress-bar-bg { min-width: 40px; }

    /* Charts stack */
    .charts-row { grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }
    .chart-container { padding: 12px; }
    .chart-title { font-size: 12px; }

    /* Filter scroll taller on mobile drawer */
    .filter-scroll { max-height: 200px; }
}

/* ==========================================
   RESPONSIVE — SMALL MOBILE (max 480px)
   ========================================== */
@media (max-width: 480px) {
    .header-title { font-size: 11px; }
    .header-logo { height: 28px; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 6px; }
    .kpi-card { padding: 10px; }
    .kpi-value { font-size: 18px; }
    .kpi-label { font-size: 9px; }
    .content-area { padding: 8px; }
    .filter-toggle-btn { font-size: 12px; padding: 6px 10px; }
}

/* ==========================================
   DASH COMPONENT OVERRIDES
   ========================================== */
._dash-loading { background: transparent !important; }
.dash-graph .js-plotly-plot { border-radius: var(--radius); }
.Select-control { border-color: var(--border) !important; border-radius: var(--radius-sm) !important; }
#_dash-app-content { background: var(--bg); }

/* ==========================================
FIX BLURRY FILTERS ON MOBILE
========================================== */
@media (max-width: 768px) {

  /* Disable backdrop blur that causes fuzzy text on phones */
  .header-timestamp,
  .filter-toggle-btn,
  .dashboard-header {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  /* Keep sidebar crisp */
  .sidebar {
    filter: none !important;
    background: linear-gradient(
      180deg,
      var(--primary-dark) 0%,
      var(--primary-darker) 100%
    );
  }

  /* Ensure filter labels stay sharp */
  .sidebar .dash-checklist label {
    background: transparent;
    color: #ffffff;
    text-shadow: none !important;
    filter: none !important;
  }

  /* Improve checkbox/text rendering on mobile browsers */
  .sidebar,
  .sidebar * {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transform: translateZ(0);
    backface-visibility: hidden;
  }
}
