/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
    /* Primary */
    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #dbeafe;
    --color-primary-ring: rgba(37, 99, 235, 0.1);

    /* Success */
    --color-success: #10b981;
    --color-success-light: #dcfce7;
    --color-success-dark: #166534;
    --color-success-border: #bbf7d0;

    /* Error / Danger */
    --color-error: #ef4444;
    --color-error-hover: #dc2626;
    --color-error-light: #fee2e2;
    --color-error-dark: #991b1b;
    --color-error-border: #fca5a5;

    /* Warning */
    --color-warning: #f59e0b;
    --color-warning-light: #fef3c7;
    --color-warning-dark: #92400e;

    /* Text */
    --color-text-dark: #111827;
    --color-text: #374151;
    --color-text-muted: #6b7280;
    --color-text-light: #9ca3af;

    /* Borders */
    --color-border: #e5e7eb;
    --color-border-dark: #d1d5db;
    --color-border-light: #f3f4f6;

    /* Backgrounds */
    --color-bg-page: #f5f5f7;
    --color-bg-card: #ffffff;
    --color-bg-hover: #f9fafb;
    --color-bg-section: #f3f4f6;

    /* Department */
    --color-dept-bg: #e0e7ff;
    --color-dept-text: #3730a3;

    /* Header */
    --color-header-start: #B8A89A;
    --color-header-end: #B8A89A;

    /* Sidebar */
    --color-sidebar-active-bg: #eff6ff;

    /* Status */
    --color-status-progress-bg: #dbeafe;
    --color-status-progress-text: #1d4ed8;
    --color-status-planned-bg: #fef3c7;
    --color-status-planned-text: #92400e;
    --color-status-completed-bg: #d1fae5;
    --color-status-completed-text: #065f46;

    /* Z-index layers */
    --z-table-header: 10;
    --z-panel: 1100;
    --z-modal: 1200;
    --z-notification: 1300;
    --z-toast: 9999;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1);
    --shadow-modal: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--color-bg-page);
    font-size: 13px;
}

/* ============================================
   Header
   ============================================ */
.header {
    background: linear-gradient(135deg, var(--color-header-start), var(--color-header-end));
    color: white;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.logo {
    width: 24px;
    height: 24px;
    background: var(--color-success);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 12px;
}

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

.search-box {
    background: rgba(255,255,255,0.2);
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    color: white;
    width: 200px;
}

.search-box::placeholder {
    color: rgba(255,255,255,0.7);
}

/* ============================================
   Navigation Bar
   ============================================ */
.nav-bar {
    background: white;
    border-bottom: 1px solid var(--color-border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-muted);
}

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

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--color-success);
    border-radius: 12px;
    cursor: pointer;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    top: 2px;
    right: 2px;
    transition: transform 0.2s;
}

/* ============================================
   Sidebar
   ============================================ */
.main-container {
    display: flex;
    height: calc(100vh - 100px);
}

.content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
}

.sidebar {
    width: 240px;
    background: white;
    border-right: 1px solid var(--color-border);
    padding: 16px 0;
    overflow: hidden;
    flex-shrink: 0;
    transition: width 0.25s ease, padding 0.25s ease, border 0.25s ease;
}

.main-container.sidebar-collapsed .sidebar {
    width: 0;
    padding: 0;
    border-right: none;
}

/* Sidebar nav toggle button */
.nav-sidebar-toggle {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 4px 8px;
    color: var(--color-text-muted);
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-sidebar-toggle:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
    border-color: var(--color-border-dark);
}

.sidebar-item {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-text);
    cursor: pointer;
    border-right: 3px solid transparent;
    text-decoration: none;
}

.sidebar-item:hover {
    background: var(--color-bg-hover);
}

.sidebar-item.active {
    background: var(--color-sidebar-active-bg);
    color: var(--color-primary);
    border-right-color: var(--color-primary);
}

/* Sidebar parent / submenu */
.sidebar-parent {
    display: flex;
    flex-direction: column;
}

.sidebar-toggle {
    cursor: pointer;
    user-select: none;
    justify-content: space-between;
}

.sidebar-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
    display: inline-block;
}

.sidebar-toggle.expanded .sidebar-arrow {
    transform: rotate(0deg);
}

.sidebar-toggle:not(.expanded) .sidebar-arrow {
    transform: rotate(-90deg);
}

.sidebar-submenu {
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    opacity: 1;
}

.sidebar-submenu.collapsed {
    max-height: 0;
    opacity: 0;
}

.sidebar-subitem {
    padding: 6px 16px 6px 36px;
    display: block;
    color: var(--color-text-muted);
    cursor: pointer;
    text-decoration: none;
    font-size: 12px;
    border-right: 3px solid transparent;
}

.sidebar-subitem:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.sidebar-subitem.active {
    background: var(--color-sidebar-active-bg);
    color: var(--color-primary);
    border-right-color: var(--color-primary);
}

.sidebar-submenu-loading,
.sidebar-submenu-empty {
    padding: 6px 16px 6px 36px;
    font-size: 11px;
    color: var(--color-text-light);
    font-style: italic;
}

/* ============================================
   Content Area
   ============================================ */
.content {
    flex: 1;
    padding: 24px;
    overflow: auto;
}

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

/* ============================================
   Buttons
   ============================================ */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}

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

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

.btn-secondary {
    background: var(--color-text-muted);
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-outline {
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text-dark);
}

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

.btn-add {
    padding: 8px 16px;
    background: var(--color-primary-hover);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
}

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

.btn-icon {
    padding: 6px 12px;
    background: white;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text);
}

.btn-icon:hover {
    background: var(--color-bg-section);
}

.btn-icon.delete {
    color: var(--color-error-hover);
    border-color: var(--color-error-border);
}

.btn-icon.delete:hover {
    background: var(--color-error-light);
}

.btn-xs {
    padding: 4px 8px;
    font-size: 11px;
    background: white;
    border: 1px solid var(--color-border-dark);
    border-radius: 3px;
    cursor: pointer;
    color: var(--color-text);
}

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

.btn-xs.delete {
    color: var(--color-error-hover);
    border-color: var(--color-error-border);
}

.btn-xs.delete:hover {
    background: var(--color-error-light);
}

/* ============================================
   Cards (Dashboard)
   ============================================ */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.card {
    background: var(--color-bg-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card h2 {
    margin-bottom: 12px;
}

.card p {
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.stat-card {
    text-align: center;
    padding: 20px;
    background: var(--color-bg-hover);
    border-radius: var(--radius-md);
}

.stat-value {
    font-size: 32px;
    font-weight: bold;
}

.stat-label {
    color: var(--color-text-muted);
    margin-top: 8px;
}

/* ============================================
   Filters
   ============================================ */
.filters {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 16px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-lg, 8px);
    padding: 12px 16px;
    background: var(--color-bg-secondary, #f9fafb);
    flex-wrap: wrap;
}
.filters-clear-btn {
    padding: 8px 14px;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-md);
    font-size: 12px;
    background: #fff;
    cursor: pointer;
    color: var(--color-text-secondary, #6b7280);
    white-space: nowrap;
    align-self: flex-end;
}
.filters-clear-btn:hover {
    border-color: var(--color-danger, #dc2626);
    color: var(--color-danger, #dc2626);
    background: #fef2f2;
}

.filter-input {
    padding: 8px 12px;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-md);
    font-size: 13px;
}

/* Multi-select filter dropdown */
.multi-filter {
    position: relative;
}
.multi-filter-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-md);
    font-size: 13px;
    background: #fff;
    cursor: pointer;
    min-width: 140px;
    white-space: nowrap;
}
.multi-filter-btn:hover {
    border-color: var(--color-primary, #2563eb);
}
.multi-filter-btn .arrow {
    margin-left: auto;
    font-size: 10px;
    color: var(--color-text-secondary, #6b7280);
}
.multi-filter-panel {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 100;
    background: #fff;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 220px;
    max-height: 320px;
    display: flex;
    flex-direction: column;
    margin-top: 2px;
}
.multi-filter-search {
    padding: 6px 8px;
    border: none;
    border-bottom: 1px solid var(--color-border);
    font-size: 12px;
    outline: none;
}
.multi-filter-actions {
    display: flex;
    gap: 8px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-border);
    font-size: 11px;
}
.multi-filter-actions a {
    color: var(--color-primary, #2563eb);
    cursor: pointer;
    text-decoration: none;
}
.multi-filter-actions a:hover {
    text-decoration: underline;
}
.multi-filter-list {
    overflow-y: auto;
    flex: 1;
    max-height: 240px;
}
.multi-filter-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
}
.multi-filter-item:hover {
    background: var(--color-bg-secondary, #f3f4f6);
}
.multi-filter-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0;
    cursor: pointer;
}

/* ============================================
   Tables
   ============================================ */
.table-container {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1800px;
}

th {
    background: var(--color-bg-hover);
    padding: 8px 12px;
    text-align: left;
    font-weight: 700;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
    font-size: 11px;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: var(--z-table-header);
}

/* ============================================
   Budget Grid - Frozen Headers & Resizable Cols
   ============================================ */
.budget-grid-wrapper {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 200px);
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.budget-grid-wrapper .table-container {
    flex: 1;
    overflow: auto;
    border-radius: var(--radius-lg);
    box-shadow: none;
}

.budget-grid-wrapper table {
    border-collapse: separate;
    border-spacing: 0;
}

.budget-grid-wrapper thead {
    position: sticky;
    top: 0;
    z-index: var(--z-table-header);
}

.budget-grid-wrapper th {
    position: relative;
    user-select: none;
    background: var(--color-bg-hover);
    box-shadow: 0 1px 0 var(--color-border);
}

/* Column Resize Handle */
.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    background: transparent;
    z-index: 1;
}

.col-resize-handle:hover,
.col-resize-handle.resizing {
    background: var(--color-primary);
}

/* Resizing state */
.budget-grid-wrapper.resizing {
    cursor: col-resize;
    user-select: none;
}

.budget-grid-wrapper.resizing * {
    cursor: col-resize !important;
}

/* Budget Grid Progress Bar */
.budget-progress-container {
    padding: 0 16px 12px;
}

.budget-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--color-border-light);
    border-radius: 3px;
    overflow: hidden;
}

