:root {
    --primary: #d32f2f;
    --primary-hover: #b71c1c;
    --bg-color: #f4f6f8;
    --card-bg: #ffffff;
    --text-main: #2d3748;
    --text-muted: #718096;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --positive: #38a169;
    --negative: #e53e3e;
    --neutral: #718096;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
}

/* Navbar */
.navbar {
    background-color: var(--card-bg);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.logo-container:hover {
    opacity: 0.8;
}

.logo {
    height: 40px;
    object-fit: contain;
}

h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

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

.btn-secondary {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: #f7fafc;
}

.btn-back {
    background-color: transparent;
    color: var(--primary);
    padding: 0.5rem 0;
    font-weight: 600;
}
.btn-back:hover {
    color: var(--primary-hover);
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.view-header {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
    position: relative;
    min-height: 40px;
}

.view-header h2 {
    font-size: 1.5rem;
    color: var(--text-main);
    flex: 1;
}

.view-header .search-bar {
    position: absolute;
    right: 0;
}

.view-header .btn-back {
    position: absolute;
    left: 0;
    z-index: 10;
}

.view-header.centered-title h2,
.view-header.centered-title .report-titles {
    text-align: center;
    width: 100%;
}

/* Dashboard Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.client-card {
    background-color: var(--card-bg);
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

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

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-stats {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.stat-value {
    font-weight: 600;
    font-size: 1rem;
}

.stat-diff {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 0.5rem;
}

.diff-pos { background-color: #e6fffa; color: var(--positive); }
.diff-neg { background-color: #fff5f5; color: var(--negative); }
.diff-neu { background-color: #edf2f7; color: var(--neutral); }

/* History List */
.history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.history-card {
    background-color: var(--card-bg);
    border-radius: 0.5rem;
    padding: 1rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid var(--primary);
}

.history-card:hover {
    background-color: #f7fafc;
}

.history-date {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.history-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Report Detail */
.report-titles {
    display: flex;
    flex-direction: column;
    text-align: center;
    width: 100%;
}
.report-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Monthly Summary */
.monthly-summary-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.monthly-box {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    text-align: center;
    min-width: 200px;
    box-shadow: 0 4px 6px rgba(211, 47, 47, 0.3);
}

.monthly-box h5 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.9;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.monthly-box p {
    font-size: 1.25rem;
    font-weight: 700;
}

/* Intelligence Section */
.intelligence-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.intel-card {
    background-color: var(--card-bg);
    border-radius: 0.5rem;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--neutral);
}

.intel-card h4 {
    font-size: 0.95rem;
    color: var(--text-main);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.intel-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.intel-card.warning { border-top-color: #f59e0b; }
.intel-card.danger { border-top-color: var(--negative); }
.intel-card.info { border-top-color: #3b82f6; }

.intel-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.intel-item:last-child { border-bottom: none; }
.intel-item strong { color: var(--text-main); }

/* Chart Expansion */
/* Chart Expansion */
.card-expanded {
    position: fixed !important;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90vw !important;
    height: 80vh !important;
    z-index: 1000;
    margin: 0 !important;
    background: white !important;
    box-shadow: 0 0 0 100vmax rgba(0,0,0,0.5), 0 10px 40px rgba(0,0,0,0.3) !important;
    display: flex;
    flex-direction: column;
    padding: 2rem !important;
    border-radius: 12px;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 180px; /* Small height by default */
}

.card-expanded .canvas-wrapper {
    flex: 1;
    height: 100%;
    max-height: calc(100% - 2rem) !important;
}

.card-expanded canvas {
    max-height: 100% !important;
}

/* Contracts UI */
.contract-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.contract-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.progress-container {
    background: #e2e8f0;
    border-radius: 10px;
    height: 20px;
    width: 100%;
    overflow: hidden;
    position: relative;
    margin: 0.5rem 0;
}

.progress-bar {
    background: var(--primary);
    height: 100%;
    transition: width 0.3s ease;
}

.progress-warn {
    background: #f59e0b; /* yellow */
}

.progress-danger {
    background: #ef4444; /* red */
}

.progress-text {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    line-height: 20px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.admin-contract-item {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.admin-contract-item input, .admin-contract-item select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    margin-top: 0.2rem;
}

/* Global Search & NIA */
.search-result-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}
.search-result-item:last-child {
    border-bottom: none;
}
.search-result-item:hover {
    background: #f1f5f9;
}
.nia-badge {
    display: inline-block;
    background-color: var(--primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.1rem 0.5rem;
    border-radius: 12px;
    margin-right: 0.5rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    letter-spacing: 0.5px;
}
.btn-assign-nia {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 0.5rem;
}
.btn-assign-nia:hover {
    background: #f1f5f9;
    color: var(--text);
}

.report-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    background-color: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.summary-card h4 {
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.summary-card p {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

/* Table */
.table-container {
    background-color: var(--card-bg);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background-color: #f8fafc;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

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

tr:hover td {
    background-color: #f7fafc;
}

/* Modals */
.hidden {
    display: none !important;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal {
    background-color: var(--card-bg);
    padding: 2rem;
    border-radius: 0.5rem;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal-lg {
    max-width: 600px;
}

.modal h3 {
    margin-bottom: 0.5rem;
}

.modal p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.modal input[type="password"],
.search-bar input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    margin-bottom: 1.5rem;
    font-family: inherit;
}

.search-bar {
    margin-bottom: 0;
}
.search-bar input {
    margin-bottom: 0;
    width: 250px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Admin Toggles */
.admin-clients-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
}

.admin-client-item {
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}
.admin-client-item:last-child {
    border-bottom: none;
}

.admin-client-item label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

/* Accordion Styles */
.accordion-header {
    background-color: var(--surface);
    border: 1px solid var(--border);
    padding: 1rem 1.25rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--primary);
    transition: background-color 0.2s, box-shadow 0.2s;
    user-select: none;
}
.accordion-header:hover {
    background-color: #f8fafc;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.accordion-icon {
    transition: transform 0.3s ease;
}
.accordion-header.active .accordion-icon {
    transform: rotate(180deg);
}
.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    border-left: 2px solid var(--primary);
    margin-left: 1rem;
    padding-left: 1rem;
    margin-bottom: 1rem;
}
.accordion-content.open {
    max-height: 5000px; /* Large enough to fit content */
}
.accordion-content.open-intelligence {
    max-height: 2000px;
    border-left: none;
    margin-left: 0;
    padding-left: 0;
    margin-top: 1rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 15px;
        padding: 1rem;
        align-items: stretch;
    }
    .global-search-container {
        margin-left: 0 !important;
        width: 100%;
        max-width: 100% !important;
    }
    .navbar-actions {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        width: 100%;
    }
    #last-sync-display {
        text-align: center !important;
        width: 100%;
        margin-right: 0 !important;
        margin-bottom: 5px;
    }
}
