:root {
    --bg-color: #f4f7fb;
    --border-color: rgba(226, 232, 240, 0.8);
    --header-bg: rgba(255, 255, 255, 0.85);
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --primary-gradient-hover: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
    --text: #1e293b;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
    --card-bg: rgba(255, 255, 255, 0.95);
    --font-heading: 'Plus Jakarta Sans', sans-serif;
    --font-body: 'Inter', sans-serif;
    --glass-blur: blur(12px);
}

body {
    font-family: var(--font-body);
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at 15% 50%, rgba(79, 70, 229, 0.04), transparent 25%), radial-gradient(circle at 85% 30%, rgba(124, 58, 237, 0.04), transparent 25%);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: none; /* Hidden initially, shown after authentication */
    flex-direction: column;
    height: 100vh;
}

header {
    background: var(--header-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 1.6rem;
    color: var(--primary);
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header h1 {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
    color: var(--text);
}

.btn {
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-family: var(--font-heading);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    line-height: 1.25;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    border: none;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover {
    background: var(--primary-gradient-hover);
    box-shadow: 0 4px 6px rgba(79, 70, 229, 0.35);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.8);
    color: var(--text);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background-color: #ffffff;
    border-color: #cbd5e1;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px;
    margin-left: 4px;
    border-radius: 6px;
    transition: all 0.2s;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.btn-icon:hover {
    background: #e2e8f0;
    color: var(--primary);
}

.toolbar {
    background: var(--header-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 90;
}

.axis-config {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.axis-panel, .filters-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(248, 250, 252, 0.7);
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.filters-panel {
    flex-direction: column;
    gap: 0;
}

.config-group {
    display: flex;
    align-items: center;
}

.config-group label {
    margin-right: 8px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    width: auto;
    min-width: 65px;
    text-align: right;
}

.config-group select {
    padding: 6px 12px;
    min-width: 150px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: #fff;
    font-size: 13px;
    color: var(--text);
    transition: border-color 0.2s;
}

.config-group select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 8px;
}

.filters .config-group label {
    width: auto;
    min-width: 0;
}

/* Checkbox styling */
input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Data Grid Container */
.grid-container {
    flex-grow: 1;
    overflow: auto;
    background: transparent;
    padding: 24px;
}

#data-grid {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    width: max-content;
}

/* Base table */
table {
    border-collapse: collapse;
    width: max-content;
    font-size: 0.9rem;
}

th, td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
    min-width: 80px;
}

th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 10;
    text-align: center;
    font-family: var(--font-heading);
}

/* JSpreadsheet Custom Styling Overrides */
.jexcel_container {
    border: none;
    font-family: inherit;
}

.jexcel > thead > tr > td {
    background-color: #f8fafc !important;
    color: #334155 !important;
    font-weight: 700 !important;
    border: 1px solid var(--border-color) !important;
    padding: 8px 12px !important;
    white-space: normal !important;
    height: auto !important;
    vertical-align: middle !important;
    text-align: center !important;
    min-height: 40px;
    font-family: var(--font-heading);
    letter-spacing: 0.02em;
    font-size: 13px !important;
}

/* Force hide the row index column (1, 2, 3...) */
.jexcel_index, 
.jspreadsheet > .jexcel_content > table > thead > tr > td:first-child:not([data-x]),
.jspreadsheet > .jexcel_content > table > tbody > tr > td:first-child:not([data-x]) {
    display: none !important;
    width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
}

/* Ensure the first actual data column (headers) is visible and styled */
.jspreadsheet > .jexcel_content > table > thead > tr > td[data-x="0"],
.jspreadsheet > .jexcel_content > table > thead > tr > td:nth-child(2) {
    display: table-cell !important;
}

.jexcel > tbody > tr > td {
    border: 1px solid var(--border-color) !important;
    padding: 6px 10px !important;
    font-size: 14px;
}

.jexcel > tbody > tr > td.readonly {
    background-color: #f8fafc !important;
    color: #64748b !important;
}

.jexcel_content {
    box-shadow: none;
}

td:first-child, th:first-child {
    position: sticky;
    left: 0;
    background-color: #ffffff;
    z-index: 20;
    text-align: left;
    font-weight: 600;
    min-width: 300px;
    width: 320px;
    max-width: 450px;
    white-space: pre;
    overflow: hidden;
    text-overflow: ellipsis;
    border-right: 2px solid #cbd5e1 !important;
}

tbody tr:hover td, tbody tr:hover th {
    background-color: #f1f5f9 !important;
}

th:first-child {
    z-index: 30;
}

input.cell-input {
    width: 100%;
    border: none;
    text-align: right;
    background: transparent;
    font-size: 0.95rem;
    padding: 4px 0;
    font-family: inherit;
}

input.cell-input:focus {
    outline: none;
    background: #fff;
}

/* Global Form Utility Classes */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    font-family: var(--font-heading);
}