.budget-progress-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 3px;
    transition: width 0.15s ease;
    width: 0%;
}

.budget-progress-text {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
    text-align: center;
}

/* Budget Grid Row Limit Warning */
.budget-row-warning {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text);
}

.budget-row-warning-icon {
    font-size: 36px;
    margin-bottom: 12px;
}

.budget-row-warning-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
}

.budget-row-warning-message {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
    max-width: 420px;
}

.budget-row-warning-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* ============================================
   Hierarchical Group Headers & Subtotals
   ============================================ */

/* Group header rows - colors are applied dynamically from org settings */
.group-header {
    cursor: pointer;
    user-select: none;
}

.group-header:hover {
    filter: brightness(0.97);
}

.group-header td {
    padding: 10px 12px;
    font-weight: 600;
}

.group-toggle {
    display: inline-block;
    width: 16px;
    font-size: 10px;
    color: inherit;
    opacity: 0.7;
    transition: transform 0.2s ease;
}

/* Data rows */
.data-row {
    background: white;
}

.data-row:hover {
    background: var(--color-bg-hover);
}

.account-name-cell {
    white-space: nowrap;
}

.account-code {
    color: var(--color-text-muted);
    font-size: 11px;
}

.labour-type-badge {
    display: inline-block;
    font-size: 14px;
    opacity: 0.4;
    padding: 2px 4px;
    line-height: 1;
    user-select: none;
    cursor: default;
}

/* Subtotal rows - colors applied dynamically from org settings */
.subtotal-row {
}

.subtotal-row td {
    background: transparent !important;
}

.subtotal-label {
    font-weight: 600;
}

.subtotal-value {
    font-weight: 600;
}

/* Grand total row */
.grand-total-row {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%) !important;
    position: sticky;
    z-index: 5;
}

.grand-total-row--top {
    top: 0;
}

.grand-total-row--bottom {
    bottom: 0;
}

.grand-total-row td {
    color: white !important;
    font-weight: 700;
    padding: 12px;
}

.grand-total-label {
    font-size: 14px;
}

.grand-total-value {
    background: transparent !important;
}

td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border-light);
    color: var(--color-text);
    font-size: 12px;
    position: relative;
}

tr:hover {
    background: var(--color-bg-hover);
}

/* Editable Cells */
.editable-cell {
    cursor: pointer;
    transition: background-color 0.2s;
}

.editable-cell:hover {
    background: #f0f9ff;
}

.editing {
    background: var(--color-warning-light) !important;
}

.cell-input {
    width: 100%;
    border: none;
    background: transparent;
    padding: 0;
    font-size: 12px;
    color: var(--color-text);
}

.cell-input:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

/* Out-year separator — left border on the first out-year column */
.col-out-year-start {
    border-left: 2px solid #94a3b8 !important;
}

/* Monthly Columns */
.monthly-column {
    min-width: 80px;
    text-align: right;
    background: #fafbfc;
}

.monthly-column input {
    text-align: right;
    width: 70px;
    border: none;
    background: transparent;
    padding: 4px;
    font-size: 12px;
    color: var(--color-text);
}

.monthly-column input:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    background: white;
}

/* Active cell (keyboard navigation) */
.cell-active {
    background: var(--color-primary-light) !important;
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.cell-active input {
    background: white !important;
    outline: none !important;
}

.monthly-toggle {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 11px;
}

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

.monthly-columns {
    transition: opacity 0.3s ease, max-width 0.3s ease;
}

.monthly-columns.collapsed {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
}

.monthly-total {
    font-weight: 600;
    color: #1f2937;
    background: #929ec7;
    text-align: right;
    min-width: 115px;
}

.grand-total {
    font-weight: 700;
    color: #1f2937;
    background: #929ec7;
    text-align: right;
}

.monthly-subtotal {
    font-weight: 700;
    color: #1f2937;
    background: var(--color-bg-section);
    text-align: right;
}

.info-column {
    font-weight: 700;
    color: #1f2937;
    background: var(--color-bg-section);
    text-align: right;
    min-width: 115px;
}

/* Save Indicator */
.save-indicator {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-success);
    opacity: 0;
    transition: opacity 0.3s;
}

.save-indicator.saving {
    background: var(--color-warning);
    opacity: 1;
}

.save-indicator.saved {
    background: var(--color-success);
    opacity: 1;
}

/* Totals Row */
.totals-row {
    background: var(--color-bg-hover);
    font-weight: 600;
}

/* Department Header */
.department-header {
    background: var(--color-dept-bg) !important;
    font-weight: 600;
    color: var(--color-dept-text);
}

/* Delete Button */
.delete-btn {
    color: var(--color-error);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
}

.delete-btn:hover {
    color: var(--color-error-hover);
}

/* Count Badges */
.project-count,
.account-count {
    background: var(--color-bg-section);
    color: var(--color-text-muted);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    margin-left: 8px;
}

/* ============================================
   Status Badges
   ============================================ */
.status-badge {
    padding: 4px 8px;
    border-radius: var(--radius-xl);
    font-size: 11px;
    font-weight: 500;
}

.status-progress {
    background: var(--color-status-progress-bg);
    color: var(--color-status-progress-text);
}

.status-planned {
    background: var(--color-status-planned-bg);
    color: var(--color-status-planned-text);
}

.status-completed {
    background: var(--color-status-completed-bg);
    color: var(--color-status-completed-text);
}

/* ============================================
   Links
   ============================================ */
.dept-link {
    color: var(--color-primary);
    text-decoration: none;
}

.dept-link:hover {
    text-decoration: underline;
}

.budget-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 12px;
}

/* ============================================
   Forms
   ============================================ */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--color-text-dark);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    box-sizing: border-box;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary-hover);
    box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.checkbox-group label {
    margin: 0;
    font-weight: 400;
    cursor: pointer;
}

/* ============================================
   Modals
   ============================================ */
.modal-backdrop,
.apputils-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: 20px;
}

.modal,
.apputils-modal {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-modal);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
}

.modal-header h2,
.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-muted);
}

.modal-close:hover {
    color: var(--color-text-dark);
}

.modal-body,
.apputils-modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    position: sticky;
    bottom: 0;
    background: white;
}

/* Legacy modal classes (backward compat) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
}

.modal-content {
    background: white;
    padding: 24px;
    border-radius: var(--radius-lg);
    width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 20px;
}

/* ============================================
   Tabs
   ============================================ */
.tabs {
    display: flex;
    gap: 8px;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    color: var(--color-text-muted);
}

.tab-btn.active {
    color: var(--color-primary-hover);
    border-bottom-color: var(--color-primary-hover);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================================
   Notifications & Toasts
   ============================================ */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: var(--z-notification);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: white;
    box-shadow: var(--shadow-md);
}

.notification.success {
    background: var(--color-success);
}

.notification.error {
    background: var(--color-error);
}

.notification.info {
    background: var(--color-primary);
}

/* Toast container */
#apputils-toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 320px;
}

.apputils-toast {
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    padding: 12px 14px;
    font-size: 13px;
    color: #0f172a;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.apputils-toast-success {
    border-left: 4px solid var(--color-success);
}

.apputils-toast-error {
    border-left: 4px solid var(--color-error);
}

.apputils-toast-info {
    border-left: 4px solid var(--color-primary-hover);
}

.apputils-toast .toast-close {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    color: #64748b;
}

/* ============================================
   Progress Overlay
   ============================================ */
.progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: 20px;
}

.progress-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    padding: 32px 40px;
    min-width: 400px;
    max-width: 500px;
    text-align: center;
}

.progress-card h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text-dark);
}

