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

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: rgba(255, 255, 255, 0.05);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --border-color: rgba(255, 255, 255, 0.1);
    --border-hover: rgba(255, 255, 255, 0.2);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --blue: #3b82f6;
    --blue-light: #60a5fa;
    --blue-glow: rgba(59, 130, 246, 0.3);
    --green: #10b981;
    --green-light: #34d399;
    --amber: #f59e0b;
    --amber-light: #fbbf24;
    --red: #ef4444;
    --red-light: #f87171;
    --purple: #8b5cf6;
    --purple-light: #a78bfa;
    --teal: #14b8a6;
    --teal-light: #2dd4bf;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 50px rgba(0, 0, 0, 0.4);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Background gradient */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(20, 184, 166, 0.04) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 56px;
    height: 56px;
    border: 4px solid rgba(59, 130, 246, 0.2);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 24px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.loading-sub {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ===== Header ===== */
.dashboard-header {
    position: relative;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 40px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 16px;
}

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

.header-icon {
    width: 48px;
    height: 48px;
    background: rgba(59, 130, 246, 0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-title {
    font-size: 22px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--blue-light), var(--purple-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.header-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.header-owner-badge {
    display: inline-block;
    margin-top: 8px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--red-light);
    border: 1px solid var(--red);
    border-radius: 6px;
}

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

.header-meta {
    display: flex;
    gap: 24px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.meta-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.meta-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.week-selector {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    margin-top: 2px;
}

.week-selector option {
    background-color: #1e293b;
    color: #f8fafc;
}

/* ===== Multi-select period dropdowns (Tuần/Tháng x Tạo đơn/E-form) ===== */
.ms-dropdown {
    position: relative;
    margin-top: 2px;
}

.ms-trigger {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    white-space: nowrap;
}

.ms-trigger:hover {
    border-color: var(--blue);
}

.ms-dropdown.open .ms-trigger {
    border-color: var(--blue);
    color: var(--blue-light);
}

.ms-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 160px;
    max-height: 320px;
    overflow-y: auto;
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    padding: 6px;
    z-index: 50;
}

.ms-dropdown.open .ms-panel {
    display: block;
}

.ms-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.ms-option:hover {
    background: rgba(255, 255, 255, 0.06);
}

.ms-option input[type="checkbox"] {
    accent-color: var(--blue);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.ms-empty {
    padding: 6px 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===== Refresh Button ===== */
.refresh-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 10px;
    color: var(--blue-light);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.refresh-btn:hover {
    background: rgba(59, 130, 246, 0.25);
    border-color: var(--blue);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
    transform: translateY(-1px);
}

.refresh-btn:active {
    transform: scale(0.96);
}

.refresh-btn.spinning svg {
    animation: spin 0.8s linear infinite;
}

/* ===== Main ===== */
.dashboard-main {
    position: relative;
    z-index: 1;
    max-width: 1600px;
    margin: 0 auto;
    padding: 32px 40px 60px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

/* ===== Section ===== */
.section {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 28px 32px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.section:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-lg);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-icon {
    font-size: 22px;
}

/* ===== Toggle Group ===== */
.toggle-group {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1px solid var(--border-color);
}

.toggle-btn {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.toggle-btn:hover {
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 2px 10px var(--blue-glow);
}

/* ===== KPI Cards ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.kpi-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius) var(--radius) 0 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.kpi-card:nth-child(1)::before { background: linear-gradient(90deg, var(--blue), var(--blue-light)); }
.kpi-card:nth-child(2)::before { background: linear-gradient(90deg, var(--purple), var(--purple-light)); }
.kpi-card:nth-child(3)::before { background: linear-gradient(90deg, var(--teal), var(--teal-light)); }
.kpi-card:nth-child(4)::before { background: linear-gradient(90deg, var(--amber), var(--amber-light)); }

.kpi-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.kpi-card:hover::before {
    opacity: 1;
}

.mc-card.active {
    border-color: var(--blue);
    background: var(--bg-card-hover);
    box-shadow: 0 0 0 1px var(--blue), 0 8px 30px rgba(0, 0, 0, 0.3);
}

.mc-card.active::before {
    opacity: 1;
}

/* ===== Miễn Cước — Top Vùng ranking ===== */
.mc-rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
    color: #1e1b12;
}
.mc-rank-badge.rank-1 { background: linear-gradient(135deg, #ffd700, #fbbf24); box-shadow: 0 0 12px rgba(251, 191, 36, 0.5); }
.mc-rank-badge.rank-2 { background: linear-gradient(135deg, #e5e7eb, #cbd5e1); }
.mc-rank-badge.rank-3 { background: linear-gradient(135deg, #d97706, #b45309); color: #fff; }
.mc-rank-badge.rank-other { background: rgba(255, 255, 255, 0.08); color: var(--text-secondary); font-weight: 600; }

.mc-bar-cell {
    position: relative;
    text-align: right;
}
.mc-bar-track {
    position: absolute;
    inset: 3px 6px;
    border-radius: 6px;
    overflow: hidden;
    z-index: 0;
    background: rgba(255, 255, 255, 0.03);
}
.mc-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    border-radius: 6px;
    opacity: 0.28;
    transition: width 0.4s ease;
}
.mc-bar-cell span {
    position: relative;
    z-index: 1;
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon.blue { background: rgba(59, 130, 246, 0.15); color: var(--blue-light); }
.kpi-icon.purple { background: rgba(139, 92, 246, 0.15); color: var(--purple-light); }
.kpi-icon.teal { background: rgba(20, 184, 166, 0.15); color: var(--teal-light); }
.kpi-icon.amber { background: rgba(245, 158, 11, 0.15); color: var(--amber-light); }
.kpi-icon.red { background: rgba(239, 68, 68, 0.15); color: var(--red-light); }

.kpi-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.kpi-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.kpi-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.kpi-value-sm {
    font-size: 16px;
    font-weight: 700;
}

.kpi-change {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}

.kpi-change .increase {
    color: var(--red);
}

.kpi-change .decrease {
    color: var(--green);
}

.kpi-change .neutral {
    color: var(--text-secondary);
}

.arrow-up::before {
    content: '▲';
    margin-right: 2px;
    font-size: 10px;
}

.arrow-down::before {
    content: '▼';
    margin-right: 2px;
    font-size: 10px;
}

/* ===== Glass Card ===== */
.glass-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    transition: var(--transition);
    min-width: 0;
}

.glass-card:hover {
    border-color: var(--border-hover);
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

/* ===== Chart Container ===== */
.chart-container {
    position: relative;
    width: 100%;
    max-height: 420px;
    margin-bottom: 24px;
}

.chart-tall {
    max-height: 520px;
    min-height: 400px;
}

/* ===== Split Grid ===== */
.split-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
}

/* ===== Data Table ===== */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    max-width: 100%;
}

/* Fixed-viewport variants for long tables (Miễn Cước's Vùng/Tỉnh tables) —
   shows a set number of rows, the rest scrolls. Opt-in via an extra class
   on the .table-responsive wrapper, not a default for every table. */
.table-scroll-10,
.table-scroll-15 {
    overflow-y: auto;
}

.table-scroll-10 { max-height: 460px; }
.table-scroll-15 { max-height: 660px; }

.table-scroll-10 .data-table thead th,
.table-scroll-15 .data-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-secondary);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    background: rgba(255, 255, 255, 0.06);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.2s ease;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

.data-table tbody td {
    padding: 11px 16px;
    color: var(--text-primary);
    white-space: nowrap;
}

/* Tighter horizontal spacing for the wide claim-type × period tables
   (up to 9 month columns + Total) — less padding eaten up per column
   means less horizontal scroll needed to see the label column. */
.table-compact thead th,
.table-compact tbody td {
    padding-left: 8px;
    padding-right: 8px;
}

.data-table .text-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.data-table .text-center {
    text-align: center;
}

.data-table .val-increase {
    color: var(--red);
    font-weight: 600;
}

.data-table .val-decrease {
    color: var(--green);
    font-weight: 600;
}

.data-table .val-neutral {
    color: var(--text-secondary);
}

/* ===== Alert Badge ===== */
.alert-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    animation: pulse-badge 2s infinite;
}

.alert-badge.danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red-light);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-badge.safe {
    background: rgba(16, 185, 129, 0.1);
    color: var(--green-light);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.alert-badge.warning {
    background: rgba(245, 158, 11, 0.12);
    color: var(--amber-light);
    border: 1px solid rgba(245, 158, 11, 0.25);
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.alert-badge.safe {
    animation: none;
}

/* ===== Highlight Row ===== */
.row-highlight {
    background: rgba(239, 68, 68, 0.06) !important;
}

.overdue-clickable-row {
    cursor: pointer;
}

.overdue-clickable-row.active-row {
    background: rgba(59, 130, 246, 0.12) !important;
}

.overdue-expand-caret {
    display: inline-block;
    width: 14px;
    margin-right: 6px;
    color: #64748b;
    font-size: 10px;
}

.overdue-subrow {
    background: rgba(255, 255, 255, 0.02);
}

.overdue-subrow td:first-child {
    padding-left: 36px;
    color: #94a3b8;
    font-size: 13px;
}

/* ===== Footer ===== */
.dashboard-footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 24px 40px;
    font-size: 13px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

/* ===== Fade In Animation ===== */
.fade-in {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ===== Responsive ===== */
@media (max-width: 1400px) {
    .dashboard-main {
        padding: 24px 24px 48px;
    }
    .dashboard-header {
        padding: 20px 24px;
    }
}

@media (max-width: 1200px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .split-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .header-title {
        font-size: 18px;
    }
    .section {
        padding: 20px;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== No data message ===== */
.no-data {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Login Screen Styles */
.login-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.login-box {
    background-color: #1e293b;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    text-align: center;
    max-width: 400px;
    width: 90%;
    border: 1px solid #334155;
}
.login-icon {
    margin-bottom: 20px;
}
.login-title {
    color: #f1f5f9;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
}
.login-desc {
    color: #94a3b8;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 30px;
}
.login-error {
    color: #ef4444;
    font-size: 14px;
    margin-top: 16px;
    min-height: 20px;
}
