/* ===== 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-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    font-size: 0.8rem;
    color: #6c757d;
    border-top: 1px solid #e9ecef;
}

/* Data Grid: Filter Row */
.data-grid-card .table thead tr.filter-row th {
    position: sticky;
    top: 38px;
    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:focus {
    background-color: #fff !important;
    border-color: var(--astral-light) !important;
    box-shadow: 0 0 0 0.15rem rgba(var(--astral-primary-rgb), 0.15);
}
.filter-input::placeholder { color: #adb5bd; font-style: italic; }

/* Data Grid: Context Menu */
.datagrid-context-menu {
    position: fixed;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 2000;
    min-width: 180px;
    padding: 4px 0;
}
.datagrid-context-item {
    padding: 6px 14px;
    font-size: 0.8rem;
    cursor: pointer;
    color: #333;
}
.datagrid-context-item:hover {
    background: var(--astral-very-light);
    color: var(--astral-primary);
}

/* Data Grid: Badge Links */
.badge-link { text-decoration: none; cursor: pointer; }
.badge-link:hover { opacity: 0.85; }

/* ===== 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; }

/* ===== Grid + Detail Wrapper ===== */
.grid-detail-wrapper { display: flex; gap: 0; align-items: stretch; flex: 1; min-height: 0; }

/* ===== Detail Panel ===== */
.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-left 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;
    flex-shrink: 0;
}
.detail-panel-body { flex: 1; overflow-y: auto; padding: 0; }
.detail-panel-list { margin: 0; padding: 12px 14px; }
.detail-panel-list dt { font-size: 0.75rem; font-weight: 600; color: #555; text-transform: uppercase; margin-top: 10px; }
.detail-panel-list dt:first-child { margin-top: 0; }
.detail-panel-list dd { font-size: 0.85rem; margin: 2px 0 0 0; word-break: break-all; }
.detail-panel-toggle { font-size: 0.75rem; padding: 0 4px; color: #6c757d; text-decoration: none; border: none; background: none; cursor: pointer; }
.detail-panel-toggle:hover { color: var(--astral-primary); }
.text-truncate-url { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8rem; }

/* ===== Dashboard Metrics ===== */
.metric-card { text-align: center; padding: 20px; }
.metric-card .metric-value { font-size: 2rem; font-weight: 700; color: var(--astral-primary); }
.metric-card .metric-label { font-size: 0.8rem; color: #6c757d; text-transform: uppercase; letter-spacing: 0.5px; }

/* ===== Search Results ===== */
.search-result-item { display: block; padding: 10px 14px; border-bottom: 1px solid #f0f0f0; cursor: pointer; text-decoration: none; color: inherit; }
.search-result-item:hover { background-color: var(--astral-very-light); text-decoration: none; color: inherit; }
.search-result-title { font-size: 0.9rem; font-weight: 500; }
.search-result-subtitle { font-size: 0.8rem; color: #6c757d; }

/* ===== Subscription Cards ===== */
.subscription-card { border-left: 3px solid var(--astral-light); margin-bottom: 8px; }
.subscription-card.status-active { border-left-color: #198754; }
.subscription-card.status-trial { border-left-color: #0dcaf0; }
.subscription-card.status-expired { border-left-color: #dc3545; }
.subscription-card.status-suspended { border-left-color: #ffc107; }
.subscription-card.status-unlicensed { border-left-color: #6c757d; }
.subscription-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; cursor: pointer; }
.subscription-header:hover { background-color: #f8f9fa; }
.subscription-body { padding: 0 14px 14px 14px; display: none; }
.subscription-body.show { display: block; }

/* ===== Audit Log ===== */
.audit-filter-bar {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid #e9ecef;
    align-items: end;
    flex-wrap: wrap;
}
.audit-filter-bar label { font-size: 0.75rem; font-weight: 600; color: #555; text-transform: uppercase; margin-bottom: 2px; }
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.pagination-controls .btn { font-size: 0.75rem; padding: 2px 10px; }

/* ===== Detail Panel Toggle Button ===== */
#btn-toggle-detail { padding: 2px 6px; line-height: 1; }
#btn-toggle-detail.active { background-color: var(--astral-primary); border-color: var(--astral-primary); color: #fff; }
#btn-toggle-detail.active:hover { background-color: var(--astral-dark); border-color: var(--astral-dark); }

/* ===== Draggable Modal ===== */
#app-modal .modal-header { cursor: move; user-select: none; }
#app-modal .modal-content { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); border: 1px solid #ccc; }
#app-modal.dragging .modal-dialog { transition: none; }
.modal-backdrop { background-color: rgba(0, 0, 0, 0.5) !important; }
.modal-backdrop.show { opacity: 1 !important; }

/* ===== Settings Modal ===== */
.settings-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1060;
    display: flex;
    align-items: center;
    justify-content: center;
}
.settings-modal {
    background: #fff;
    border-radius: 10px;
    width: 720px;
    max-width: 92vw;
    height: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}
.settings-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
}
.settings-modal-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e9ecef;
    padding: 0 20px;
    flex-shrink: 0;
    overflow: hidden;
}
.settings-tab {
    background: none;
    border: none;
    padding: 10px 16px;
    font-size: 0.8rem;
    font-weight: 500;
    color: #6c757d;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}
.settings-tab:hover { color: var(--astral-primary); }
.settings-tab.active {
    color: var(--astral-primary);
    border-bottom-color: var(--astral-primary);
}
.settings-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.settings-field-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.8rem;
}
.settings-field-row:last-child { border-bottom: none; }
.settings-field-label { width: 140px; flex-shrink: 0; font-size: 0.8rem; }
.settings-field-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.settings-field-modified { width: 120px; flex-shrink: 0; font-size: 0.7rem; color: #6c757d; text-align: right; }
.settings-field-action { width: 55px; flex-shrink: 0; text-align: right; }

/* ===== Navbar Settings Cog ===== */
#btn-settings:hover svg { fill: #fff; }
#btn-settings:focus { box-shadow: none; }

/* ===== 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);
}