.progress-card .progress-status {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

.progress-bar-track {
    width: 100%;
    height: 8px;
    background: var(--color-bg-section);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px;
    width: 0%;
    transition: width 0.2s ease;
}

.progress-card .progress-percent {
    font-size: 13px;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

/* ============================================
   Messages (inline feedback)
   ============================================ */
.message {
    padding: 12px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 13px;
}

.message.success {
    background: var(--color-success-light);
    color: var(--color-success-dark);
    border: 1px solid var(--color-success-border);
}

.message.error {
    background: var(--color-error-light);
    color: var(--color-error-dark);
    border: 1px solid var(--color-error-border);
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    text-align: center;
    padding: 32px 20px;
    color: var(--color-text-muted);
}

.empty-state p {
    margin: 0 0 16px 0;
    font-size: 14px;
}

/* ============================================
   Collapsible Sections
   ============================================ */
.collapsible-section {
    margin-bottom: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: white;
    overflow: hidden;
}

.collapsible-header {
    width: 100%;
    padding: 16px;
    background: var(--color-bg-hover);
    border: none;
    border-bottom: 1px solid var(--color-border);
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text-dark);
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s ease;
}

.collapsible-header:hover {
    background: var(--color-bg-section);
}

.collapsible-icon {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 12px;
}

.collapsible-header.collapsed .collapsible-icon {
    transform: rotate(-90deg);
}

.collapsible-header.collapsed {
    border-bottom: none;
}

.collapsible-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.collapsible-content.collapsed {
    max-height: 0;
    opacity: 0;
}

/* ============================================
   Organisation Settings Page
   ============================================ */
.org-settings-container {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.settings-header {
    margin-bottom: 32px;
}

.settings-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 8px 0;
}

.settings-header p {
    color: var(--color-text-muted);
    margin: 0;
}

.section-content {
    padding: 24px;
}

.section-controls {
    margin-bottom: 16px;
    display: flex;
    justify-content: flex-end;
}

/* Levels */
.levels-section {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    padding: 24px;
    margin-bottom: 24px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--color-border-light);
}

.section-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.levels-list {
    display: grid;
    gap: 12px;
}

.level-card {
    background: var(--color-bg-hover);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.level-reorder {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.level-info {
    flex: 1;
}

.level-name {
    font-weight: 600;
    font-size: 14px;
    margin: 0 0 4px 0;
}

.level-meta {
    font-size: 12px;
    color: var(--color-text-muted);
    margin: 0;
}

.level-actions {
    display: flex;
    gap: 8px;
    margin-left: 16px;
}

.level-style-preview {
    display: flex;
    align-items: center;
}

.style-swatch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 28px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    border: 1px solid var(--color-border);
}

/* Font Settings Modal Styles */
.font-settings-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border-light);
}

.font-settings-section h4 {
    margin: 0 0 12px 0;
    font-size: 13px;
    color: var(--color-text-muted);
    font-weight: 500;
}

.form-group-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.form-group-inline label {
    min-width: 120px;
    margin-bottom: 0;
}

.color-picker {
    width: 60px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.font-size-select {
    width: 100px;
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.style-preview {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-weight: 600;
    margin-top: 8px;
}

/* Elements */
.elements-grid {
    display: grid;
    gap: 16px;
}

.element-card {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px;
}

.element-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border-light);
}

.element-title {
    font-weight: 600;
    font-size: 14px;
    margin: 0;
}

.element-card-actions {
    display: flex;
    gap: 6px;
}

.element-subtitle {
    font-size: 12px;
    color: var(--color-text-muted);
    margin: 4px 0 0 0;
}

/* Groupings */
.groupings-list {
    background: var(--color-bg-hover);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 12px;
}

.groupings-label {
    font-size: 12px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: var(--color-text-dark);
}

.grouping-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
}

.grouping-item:last-child {
    margin-bottom: 0;
}

.grouping-value {
    font-size: 13px;
    color: var(--color-text-dark);
    flex: 1;
}

.grouping-actions {
    display: flex;
    gap: 4px;
}

.grouping-empty {
    font-size: 12px;
    color: var(--color-text-light);
    font-style: italic;
}

.btn-add-grouping {
    width: 100%;
    padding: 8px 12px;
    background: white;
    border: 1px dashed var(--color-border-dark);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
}

.btn-add-grouping:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-text-light);
}

/* Elements list (used in level detail modal) */
.elements-list {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    max-height: 300px;
    overflow-y: auto;
}

.elements-empty {
    padding: 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
}

.element-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--color-border-light);
}

.element-item:last-child {
    border-bottom: none;
}

.element-info {
    flex: 1;
}

.element-key {
    font-weight: 600;
    font-size: 12px;
    color: var(--color-text-dark);
    margin: 0 0 2px 0;
}

.element-label {
    font-size: 12px;
    color: var(--color-text-muted);
    margin: 0;
}

.element-actions {
    display: flex;
    gap: 6px;
    margin-left: 8px;
}

/* Configure Levels button (budgets page) */
#levelConfigButton {
    padding: 8px 12px;
    background: var(--color-primary-hover);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
}

#levelConfigButton:hover {
    background: var(--color-primary-dark);
}

/* Section description paragraphs */
.section-description {
    font-size: 13px;
    color: var(--color-text-muted);
    margin: 0 0 12px;
}

/* Labour Settings form layout */
.labour-settings-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 500px;
}

#labourFormulaInput {
    font-family: monospace;
}

.labour-formula-help {
    color: var(--color-text-muted);
}

.labour-settings-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.labour-settings-msg {
    font-size: 12px;
    margin: 0;
}

/* Import section */
.import-preview-stats {
    font-size: 13px;
    color: var(--color-text-dark);
    margin-bottom: 16px;
    line-height: 1.6;
}

.import-progress-msg {
    font-size: 13px;
    color: var(--color-text-dark);
    margin: 0 0 8px;
}

/* Disabled button state */
.btn-xs:disabled,
.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Element Maintenance Page
   ============================================ */
.element-maintenance-container {
    padding: 24px;
}

.element-maintenance-container .table-container {
    margin-bottom: 0;
}

.element-maintenance-container table {
    min-width: auto;
}

.element-maintenance-container td,
.element-maintenance-container th {
    padding: 7px 10px;
}

/* Description column (3rd child) */
.element-maintenance-container th:nth-child(3),
.element-maintenance-container td:nth-child(3) {
    min-width: 220px;
}

/* Drag-to-reorder handle */
.drag-handle-cell {
    width: 40px;
    text-align: center;
}

.row-drag-handle {
    font-size: 14px;
    color: #9ca3af;
    cursor: grab;
    display: inline-block;
    padding: 2px 4px;
    user-select: none;
}

.row-drag-handle:active {
    cursor: grabbing;
}

tr.row-dragging {
    opacity: 0.5;
}

tr.row-drag-over td {
    background: #eff0ff;
    border-top: 2px solid var(--color-primary, #6366f1);
}

.grouping-item.row-dragging {
    opacity: 0.5;
}

.grouping-item.row-drag-over {
    border-color: var(--color-primary, #6366f1);
    background: #eff0ff;
}

/* Grouping cell value padding — matches td height */
.element-maintenance-container .grouping-cell-value {
    padding: 6px 8px;
}

.reorder-btns {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
}

.item-actions {
    display: flex;
    gap: 4px;
}

.maintenance-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.import-label {
    cursor: pointer;
    display: inline-block;
}

.search-input {
    padding: 6px 10px;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-sm);
    font-size: 13px;
    width: 240px;
    outline: none;
}

.search-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 4px 0;
    font-size: 13px;
    color: var(--color-text-muted);
}

.pagination-btns {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-page {
    font-size: 13px;
    color: var(--color-text);
}

/* Order cell — click to edit */
.order-cell:hover {
    background: var(--color-bg-hover);
}

.order-cell-input {
    width: 56px;
    padding: 2px 4px;
    border: 2px solid var(--color-primary);
    border-radius: 0;
    font-size: 12px;
    text-align: center;
    outline: none;
}

/* Grouping cell — compact text, click to edit */
.grouping-cell {
    cursor: pointer;
    padding: 0 !important;
}

.grouping-cell:hover {
    background: var(--color-bg-hover);
}

.grouping-cell-value {
    display: block;
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.grouping-cell-value.unassigned {
    color: var(--color-text-light);
    font-style: italic;
}

.grouping-cell-value.assigned {
    font-weight: 600;
}

.grouping-cell .grouping-select {
    width: 100%;
    padding: 4px 6px;
    border: 2px solid var(--color-primary);
    border-radius: 0;
    font-size: 12px;
    background: white;
    outline: none;
}

/* ============================================
   User Management Page
   ============================================ */
.role-badge {
    padding: 4px 8px;
    border-radius: var(--radius-xl);
    font-size: 11px;
    font-weight: 500;
}

.role-user {
    background: var(--color-bg-section);
    color: var(--color-text);
}

.role-tenant_admin {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
}

.role-super_admin {
    background: #fce7f3;
    color: #9d174d;
}

.status-active {
    background: var(--color-success-light);
    color: var(--color-success-dark);
}

.status-inactive {
    background: var(--color-error-light);
    color: var(--color-error-dark);
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-primary);
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    text-decoration: underline;
}

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

.btn-icon {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 11px;
    color: var(--color-text);
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border-dark);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--color-border-dark);
    color: var(--color-text);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-outline:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-text-muted);
}

.user-count {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-left: 12px;
}

/* Grant Access Modal */
.grant-access-container {
    min-height: 200px;
}