/* Global Form Input Style */
.form-input {
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background-color: #ffffff;
    color: var(--text);
    font-size: 14px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    box-shadow: var(--shadow-sm);
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-input::placeholder {
    color: #94a3b8;
}

/* Slim table for management */
.management-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.management-table th, .management-table td {
    padding: 14px 16px;
    text-align: left;
    border: none;
    border-bottom: 1px solid var(--border-color);
}

.management-table th {
    background-color: #f8fafc;
    font-weight: 700;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 13px;
}

.management-table tr:last-child td {
    border-bottom: none;
}

.management-table tr:hover td {
    background-color: #f1f5f9;
}

/* Badge styles for roles */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    font-family: var(--font-heading);
    letter-spacing: 0.05em;
}
.badge.SuperAdmin { background-color: #fef3c7; color: #92400e; border: 1px solid #fde68a;}
.badge.TenantAdmin { background-color: #dcfce7; color: #166534; border: 1px solid #bbf7d0;}
.badge.GeneralUser { background-color: #e0f2fe; color: #075985; border: 1px solid #bae6fd;}

/* Modal styles */
.modal { 
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%; 
    overflow: hidden; 
    background-color: rgba(15, 23, 42, 0.4); 
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: modalBgFadeIn 0.2s ease-out;
}

@keyframes modalBgFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content { 
    background-color: #ffffff; 
    margin: 3% auto; 
    border: 1px solid rgba(255,255,255,0.2); 
    width: 90%; 
    max-width: 1200px;
    height: 85%; 
    display: flex; 
    flex-direction: column; 
    border-radius: 16px; 
    box-shadow: var(--shadow-lg); 
    animation: modalContentFadeIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalContentFadeIn {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header { 
    padding: 20px 24px; 
    background-color: rgba(255, 255, 255, 0.9); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border-bottom: 1px solid var(--border-color);
    border-radius: 16px 16px 0 0;
}

.modal-footer {
    padding: 16px 24px;
    background-color: #f8fafc;
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 16px 16px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-header h2 { 
    margin: 0; 
    font-size: 1.25rem; 
    font-weight: 700; 
    color: var(--text); 
    font-family: var(--font-heading);
}

.close-btn { 
    color: #94a3b8; 
    font-size: 24px; 
    font-weight: 400; 
    cursor: pointer; 
    transition: color 0.2s; 
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-btn:hover { 
    color: var(--text); 
    background-color: #f1f5f9;
}

.modal-body { 
    display: flex; 
    flex-grow: 1; 
    overflow: hidden; 
    background-color: #ffffff; 
}

.dim-sidebar { 
    width: 260px; 
    border-right: 1px solid var(--border-color); 
    background: #f8fafc; 
    padding: 20px; 
}

.dim-sidebar ul { list-style-type: none; padding: 0; margin: 0; }

.dim-sidebar li { 
    padding: 12px 16px; 
    cursor: pointer; 
    border-radius: 8px;
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    color: var(--text-muted);
}

.dim-sidebar li:hover { 
    background: #e2e8f0; 
    color: var(--text); 
}

.dim-sidebar li.active { 
    background: var(--primary); 
    color: white; 
    font-weight: 600; 
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
}

.dim-main { 
    flex-grow: 1; 
    padding: 30px; 
    overflow-y: auto; 
    background: #ffffff; 
}

.btn-danger { 
    background: #ef4444; 
    color: white; 
    border: none;
}
.btn-danger:hover { 
    background: #dc2626; 
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.3);
}

#dim-edit-table { width: 100%; }
#dim-edit-table th, #dim-edit-table td { text-align: left; background: none; position: static; min-width: auto; }

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent; 
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1; 
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8; 
}

/* Auth / Card Layouts */
.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: var(--bg-color);
    padding: 20px;
    box-sizing: border-box;
}

.login-card {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    padding: 40px 48px;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 460px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-sizing: border-box;
}

.login-card h1 {
    margin-top: 0;
    margin-bottom: 30px;
    color: var(--text);
    font-size: 1.75rem;
    font-weight: 800;
    text-align: center;
    font-family: var(--font-heading);
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

#error-msg {
    color: #ef4444;
    margin-top: 15px;
    font-size: 13px;
    display: none;
    text-align: left;
    background-color: #fef2f2;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #fee2e2;
    font-weight: 500;
}

/* Information Guide Banner (for aggregated view mode) */
.info-banner {
    display: none; /* Controlled by JS */
    align-items: center;
    gap: 12px;
    background-color: #f0f7ff; /* Very soft slate blue */
    border: 1px solid #e0f2fe;
    border-radius: 12px;
    padding: 12px 18px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    animation: slideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.info-banner-icon {
    color: #0284c7; /* Sky blue information icon */
    font-size: 1.25rem;
    flex-shrink: 0;
}

.info-banner-text {
    color: #0369a1;
    font-size: 13.5px;
    line-height: 1.5;
}

.info-banner-text strong {
    font-weight: 700;
}

.info-banner-text span.dim-pill {
    background-color: #e0f2fe;
    color: #0369a1;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 600;
    border: 1px solid #bae6fd;
    font-size: 12px;
    margin: 0 2px;
    display: inline-block;
}

/* Spinner Animation */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s ease-in-out infinite;
    margin-right: 6px;
    flex-shrink: 0;
}

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


