/* ===== Astral 365 Brand Overrides ===== */
:root {
    --astral-primary: #7030a0;
    --astral-primary-rgb: 112, 48, 160;
    --astral-light: #c198e0;
    --astral-dark: #5a2680;
    --astral-very-light: #f3eaf9;
    --astral-bg: #faf7fc;
    --bs-primary: #7030a0;
    --bs-primary-rgb: 112, 48, 160;
    --bs-link-color: #7030a0;
    --bs-link-hover-color: #5a2680;
}

/* ===== Bootstrap Component Overrides ===== */
.btn-primary { background-color: var(--astral-primary); border-color: var(--astral-primary); }
.btn-primary:hover, .btn-primary:active, .btn-primary:focus { background-color: var(--astral-dark); border-color: var(--astral-dark); }
.btn-outline-primary { color: var(--astral-primary); border-color: var(--astral-primary); }
.btn-outline-primary:hover { background-color: var(--astral-primary); color: #fff; }
.badge.bg-primary { background-color: var(--astral-primary) !important; }
.form-check-input:checked { background-color: var(--astral-primary); border-color: var(--astral-primary); }
.form-control:focus, .form-select:focus {
    border-color: var(--astral-light);
    box-shadow: 0 0 0 0.2rem rgba(var(--astral-primary-rgb), 0.25);
}
a { color: var(--astral-primary); }
a:hover { color: var(--astral-dark); }
.page-link { color: var(--astral-primary); }
.page-link:hover { color: var(--astral-dark); }
.active > .page-link { background-color: var(--astral-primary); border-color: var(--astral-primary); }
.breadcrumb-item a { color: var(--astral-primary); text-decoration: none; }
.breadcrumb-item a:hover { color: var(--astral-dark); }

/* ===== Layout ===== */
html, body { height: 100%; margin: 0; overflow: hidden; }
#app { display: flex; flex-direction: column; height: 100vh; }

.content-wrapper {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ===== Navbar ===== */
#navbar-container .navbar {
    background-color: var(--astral-primary) !important;
    min-height: 56px;
}
#navbar-container .navbar-brand { font-weight: 600; letter-spacing: 0.5px; }

/* ===== Sidebar ===== */
#sidebar-container {
    width: 220px;
    min-width: 220px;
    background-color: var(--astral-dark);
    color: #fff;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-group-header {
    display: block;
    padding: 16px 16px 4px 16px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.45);
    letter-spacing: 1px;
}

.sidebar-link {
    display: block;
    padding: 8px 16px 8px 20px;
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    font-size: 0.875rem;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
}
.sidebar-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
    text-decoration: none;
}
.sidebar-link.active {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.15);
    border-left-color: var(--astral-light);
}