.search-results {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

.search-results:empty {
    display: none;
}

.search-result-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--color-bg-hover);
}

.search-result-item strong {
    font-size: 13px;
    color: var(--color-text-dark);
}

.search-result-item span {
    font-size: 12px;
    color: var(--color-text-muted);
}

.search-empty {
    padding: 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
}

.selected-user {
    background: var(--color-bg-section);
    padding: 12px;
    border-radius: var(--radius-md);
    margin-top: 12px;
}

.selected-user-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.selected-user-info strong {
    font-size: 14px;
    color: var(--color-text-dark);
}

.selected-user-info span {
    font-size: 12px;
    color: var(--color-text-muted);
}

/* Restrictions Modal */
.restrictions-modal-content {
    min-height: 300px;
}

.restrictions-info {
    background: var(--color-bg-section);
    padding: 12px;
    border-radius: var(--radius-md);
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

.restrictions-info small {
    display: block;
    margin-top: 8px;
    font-size: 11px;
}

.restrictions-list {
    max-height: 400px;
    overflow-y: auto;
}

.restriction-element {
    margin-bottom: 20px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px;
}

.restriction-element h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-dark);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border-light);
}

.restriction-grouping {
    margin-bottom: 12px;
}

.restriction-grouping h5 {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

.restriction-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.restriction-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--color-text);
    cursor: pointer;
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-card);
    transition: all 0.15s ease;
}

.restriction-item:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.restriction-item input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.restriction-item input[type="checkbox"]:checked + span {
    font-weight: 500;
    color: var(--color-primary-dark);
}

.empty-hint {
    font-size: 12px;
    color: var(--color-text-light);
    font-style: italic;
}

/* ============================================
   Roles & Permissions Page
   ============================================ */

/* Tab bar */
.rp-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 20px;
}

.rp-tab {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
    transition: all 0.15s ease;
}

.rp-tab:hover {
    color: var(--color-text-dark);
    background: var(--color-bg-hover);
}

.rp-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: 600;
}

.rp-tab-content {
    display: none;
}

.rp-tab-content.active {
    display: block;
}

/* Permission checkbox grid */
.perm-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.perm-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--color-text);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
}

.perm-check:hover {
    background: var(--color-bg-hover);
}

.perm-check input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}


/* ============================================
   Rule Builder
   ============================================ */
#rule-builder-root {
    max-height: 400px;
    overflow-y: auto;
}

.rb-group {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--color-bg-section, #f9fafb);
}

.rb-group[data-depth="1"] {
    background: var(--color-bg-hover, #f3f4f6);
    margin-left: 16px;
    margin-top: 8px;
}

.rb-group[data-depth="2"] {
    background: var(--color-bg-card, #ffffff);
    margin-left: 16px;
    margin-top: 8px;
}

.rb-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.rb-logic-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    padding: 4px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background 0.15s;
}

.rb-logic-toggle:hover {
    opacity: 0.9;
}

.rb-logic-toggle:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.rb-logic-toggle.rb-logic-or {
    background: var(--color-warning, #f59e0b);
}

.rb-conditions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rb-condition {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px;
    background: var(--color-bg-card, #ffffff);
    border: 1px solid var(--color-border-light, #e5e7eb);
    border-radius: var(--radius-sm);
    flex-wrap: wrap;
}

.rb-condition select,
.rb-condition input[type="text"],
.rb-condition input[type="number"] {
    padding: 6px 10px;
    border: 1px solid var(--color-border-dark, #d1d5db);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: #fff;
    max-width: 100%;
    box-sizing: border-box;
}

.rb-condition select:focus,
.rb-condition input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.rb-field-select {
    width: 180px;
    flex-shrink: 0;
}

.rb-operator-select {
    width: 140px;
    flex-shrink: 0;
}

.rb-value-input {
    flex: 1 1 200px;
    min-width: 150px;
}

.rb-value-input .rb-number-input,
.rb-value-input .rb-text-input,
.rb-value-input .rb-enum-select {
    width: 100%;
    box-sizing: border-box;
}

.rb-placeholder {
    color: var(--color-text-muted, #9ca3af);
    font-size: 12px;
    font-style: italic;
    padding: 6px 0;
    display: inline-block;
}

.rb-multi-select {
    border: 1px solid var(--color-border-dark, #d1d5db);
    border-radius: var(--radius-sm);
    background: #fff;
    width: 100%;
    box-sizing: border-box;
}

.rb-multi-select-search {
    width: 100%;
    padding: 6px 10px;
    border: none;
    border-bottom: 1px solid var(--color-border-light, #e5e7eb);
    font-size: 12px;
    outline: none;
    box-sizing: border-box;
}

.rb-multi-select-list {
    max-height: 140px;
    overflow-y: auto;
    padding: 4px;
}

.rb-check-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px;
    border-radius: 3px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.rb-check-item:hover {
    background: var(--color-bg-hover, #f3f4f6);
}

.rb-check-item input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.rb-between-input {
    display: flex;
    align-items: center;
    gap: 6px;
}

.rb-between-input .rb-number-input {
    width: 80px;
}

.rb-between-sep {
    font-size: 12px;
    color: var(--color-text-muted, #6b7280);
}

.rb-remove-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-error, #ef4444);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 12px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
    flex-grow: 0;
}

.rb-remove-condition {
    font-size: 16px;
    font-weight: 700;
    padding: 2px 8px;
    align-self: flex-start;
    margin-top: 4px;
}

.rb-remove-btn:hover {
    background: var(--color-error, #ef4444);
    color: #fff;
    border-color: var(--color-error, #ef4444);
}

.rb-remove-btn:focus-visible {
    outline: 2px solid var(--color-error, #ef4444);
    outline-offset: 2px;
}

.rb-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.rb-actions .btn {
    font-size: 11px;
    padding: 4px 10px;
}

.rb-add-condition {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.rb-add-group {
    background: transparent;
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.rb-add-group:hover {
    background: var(--color-primary);
    color: #fff;
}

.rb-empty {
    text-align: center;
    padding: 24px;
    color: var(--color-text-muted, #9ca3af);
    font-size: 13px;
}

/* Filter tree summary in assignment table */
.rb-summary {
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rb-summary-tag {
    display: inline-block;
    background: var(--color-primary-light, #dbeafe);
    color: var(--color-primary-dark, #1e40af);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
    margin-right: 4px;
}

/* Lock type badges */
.lock-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-xl);
    font-size: 11px;
    font-weight: 500;
}

.lock-type-manual {
    background: var(--color-warning-light);
    color: var(--color-warning-dark);
}

.lock-type-workflow {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
}

.lock-type-period_close {
    background: var(--color-error-light);
    color: var(--color-error-dark);
}

/* Workflow cards */
.wf-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
}

/* Workflow steps progress */
.wf-steps {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.wf-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    border: 1px solid var(--color-border);
    background: var(--color-bg-section);
    color: var(--color-text-muted);
}

.wf-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    background: var(--color-border);
    color: var(--color-text-muted);
}

.wf-step-done {
    background: var(--color-success-light);
    border-color: var(--color-success-border);
    color: var(--color-success-dark);
}

.wf-step-done .wf-step-num {
    background: var(--color-success);
    color: white;
}

.wf-step-active {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    color: var(--color-primary-dark);
    font-weight: 500;
}

.wf-step-active .wf-step-num {
    background: var(--color-primary);
    color: white;
}

.wf-step-rejected {
    background: var(--color-error-light);
    border-color: var(--color-error-border);
    color: var(--color-error-dark);
}

.wf-step-rejected .wf-step-num {
    background: var(--color-error);
    color: white;
}

.wf-step-pending {
    opacity: 0.6;
}

.wf-step-arrow {
    color: var(--color-text-light);
    font-size: 14px;
    font-weight: 600;
}

.wf-lock-icon {
    font-size: 12px;
}

/* Workflow step row in create modal */
.wf-step-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--color-bg-section);
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.wf-step-row input[type="text"] {
    padding: 4px 8px;
    font-size: 12px;
}

.wf-step-row select {
    padding: 4px 6px;
    font-size: 12px;
}

.wf-step-row label {
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
}

.wf-step-row input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* Status badges (shared with workflow) */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-xl);
    font-size: 11px;
    font-weight: 500;
}

.status-active {
    background: var(--color-success-light);
    color: var(--color-success-dark);
}

.status-completed {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
}

.status-rejected {
    background: var(--color-error-light);
    color: var(--color-error-dark);
}

/* Explain result */
.explain-result {
    font-size: 13px;
    line-height: 1.6;
}

.explain-result h4 {
    margin: 12px 0 8px 0;
    font-size: 14px;
}

.explain-result hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 12px 0;
}

/* Locked cell indicator in budget grid */
.budget-cell-locked {
    background: #fef2f2 !important;
    cursor: not-allowed;
}

.budget-cell-locked input {
    pointer-events: none;
    opacity: 0.5;
    background: transparent !important;
}

/* Access Denied */
/* ===== Budget Profiling ===== */

/* Annual total input — blends into the cell, editable on focus */
.annual-total-input {
    background: transparent !important;
    border: none !important;
    font-weight: 600;
    color: inherit;
    text-align: right;
    width: 100%;
    padding: 1px 4px;
    box-sizing: border-box;
    cursor: text;
}

.annual-total-input:focus {
    background: #fff !important;
    border: 1px solid #6366f1 !important;
    outline: none;
    border-radius: 2px;
    color: #1f2937;
}

.annual-total-input.annual-total-locked {
    cursor: not-allowed !important;
    pointer-events: none;
}

.annual-total-input.annual-total-locked:focus {
    background: transparent !important;
    border: none !important;
    outline: none;
    cursor: not-allowed !important;
}

.profile-cell {
    padding: 0 2px !important;
    text-align: center;
    vertical-align: middle;
}

.profile-cell-icons {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 2px;
    white-space: nowrap;
}

.profile-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 3px;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.profile-btn:hover {
    opacity: 1;
    background: var(--hover-bg, #f3f4f6);
}

.profile-modal {
    min-width: 560px;
    max-width: 680px;
}

.profile-annual-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    font-size: 14px;
}

.profile-annual-row label {
    font-weight: 600;
}

.profile-annual-input {
    width: 160px;
    padding: 5px 8px;
    font-size: 14px;
    text-align: right;
    border: 1px solid #d1d5db;
    border-radius: 4px;
}

.profile-annual-input[readonly] {
    background: #f3f4f6;
    color: #6b7280;
}

.profile-method-group {
    margin: 12px 0;
}

.profile-method-group label {
    display: block;
    margin: 6px 0;
    cursor: pointer;
    font-size: 13px;
}

.profile-method-group input[type="radio"] {
    margin-right: 6px;
}

.profile-method-area {
    margin: 10px 0;
}

.profile-hint {
    font-size: 12px;
    color: #6b7280;
    margin: 0 0 8px 0;
}

.profile-inputs-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin: 8px 0;
}

.profile-inputs-grid > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.profile-inputs-grid label {
    font-size: 11px;
    color: #6b7280;
    text-align: center;
}

.profile-inputs-grid input {
    width: 100%;
    padding: 4px 4px;
    text-align: right;
    font-size: 12px;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    box-sizing: border-box;
}

.profile-inputs-grid .profile-ly-value,
.profile-inputs-grid .profile-preview-value {
    text-align: center;
    font-size: 12px;
}

.profile-ly-value {
    text-align: center;
    font-size: 12px;
    color: #374151;
}

.profile-pct-total {
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
    text-align: right;
}

.profile-option-row {
    margin: 10px 0;
    font-size: 13px;
}

.profile-option-row label {
    cursor: pointer;
}

.profile-validation-error {
    color: #dc2626;
    font-size: 12px;
    min-height: 16px;
    margin: 4px 0;
}

.profile-preview {
    background: #f9fafb;
    padding: 10px 12px;
    border-radius: 4px;
    margin: 12px 0;
}

.profile-preview strong {
    font-size: 13px;
}

.profile-preview-value {
    font-size: 12px;
    font-weight: 500;
    text-align: center;
}

.profile-preview-total {
    font-size: 12px;
    color: #374151;
    text-align: right;
    margin-top: 6px;
    font-weight: 600;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}

/* ===== Access Denied ===== */

.access-denied {
    text-align: center;
    padding: 60px 20px;
}

.access-denied h2 {
    font-size: 24px;
    color: var(--color-text-dark);
    margin-bottom: 12px;
}

.access-denied p {
    font-size: 14px;
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

/* ── Labour Budget Panel ─────────────────────────────────────────────────── */
.labour-panel {
    position: fixed;
    bottom: -50vh;
    left: var(--sidebar-width, 240px);
    right: 0;
    height: 50vh;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    z-index: var(--z-panel);
    transition: bottom 0.3s ease, left 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.labour-panel.open {
    bottom: 0;
}

.labour-panel-resize-handle {
    width: 100%;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
    flex-shrink: 0;
    background: transparent;
    user-select: none;
}

.labour-panel-resize-handle::before {
    content: '';
    width: 44px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    transition: background 0.15s;
}

.labour-panel-resize-handle:hover::before {
    background: #9ca3af;
}

.labour-panel.is-resizing {
    transition: none;
    user-select: none;
}

/* ── Transactions Panel ───────────────────────────────────────────────────── */
.txn-panel {
    position: fixed;
    bottom: -50vh;
    left: var(--sidebar-width, 240px);
    right: 0;
    height: 50vh;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    z-index: var(--z-panel);
    transition: bottom 0.3s ease, left 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.txn-panel.open {
    bottom: 0;
}

.txn-panel-resize-handle {
    width: 100%;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
    flex-shrink: 0;
    background: transparent;
    user-select: none;
}

.txn-panel-resize-handle::before {
    content: '';
    width: 44px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    transition: background 0.15s;
}

.txn-panel-resize-handle:hover::before {
    background: #9ca3af;
}

.txn-panel.is-resizing {
    transition: none;
    user-select: none;
}

.txn-panel-header {
    padding: 10px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
    flex-shrink: 0;
    gap: 12px;
}

.txn-panel-period-bar {
    display: flex;
    align-items: center;
    flex: 1;
}

/* Active/open state for the period filter button */
.txn-panel-period-bar .multi-filter-btn.open {
    border-color: var(--color-primary, #2563eb);
}

/* Ensure the dropdown panel sits above the table */
.txn-panel-period-bar .multi-filter-panel {
    z-index: 150;
}

.txn-panel-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
    width: 100%;
}

.txn-panel-table {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 13px;
}

.txn-panel-table th,
.txn-panel-table td {
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.txn-panel-table th {
    position: sticky;
    top: 0;
    background: #f9fafb;
    padding: 8px 20px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    z-index: 1;
}

.txn-panel-table th.num { text-align: right; }

.txn-panel-table td {
    padding: 8px 20px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    vertical-align: top;
}

.txn-panel-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.txn-panel-table tbody tr:hover td {
    background: #f9fafb;
}

.txn-panel-table tfoot td {
    position: sticky;
    bottom: 0;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 700;
    color: #111827;
    border-top: 2px solid #d1d5db;
    border-bottom: none;
    background: #f9fafb;
    z-index: 1;
}

.labour-panel-header {
    padding: 14px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
    flex-shrink: 0;
}

.labour-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.labour-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 14px;
    opacity: 0.65;
    line-height: 1;
}

.labour-btn:hover {
    opacity: 1;
}

.labour-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 13px;
    opacity: 0.7;
    line-height: 1;
}

.labour-action-btn:hover {
    opacity: 1;
}

/* ── Labour positions grid (matches main budget grid aesthetic) ── */
.labour-grid-wrap {
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    background: #fff;
}

.labour-grid {
    width: auto;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    color: var(--color-text);
}

.labour-grid tfoot tr {
    background: var(--color-bg-section);
}

.labour-grid tfoot td {
    padding: 7px 12px;
    font-weight: 700;
    font-size: 12px;
    color: #1f2937;
    border-top: 2px solid var(--color-border);
}

.labour-grid tfoot .col-info {
    font-weight: 700;
    background: #e5e9f0;
}

.labour-grid thead th {
    background: var(--color-bg-hover);
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
    border-bottom: 2px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 2;
}

.labour-grid thead th.col-right {
    text-align: right;
}

.labour-grid thead th.col-center {
    text-align: center;
}

.labour-grid tbody tr {
    background: #fff;
}

.labour-grid tbody tr:hover {
    background: var(--color-bg-hover);
}

.labour-grid tbody td {
    padding: 0;
    border-bottom: 1px solid var(--color-border-light);
    vertical-align: middle;
    position: relative;
}

/* Transparent inputs that look like plain text, reveal on focus */
.labour-grid input[type="text"],
.labour-grid input[type="number"] {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--color-text);
    box-sizing: border-box;
    font-family: inherit;
}

.labour-grid input[type="text"]:focus,
.labour-grid input[type="number"]:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    background: #fff;
}

.labour-grid input[type="number"] {
    text-align: right;
}

.labour-grid select {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    padding: 8px 6px;
    font-size: 12px;
    color: var(--color-text);
    box-sizing: border-box;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    -webkit-appearance: none;
    appearance: none;
}

.labour-grid select:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    background: #fff;
}

/* Info-column style for read-only cells (monthly cost) */
.labour-grid .col-info {
    background: var(--color-bg-section);
    font-weight: 600;
    color: #1f2937;
    padding: 8px 12px;
    text-align: right;
    white-space: nowrap;
}

/* Action cell */
.labour-grid .col-actions {
    padding: 4px 8px;
    white-space: nowrap;
    text-align: center;
}

.labour-grid-save-btn {
    border: none;
    background: var(--color-primary);
    color: #fff;
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
}

.labour-grid-save-btn:hover {
    background: #2563eb;
}

.labour-grid-save-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.labour-grid-del-btn {
    border: 1px solid #fca5a5;
    background: transparent;
    color: #ef4444;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 4px;
    font-family: inherit;
}

.labour-grid-del-btn:hover {
    background: #fef2f2;
}

/* ===== Rate Table Grid (org settings editor) ===== */
.rate-table-grid {
    border-collapse: collapse;
    font-size: 12px;
    min-width: 100%;
}

.rate-table-grid th {
    background: #f3f4f6;
    padding: 5px 8px;
    border: 1px solid #e5e7eb;
    font-weight: 600;
    white-space: nowrap;
    text-align: center;
}

.rate-table-grid td {
    border: 1px solid #f3f4f6;
    padding: 2px 4px;
    vertical-align: middle;
}

.rate-table-grid input[type="number"] {
    width: 76px;
    border: none;
    background: transparent;
    text-align: right;
    font-size: 12px;
    padding: 3px 4px;
    border-radius: 3px;
    font-family: inherit;
}

.rate-table-grid input[type="number"]:focus {
    outline: 2px solid var(--color-primary);
    background: #eff6ff;
}

/* ===== Rate Picker Grid (modal) ===== */
.rate-picker-grid {
    border-collapse: collapse;
    font-size: 12px;
    min-width: 100%;
}

.rate-picker-grid th {
    background: #f3f4f6;
    padding: 6px 10px;
    border: 1px solid #e5e7eb;
    font-weight: 600;
    white-space: nowrap;
    text-align: left;
}

.rate-picker-grid td {
    border: 1px solid #e5e7eb;
    padding: 6px 10px;
    text-align: right;
    cursor: pointer;
    transition: background 0.1s;
}

.rate-picker-grid tbody tr:hover td {
    background: #eff6ff;
}

/* ===== Labour Column Toggle Dropdown ===== */
.labour-col-toggle-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 1000;
    min-width: 170px;
    padding: 4px 0;
}

.labour-col-toggle-dropdown label:hover {
    background: #f9fafb;
}

/* ===== Import Budget page ===== */
.import-panel {
    max-width: 640px;
}

.import-drop-zone {
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 40px 24px;
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
}

.import-drop-zone.drag-over {
    border-color: #6366f1;
    background: #eef2ff;
}

.progress-bar-outer {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar-inner {
    height: 100%;
    background: #10b981;
    transition: width 0.3s ease;
}
/* ============================================
   Reports Page Styles
   ============================================ */

/* Page header */
.reports-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 12px;
}

.reports-page-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

/* Reports list */
.reports-list {
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Empty state */
.reports-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 60px 20px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

/* Report card */
.report-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    transition: box-shadow 0.15s ease;
}

.report-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.report-card-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.report-card-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.report-card-budget {
    font-size: 12px;
    color: var(--color-text-muted);
}

.report-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.report-card-tag {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--color-bg-section);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.report-card-tag--filter {
    background: #eef2ff;
    border-color: #c7d2fe;
    color: #4338ca;
}

.report-card-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Small button variant */
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* Results section (shown after running a report) */
.reports-results-section {
    margin: 0 20px 20px;
}

/* Config group (reused in the add/edit modal) */
.config-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.config-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.config-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text);
}

.config-group select,
.config-group input[type="text"] {
    padding: 8px;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-md);
    font-size: 12px;
    outline: none;
}

.config-group select:focus,
.config-group input[type="text"]:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.checkbox-item:hover {
    background: var(--color-bg-hover);
}

.checkbox-item input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--color-primary);
}

.filter-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}

.filter-section {
    padding: 8px;
    background: var(--color-bg-hover);
    border-radius: 4px;
}

/* ── Report Add/Edit Modal ── */

.report-modal-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 700px) {
    .report-modal-body {
        grid-template-columns: 1fr;
    }
}