/* ===== Page Content ===== */
#page-content {
    flex: 1;
    padding: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--astral-bg);
    min-width: 0;
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e9ecef;
}
.page-header h5 { margin: 0; font-weight: 600; color: #333; }
.page-header .breadcrumb { margin-bottom: 0; font-size: 0.85rem; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ===== Data Grid ===== */
.data-grid-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.data-grid-card { flex: 1; min-height: 0; overflow: hidden; }
.data-grid-card .card-body { padding: 0; }
.data-grid-table-wrapper { flex: 1; overflow-y: auto; overflow-x: auto; }
.data-grid-card .table { margin-bottom: 0; }
.data-grid-card .table thead th {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
    border-bottom: 2px solid var(--astral-light);
    padding: 10px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    cursor: default;
}
.data-grid-card .table thead th.sortable { cursor: pointer; user-select: none; }
.data-grid-card .table thead th.sortable:hover { color: var(--astral-primary); }
.data-grid-card .table tbody td { font-size: 0.85rem; vertical-align: middle; }
.data-grid-card .table-hover tbody tr:hover { background-color: var(--astral-very-light); }
.sort-arrow { font-size: 0.65rem; margin-left: 4px; opacity: 0.4; }
.sort-arrow.active { opacity: 1; color: var(--astral-primary); }
.data-grid-card .table thead tr:first-child th { height: 40px; }
.data-grid-card .table thead tr.filter-row th {
    position: sticky;
    top: 40px;
    background: #fff;
    z-index: 1;
    padding: 4px 6px;
    border-bottom: 1px solid #e9ecef;
}
.filter-input {
    font-size: 0.75rem !important;
    padding: 2px 6px !important;
    height: 26px !important;
    background-color: var(--astral-very-light) !important;
    border: 1px solid #dee2e6 !important;
}
.filter-input::placeholder { color: #adb5bd; font-style: italic; }
.filter-input:focus { background-color: #fff !important; }
/* Context menu */
.datagrid-context-menu {
    position: absolute;
    z-index: 1050;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    padding: 4px 0;
}
.datagrid-context-item {
    padding: 8px 16px;
    font-size: 0.85rem;
    color: #333;
    cursor: pointer;
    white-space: nowrap;
}
.datagrid-context-item:hover {
    background-color: var(--astral-very-light);
    color: var(--astral-primary);
}
/* ===== Environment Badge ===== */
#env-badge {
    letter-spacing: 1px;
    font-weight: 700;
    transition: opacity 0.15s;
}
#env-badge:hover {
    opacity: 0.85;
}
.data-grid-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    font-size: 0.8rem;
    color: #6c757d;
    border-top: 1px solid #e9ecef;
}

/* ===== Drilldown Badge ===== */
.badge-link {
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s;
}
.badge-link:hover { opacity: 0.85; }

/* ===== Line Editor ===== */
.line-editor {
    padding: 12px 16px;
    background: var(--astral-very-light);
    border-bottom: 1px solid #e9ecef;
}

/* ===== Login Page ===== */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--astral-very-light);
}
.login-card {
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 8px;
    overflow: hidden;
}
.login-card .card-header {
    background: linear-gradient(135deg, var(--astral-primary), var(--astral-dark));
    color: #fff;
    text-align: center;
    padding: 24px;
    border-bottom: none;
}
.login-card .card-header h4 { margin: 0; font-weight: 600; }
.login-card .card-header p { margin: 4px 0 0 0; opacity: 0.85; font-size: 0.85rem; }
.login-card .card-body { padding: 24px; }

/* ===== Index Status ===== */
.index-card { transition: border-color 0.2s; }
.index-card.index-exists { border-left: 4px solid #198754; }
.index-card.index-missing { border-left: 4px solid #dc3545; }

/* ===== Detail Panel ===== */
.grid-detail-wrapper {
    display: flex;
    gap: 0;
    align-items: stretch;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.grid-detail-wrapper > :first-child {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.detail-panel {
    width: 300px;
    min-width: 300px;
    height: 100%;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    margin-left: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: width 0.2s, min-width 0.2s, margin 0.2s, opacity 0.2s;
}
.detail-panel.collapsed {
    width: 0;
    min-width: 0;
    margin-left: 0;
    border: none;
    opacity: 0;
}
.detail-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #555;
    border-bottom: 2px solid var(--astral-light);
    background: #fff;
}
.detail-panel-toggle {
    padding: 0 4px;
    font-size: 1rem;
    line-height: 1;
    color: var(--astral-primary);
    text-decoration: none;
}
.detail-panel-body {
    flex: 1;
    overflow-y: auto;
}
.detail-panel-list {
    margin: 0;
    padding: 0;
}
.detail-panel-list dt {
    padding: 8px 14px 2px 14px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
    margin: 0;
}
.detail-panel-list dd {
    padding: 0 14px 6px 14px;
    font-size: 0.85rem;
    color: #212529;
    margin: 0;
    border-bottom: 1px solid #f0f0f0;
    word-break: break-word;
}
.text-truncate-url {
    display: block;
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: help;
}
.table-active {
    background-color: var(--astral-very-light) !important;
}

/* ===== Utility ===== */
.text-astral { color: var(--astral-primary); }
.bg-astral { background-color: var(--astral-primary); }
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--astral-primary);
}
.form-switch .form-check-input { cursor: pointer; }
.form-switch .form-check-input:disabled { cursor: not-allowed; opacity: 0.5; }

/* ===== Search Page ===== */
.search-input-group { max-width: 600px; margin-bottom: 16px; }
.search-results-section { margin-bottom: 20px; }
.search-results-section h6 { font-weight: 600; color: #555; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.5px; margin-bottom: 8px; }
.search-message { text-align: center; color: #6c757d; padding: 48px; font-size: 0.9rem; }

/* ===== Table Modal ===== */
.table-modal-wrapper { max-height: 400px; overflow-y: auto; }

/* ===== Company Picker ===== */
.company-selectable { cursor: pointer; color: var(--astral-primary); }
.company-selectable:hover { background-color: var(--astral-very-light); }
.company-selected { background-color: var(--astral-light) !important; color: #fff; font-weight: 600; }