.report-modal-left,
.report-modal-right {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.report-modal-filters-group {
    height: 100%;
}

.report-modal-filter-list {
    flex: 1;
    max-height: 340px;
    overflow-y: auto;
}

.report-modal-hint {
    color: var(--color-text-muted);
    font-size: 12px;
    margin: 0;
}

.report-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px 4px;
    border-top: 1px solid var(--color-border);
    margin-top: 4px;
}

.reports-results-panel {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.reports-results-panel .table-container {
    max-height: 600px;
    overflow: auto;
}

.reports-results-panel table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.reports-results-panel th {
    background: var(--color-bg-section);
    padding: 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.reports-results-panel td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border-light);
}

.reports-results-panel tbody tr:hover {
    background: var(--color-bg-hover);
}

#reportPlaceholder {
    min-height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.placeholder-icon {
    font-size: 40px;
    opacity: 0.4;
    line-height: 1;
}

.placeholder-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    color: var(--color-text);
}

.placeholder-hint {
    font-size: 12px;
    max-width: 280px;
    text-align: center;
    margin: 0;
    color: var(--color-text-muted);
    line-height: 1.5;
}

/* Config group header with select-all/none links */
.config-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.config-group-header label {
    margin: 0;
}

.select-all-links {
    font-size: 11px;
    white-space: nowrap;
    color: var(--color-text-muted);
}

.select-all-links a {
    color: var(--color-primary);
    text-decoration: none;
    cursor: pointer;
}

.select-all-links a:hover {
    text-decoration: underline;
}

/* Ghost/muted button for Reset */
.btn-ghost {
    background: transparent;
    border: 1px solid transparent;
    color: var(--color-text-muted);
    font-size: 12px;
    text-align: center;
    cursor: pointer;
    border-radius: var(--radius-md);
    padding: 6px 16px;
    width: 100%;
}

.btn-ghost:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border);
    color: var(--color-text);
}

/* Report results header */
.reports-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
}

.report-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
}

/* Report footer */
.report-footer {
    margin: 0;
    padding: 12px 16px;
    background: var(--color-bg-section);
    border-top: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.report-footer-items {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.report-footer-item {
    font-size: 13px;
}

.report-footer-label {
    font-weight: 600;
}

/* Report table: total rows */
.row-total td {
    font-weight: 600;
    background: var(--color-bg-section);
    border-top: 2px solid var(--color-border-dark);
}

/* Report table: dimension cell indentation */
.cell-dimension {
    display: inline-block;
}

.indent-0 .cell-dimension { margin-left: 0; }
.indent-1 .cell-dimension { margin-left: 20px; }
.indent-2 .cell-dimension { margin-left: 40px; }
.indent-3 .cell-dimension { margin-left: 60px; }
.indent-4 .cell-dimension { margin-left: 80px; }
.indent-5 .cell-dimension { margin-left: 100px; }

/* Filter section heading (replaces inline style) */
.filter-section-heading {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--color-text);
}

.filter-section-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Budget year display */
.budget-year-display {
    font-size: 11px;
    color: var(--color-text-muted);
    padding: 2px 4px;
    min-height: 16px;
}

/* ── Report result modal layout ── */

.report-result-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 12px;
    gap: 12px;
}

.report-result-subtitle {
    font-size: 13px;
    color: var(--color-text-muted);
    flex: 1;
}

/* Table grid inside the result modal */
.report-result-grid {
    max-height: 62vh;
    box-shadow: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: 4px;
}

.report-result-grid .table-container {
    max-height: 62vh;
}

/* Footer row count */
.report-result-footer {
    padding: 6px 4px 0;
    font-size: 12px;
    color: var(--color-text-muted);
    text-align: right;
}

/* Runtime filter bar: space before the table */
#reportRuntimeFilters {
    margin-bottom: 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

/* ── Runtime filter bar ── */

.report-runtime-filters {
    padding: 10px 16px;
    background: var(--color-bg-section);
    border-bottom: 1px solid var(--color-border);
}

.runtime-filter-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.runtime-search {
    flex: 1;
    max-width: 260px;
    padding: 6px 10px;
    font-size: 12px;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-md);
    outline: none;
    background: white;
}

.runtime-search:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.runtime-filter-sections {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.runtime-filter-section {
    min-width: 160px;
    max-width: 240px;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 8px 10px;
}

.runtime-filter-heading {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.runtime-filter-items {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-height: 140px;
    overflow-y: auto;
}

/* ── Level formatting controls in the modal ── */

.level-format-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.level-format-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--color-bg-hover);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
}

.level-format-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text);
    min-width: 90px;
    flex: 1;
}

.level-format-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--color-text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.level-format-bg,
.level-format-text {
    width: 28px;
    height: 22px;
    padding: 1px;
    border: 1px solid var(--color-border-dark);
    border-radius: 3px;
    cursor: pointer;
}

.level-format-size {
    font-size: 11px;
    padding: 3px 6px;
    border: 1px solid var(--color-border-dark);
    border-radius: var(--radius-md);
    background: white;
    color: var(--color-text);
    cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════
   Budget Comments
   ═══════════════════════════════════════════════════════════════ */

.comment-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    line-height: 1;
    opacity: 0.35;
    transition: opacity 0.15s;
}

.comment-btn:hover {
    opacity: 1;
    background: var(--hover-bg, #f3f4f6);
}

.comment-btn.has-comment {
    opacity: 1;
}

.comment-header-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 1px 3px;
    line-height: 1;
    opacity: 0.35;
    transition: opacity 0.15s;
    margin-left: 6px;
    vertical-align: middle;
}

.comment-header-icon:hover,
.comment-header-icon.has-comment {
    opacity: 1;
}

.comment-modal-type-section {
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    padding: 14px 16px;
    background: var(--color-bg-surface, #f9fafb);
}

.comment-type-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
}

.comment-type-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.comment-scope-badge {
    font-size: 10px;
    font-weight: 400;
    color: var(--color-text-muted, #6b7280);
    background: var(--color-bg-card, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 4px;
}

.comment-textarea {
    width: 100%;
    min-height: 72px;
    resize: vertical;
    padding: 8px 10px;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    color: var(--color-text, #111827);
    background: var(--color-bg-card, #fff);
    box-sizing: border-box;
    transition: border-color 0.15s;
}

.comment-textarea:focus {
    outline: none;
    border-color: var(--color-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.comment-action-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.comment-save-btn {
    padding: 5px 14px;
    background: var(--color-primary, #2563eb);
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.comment-save-btn:hover {
    background: var(--color-primary-dark, #1d4ed8);
}

.comment-clear-btn {
    padding: 5px 12px;
    background: transparent;
    color: var(--color-text-muted, #6b7280);
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    transition: color 0.15s;
}

.comment-clear-btn:hover {
    color: var(--color-error, #ef4444);
    border-color: var(--color-error, #ef4444);
}

.comment-meta {
    font-size: 11px;
    color: var(--color-text-muted, #9ca3af);
    margin-top: 4px;
}

/* Report footer count */
.report-footer-count {
    font-size: 12px;
    color: var(--color-text-muted);
}

/* ══════════════════════════════════════════════════════════════
   Attachment Button (in budget grid profile cell)
══════════════════════════════════════════════════════════════ */

.attach-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
    color: var(--color-text-secondary, #6b7280);
    opacity: 0.5;
    position: relative;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    transition: opacity 0.15s, color 0.15s;
}

.attach-btn:hover {
    opacity: 1;
    color: var(--color-primary, #3b82f6);
    background: var(--color-primary-10, #eff6ff);
}

.attach-btn.has-attachments {
    opacity: 1;
    color: var(--color-primary, #3b82f6);
}

.attach-count-badge {
    background: var(--color-primary, #3b82f6);
    color: #fff;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    padding: 0 5px;
    min-width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ══════════════════════════════════════════════════════════════
   Attachment Modal
══════════════════════════════════════════════════════════════ */

.attach-modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 9000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.attach-modal {
    background: var(--color-surface, #fff);
    border-radius: 10px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.attach-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-surface-alt, #f9fafb);
    flex-shrink: 0;
}

.attach-modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text, #111827);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attach-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--color-text-secondary, #6b7280);
    padding: 4px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.attach-modal-close:hover {
    background: var(--color-hover, #f3f4f6);
    color: var(--color-text, #111827);
}

.attach-modal-body {
    padding: 16px 18px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Attachment list */
.attach-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.attach-empty {
    color: var(--color-text-muted, #9ca3af);
    font-size: 13px;
    padding: 12px 0;
    text-align: center;
}

.attach-error {
    color: var(--color-error, #ef4444);
}

.attach-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    background: var(--color-surface-alt, #f9fafb);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 7px;
}

.attach-item-icon {
    font-size: 22px;
    flex-shrink: 0;
    line-height: 1.2;
}

.attach-item-info {
    flex: 1;
    min-width: 0;
}

.attach-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text, #111827);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attach-item-meta {
    font-size: 11px;
    color: var(--color-text-muted, #9ca3af);
    margin-top: 2px;
}

.attach-sync-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.attach-sync-badge {
    font-size: 10px;
    font-weight: 600;
    background: var(--color-primary-10, #eff6ff);
    color: var(--color-primary, #3b82f6);
    border: 1px solid var(--color-primary-30, #bfdbfe);
    border-radius: 10px;
    padding: 1px 7px;
}

.attach-item-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.attach-action-btn {
    background: none;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    padding: 3px 8px;
    color: var(--color-text-secondary, #6b7280);
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
}

.attach-action-btn:hover {
    background: var(--color-hover, #f3f4f6);
    color: var(--color-text, #111827);
}

.attach-delete-btn:hover {
    background: var(--color-error-light, #fef2f2);
    color: var(--color-error, #ef4444);
    border-color: var(--color-error, #ef4444);
}

.attach-sync-btn {
    color: var(--color-primary, #3b82f6);
    border-color: var(--color-primary, #3b82f6);
}

.attach-sync-btn:hover {
    background: var(--color-primary-10, #eff6ff);
}

/* Upload toggle */
.attach-upload-toggle-row {
    display: flex;
    justify-content: flex-start;
}

.attach-upload-toggle-btn {
    background: none;
    border: 1px dashed var(--color-border, #d1d5db);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    padding: 7px 14px;
    color: var(--color-primary, #3b82f6);
    width: 100%;
    text-align: left;
    transition: background 0.12s;
}

.attach-upload-toggle-btn:hover {
    background: var(--color-primary-10, #eff6ff);
}

/* Upload form */
.attach-upload-form {
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    padding: 14px;
    background: var(--color-surface-alt, #f9fafb);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.attach-form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.attach-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-secondary, #6b7280);
}

.attach-file-input {
    font-size: 13px;
    color: var(--color-text, #111827);
}

.attach-text-input {
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 5px;
    padding: 6px 10px;
    font-size: 13px;
    background: var(--color-surface, #fff);
    color: var(--color-text, #111827);
    width: 100%;
    box-sizing: border-box;
}

.attach-text-input:focus {
    outline: none;
    border-color: var(--color-primary, #3b82f6);
    box-shadow: 0 0 0 2px var(--color-primary-20, #dbeafe);
}

.attach-select {
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 5px;
    padding: 6px 10px;
    font-size: 13px;
    background: var(--color-surface, #fff);
    color: var(--color-text, #111827);
    cursor: pointer;
}

/* Excel options section */
.attach-excel-options {
    border: 1px solid var(--color-primary-30, #bfdbfe);
    border-radius: 7px;
    padding: 12px;
    background: var(--color-primary-5, #f0f9ff);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.attach-excel-heading {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary, #3b82f6);
}

/* Monthly cell mapping grid */
.attach-monthly-hint {
    font-size: 12px;
    color: var(--color-text-secondary, #6b7280);
    margin: 0;
}

.attach-monthly-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.attach-month-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.attach-month-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary, #6b7280);
    width: 80px;
    flex-shrink: 0;
}

/* Form actions */
.attach-form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 4px;
}

.attach-btn-primary {
    background: var(--color-primary, #3b82f6);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 7px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.attach-btn-primary:hover { background: var(--color-primary-hover, #2563eb); }
.attach-btn-primary:disabled { opacity: 0.6; cursor: default; }

.attach-btn-secondary {
    background: var(--color-surface, #fff);
    color: var(--color-text-secondary, #6b7280);
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 6px;
    padding: 7px 18px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}

.attach-btn-secondary:hover { background: var(--color-hover, #f3f4f6); }

/* Config sub-dialog */
.attach-config-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.attach-config-dialog {
    max-width: 500px;
    max-height: 85vh;
}

/* ══════════════════════════════════════════════════════════════
   Documents Page
══════════════════════════════════════════════════════════════ */

.docs-page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.docs-page-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text, #111827);
    margin: 0;
}

.docs-filters {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 12px 14px;
    background: var(--color-surface-alt, #f9fafb);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
}

.docs-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.docs-filter-search {
    flex: 1;
    min-width: 180px;
}

.docs-filter-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-secondary, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.docs-select {
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 5px;
    padding: 6px 10px;
    font-size: 13px;
    background: var(--color-surface, #fff);
    color: var(--color-text, #111827);
    cursor: pointer;
    min-width: 140px;
}

.docs-search-input {
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 5px;
    padding: 6px 10px;
    font-size: 13px;
    background: var(--color-surface, #fff);
    color: var(--color-text, #111827);
    width: 100%;
}

.docs-search-input:focus,
.docs-select:focus {
    outline: none;
    border-color: var(--color-primary, #3b82f6);
    box-shadow: 0 0 0 2px var(--color-primary-20, #dbeafe);
}

.docs-refresh-btn {
    align-self: flex-end;
}

.docs-table-container {
    overflow-x: auto;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
}

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

.docs-table th {
    background: var(--color-surface-alt, #f3f4f6);
    color: var(--color-text-secondary, #6b7280);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    white-space: nowrap;
}

.docs-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border-light, #f3f4f6);
    color: var(--color-text, #111827);
    vertical-align: top;
}

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

.docs-table tr:hover td {
    background: var(--color-hover, #f9fafb);
}

.docs-type-cell {
    font-size: 18px;
    text-align: center;
    width: 36px;
}

.docs-name-cell {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.docs-desc {
    font-size: 11px;
    color: var(--color-text-muted, #9ca3af);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.docs-dimkey-cell {
    font-family: monospace;
    font-size: 11px;
    color: var(--color-text-muted, #9ca3af);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.docs-sync-badge {
    font-size: 10px;
    font-weight: 600;
    background: var(--color-primary-10, #eff6ff);
    color: var(--color-primary, #3b82f6);
    border: 1px solid var(--color-primary-30, #bfdbfe);
    border-radius: 10px;
    padding: 2px 8px;
}

.docs-actions-cell {
    white-space: nowrap;
    display: flex;
    gap: 6px;
}

.docs-action-btn {
    background: none;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    padding: 3px 9px;
    color: var(--color-text-secondary, #6b7280);
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
}

.docs-action-btn:hover {
    background: var(--color-hover, #f3f4f6);
    color: var(--color-text, #111827);
}

.docs-delete-btn:hover {
    background: var(--color-error-light, #fef2f2);
    color: var(--color-error, #ef4444);
    border-color: var(--color-error, #ef4444);
}

.docs-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--color-text-muted, #9ca3af);
    font-size: 14px;
}

.docs-error {
    color: var(--color-error, #ef4444);
}

.docs-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 12px;
    padding: 8px;
}

.docs-page-info {
    font-size: 13px;
    color: var(--color-text-secondary, #6b7280);
}

/* ═══════════════════════════════════════════════════════════════
   Excel Editor (in-browser spreadsheet via x-data-spreadsheet)
═══════════════════════════════════════════════════════════════ */

.xled-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1200;
    align-items: stretch;
    justify-content: center;
    padding: 16px;
}

.xled-container {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1400px;
    overflow: hidden;
}

.xled-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    background: #f9fafb;
    flex-shrink: 0;
}

.xled-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-primary, #111827);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xled-header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    margin-left: 16px;
}

.xled-sheet-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* x-data-spreadsheet resets to fill the container */
.xled-sheet-container .x-spreadsheet {
    border: none !important;
}

.xled-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 200px;
    font-size: 14px;
    color: var(--color-text-secondary, #6b7280);
}

.xled-error {
    color: #dc2626;
}
/* ═══════════════════════════════════════
   Allocation sub-rows (budget grid)
   ═══════════════════════════════════════ */
.alloc-sub-row td {
    font-style: italic;
    font-size: 0.83em;
    color: #6b7280;
    background: #f9fafb;
    padding-top: 2px \!important;
    padding-bottom: 2px \!important;
    border-top: none \!important;
    user-select: none;
}
.alloc-sub-row td input {
    display: none;
}
.alloc-out-row > td:first-child {
    border-left: 3px solid #f59e0b;
    padding-left: 5px \!important;
}
.alloc-in-row > td:first-child {
    border-left: 3px solid #3b82f6;
    padding-left: 5px \!important;
}
.alloc-sub-row .alloc-amount {
    color: #374151;
    font-style: normal;
    font-size: 0.83em;
}

/* ═══════════════════════════════════════════════════════════════
   REPORTS LIST PAGE  (/reports.html)
   ═══════════════════════════════════════════════════════════════ */

.rpt-section {
    margin-bottom: 32px;
}

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

.rpt-section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text-secondary, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.rpt-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rpt-empty {
    font-size: 13px;
    color: var(--color-text-muted, #9ca3af);
    padding: 16px 0;
}

.rpt-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: #fff;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    padding: 14px 16px;
    transition: box-shadow 0.15s;
}

.rpt-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.rpt-card-main {
    flex: 1;
    min-width: 0;
}

.rpt-card-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.rpt-card-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text, #111827);
}

.rpt-card-desc {
    font-size: 12px;
    color: var(--color-text-secondary, #6b7280);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rpt-card-meta {
    font-size: 12px;
    color: var(--color-text-muted, #9ca3af);
}

.rpt-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.rpt-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.rpt-badge--published {
    background: #d1fae5;
    color: #065f46;
}

.rpt-badge--draft {
    background: #e0e7ff;
    color: #3730a3;
}

/* ═══════════════════════════════════════════════════════════════
   REPORT BUILDER PAGE  (/report-builder.html)
   ═══════════════════════════════════════════════════════════════ */

.rb-layout {
    max-width: 860px;
    margin: 0 auto;
    padding-bottom: 80px; /* space for sticky save bar */
}

.rb-sections {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.rb-section {
    background: #fff;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    padding: 20px 24px;
    margin-bottom: 16px;
}

.rb-section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary, #6b7280);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
}

.rb-subsection-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text, #374151);
    margin-bottom: 8px;
}

.rb-hint-inline {
    font-size: 11px;
    font-weight: 400;
    color: var(--color-text-muted, #9ca3af);
}

.rb-field {
    margin-bottom: 16px;
}

.rb-field:last-child {
    margin-bottom: 0;
}

.rb-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text, #374151);
    margin-bottom: 6px;
}

.rb-required {
    color: #dc2626;
}

.rb-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 5px;
    font-size: 13px;
    color: var(--color-text, #111827);
    background: #fff;
    box-sizing: border-box;
}

.rb-input:focus {
    outline: none;
    border-color: var(--color-primary, #6366f1);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

.rb-textarea {
    resize: vertical;
    min-height: 56px;
}

.rb-hint {
    font-size: 11px;
    color: var(--color-text-muted, #9ca3af);
    margin-top: 4px;
    display: block;
}

.rb-field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.rb-select-all {
    font-size: 11px;
    color: var(--color-text-muted, #9ca3af);
}

.rb-select-all a {
    color: var(--color-primary, #6366f1);
    text-decoration: none;
}

.rb-checklist {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 5px;
    background: #fafafa;
}

.rb-check-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--color-text, #374151);
    cursor: pointer;
    padding: 3px 4px;
    border-radius: 3px;
}

.rb-check-item:hover {
    background: rgba(99,102,241,0.06);
}

.rb-radio-group {
    display: flex;
    gap: 20px;
}

.rb-radio {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--color-text, #374151);
    cursor: pointer;
}

/* Styling rows */
.rb-styling-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rb-style-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 5px;
    background: #fafafa;
    flex-wrap: wrap;
}

.rb-style-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text, #374151);
    min-width: 100px;
    flex: 1;
}

.rb-style-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--color-text-muted, #9ca3af);
    cursor: pointer;
}

.rb-color {
    width: 28px;
    height: 22px;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    cursor: pointer;
}

.rb-size {
    font-size: 12px;
    padding: 3px 6px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 4px;
    background: #fff;
    color: var(--color-text, #374151);
}

/* Column reorder list */
.rb-col-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rb-col-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 5px;
    background: #fff;
    cursor: grab;
    transition: background 0.1s, box-shadow 0.1s;
}

.rb-col-row:hover {
    background: #f5f5ff;
}

.rb-col-row.rb-col-dragging {
    opacity: 0.5;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.rb-col-row.rb-col-drag-over {
    border-color: var(--color-primary, #6366f1);
    background: #eff0ff;
}

.rb-col-drag {
    font-size: 14px;
    color: #9ca3af;
    cursor: grab;
    flex-shrink: 0;
}

.rb-col-visible {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    cursor: pointer;
}

.rb-col-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text, #374151);
}

.rb-col-fmt,
.rb-col-align {
    font-size: 12px;
    padding: 3px 6px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 4px;
    background: #fff;
    color: var(--color-text, #374151);
    flex-shrink: 0;
}

/* Filter panels */
.rb-filter-panel {
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 5px;
    padding: 10px;
    background: #fafafa;
    max-height: 220px;
    overflow-y: auto;
}

.rb-filter-section {
    margin-bottom: 12px;
}

.rb-filter-section:last-child {
    margin-bottom: 0;
}

.rb-filter-heading {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text, #374151);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.rb-filter-items {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* Sticky save bar */
.rb-save-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid var(--color-border, #e5e7eb);
    padding: 12px 24px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

/* ═══════════════════════════════════════════════════════════════
   REPORT VIEWER PAGE  (/report-view.html)
   ═══════════════════════════════════════════════════════════════ */

.rv-topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.rv-topbar-left {
    flex: 1;
    min-width: 0;
}

.rv-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text, #111827);
    margin: 0 0 4px;
}

.rv-subtitle {
    font-size: 13px;
    color: var(--color-text-muted, #9ca3af);
}

.rv-topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Applied filters info box */
.rv-applied-filters {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.rv-applied-filters-label {
    font-size: 12px;
    font-weight: 600;
    color: #92400e;
    white-space: nowrap;
}

.rv-applied-filters-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rv-filter-tag {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #fef3c7;
    color: #78350f;
    border: 1px solid #fde68a;
}

/* Interactive filter bar */
.rv-filter-bar {
    background: #f9fafb;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 12px;
}

.rv-filter-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.rv-search {
    flex: 1;
    max-width: 300px;
    padding: 6px 10px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 5px;
    font-size: 13px;
    background: #fff;
}

.rv-search:focus {
    outline: none;
    border-color: var(--color-primary, #6366f1);
}

.rv-filter-sections {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.rv-filter-section {
    min-width: 140px;
}

.rv-filter-heading {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary, #6b7280);
    margin-bottom: 6px;
}

.rv-filter-items {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* Report table wrapper */
.rv-table-wrap {
    overflow-x: auto;
}

.rv-footer {
    font-size: 12px;
    color: var(--color-text-muted, #9ca3af);
    margin-top: 8px;
    text-align: right;
}

/* breadcrumb separator */
.breadcrumb-sep {
    color: var(--color-text-muted, #9ca3af);
    margin: 0 4px;
    font-weight: 400;
}
