:root {
    /* Base Modern Black Dark Palette */
    --bg-main: #000000;
    --bg-canvas: #09090b;
    --bg-surface: #121214;
    --bg-surface-elevated: #1a1a1e;
    --bg-surface-hover: #222228;
    --bg-header: #0c0c0e;
    
    /* Borders */
    --border-color: #27272a;
    --border-light: #3f3f46;
    --border-subtle: #1c1c20;
    
    /* Typography */
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --text-inverse: #09090b;
    
    /* Accent & Brand */
    --accent: #38bdf8;
    --accent-hover: #0ea5e9;
    --accent-subtle: rgba(56, 189, 248, 0.12);
    --accent-glow: rgba(56, 189, 248, 0.25);
    
    /* Status Colors */
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --success-border: rgba(34, 197, 94, 0.25);
    --success-text: #4ade80;
    
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --danger-border: rgba(239, 68, 68, 0.25);
    --danger-text: #f87171;
    
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --warning-border: rgba(245, 158, 11, 0.25);
    --warning-text: #fbbf24;
    
    --info: #06b6d4;
    --info-bg: rgba(6, 182, 212, 0.12);
    --info-border: rgba(6, 182, 212, 0.25);
    --info-text: #38bdf8;
    
    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.6);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.85);
    --shadow-card: 0 0 0 1px var(--border-color), 0 4px 20px -2px rgba(0, 0, 0, 0.7);
}

/* Global Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color-scheme: dark;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: #27272a;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3f3f46;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #27272a var(--bg-main);
}

/* Code & Preformatted Text */
code, pre, kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.84em;
    background-color: #18181b;
    color: var(--accent);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--accent-hover);
}

/* Layout */
.page {
    position: relative;
    display: flex;
    min-height: 100vh;
    background-color: var(--bg-main);
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--bg-header);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar .top-row {
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.25rem;
}

.navbar-brand {
    color: #ffffff;
    text-decoration: none;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    padding: 1rem 0;
    display: flex;
    align-items: center;
}

.navbar-brand strong {
    background: linear-gradient(135deg, #ffffff 0%, #a1a1aa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-scrollable {
    overflow-y: auto;
    flex-grow: 1;
    padding: 0.75rem 0;
}

.nav-item {
    margin: 3px 10px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
    transition: all 0.15s ease;
}

.nav-link:hover {
    background-color: var(--bg-surface-elevated);
    color: #ffffff;
    border-color: var(--border-color);
}

.nav-link.active {
    background-color: var(--bg-surface-hover);
    color: var(--accent);
    font-weight: 600;
    border-color: rgba(56, 189, 248, 0.3);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.1);
}

.nav-icon {
    font-size: 1.1rem;
    width: 20px;
    display: inline-block;
    text-align: center;
    opacity: 0.9;
}

/* Main Area */
main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background-color: var(--bg-main);
}

.top-row {
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
}

.app-title {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #ffffff;
}

.system-badge {
    font-size: 0.78rem;
    background-color: var(--bg-surface-elevated);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    font-weight: 500;
}

.content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background-color: var(--bg-main);
}

/* Master Detail Containers */
.master-detail-container {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 1.5rem;
    min-height: calc(100vh - 120px);
}

@media (max-width: 1024px) {
    .master-detail-container {
        grid-template-columns: 1fr;
    }
}

.master-pane, .detail-pane {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.pane-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: rgba(255, 255, 255, 0.02);
}

.pane-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
    color: #ffffff;
    letter-spacing: -0.01em;
}

.pane-body {
    padding: 1.25rem;
    flex-grow: 1;
    overflow-y: auto;
}

/* Cards */
.card-panel {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

/* Custom Table */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    margin-bottom: 0;
}

.custom-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: #16161a;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.custom-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
}

.custom-table tbody tr.table-row {
    cursor: pointer;
    background-color: transparent;
    transition: background-color 0.12s ease;
}

.custom-table tbody tr.table-row:hover {
    background-color: var(--bg-surface-elevated);
}

.custom-table tbody tr.table-row.selected {
    background-color: var(--accent-subtle);
    border-left: 3px solid var(--accent);
}

.custom-table tbody tr:last-child td {
    border-bottom: none;
}

/* Property Table for Master Entity Properties in Detail Views */
.property-table {
    width: 100%;
    max-width: 650px;
    border-collapse: collapse;
    margin-top: 0.5rem;
    font-size: 0.88rem;
}

.property-table tr {
    border-bottom: 1px solid var(--border-subtle);
}

.property-table tr:last-child {
    border-bottom: none;
}

.property-table th {
    width: 160px;
    padding: 8px 14px 8px 0;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

.property-table td {
    padding: 8px 0;
    color: var(--text-primary);
    vertical-align: middle;
}

/* Tabs */
.tabs-header {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background-color: #0c0c0e;
    overflow-x: auto;
}

.tab-btn {
    padding: 12px 18px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-btn:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
    background-color: var(--accent-subtle);
}

.tab-count {
    background-color: var(--bg-surface-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 2px 7px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.tab-content {
    padding: 1.25rem;
}

/* Forms & Inputs */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.search-box input {
    width: 100%;
    padding: 9px 36px 9px 36px;
    background-color: #0c0c0e;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: #ffffff;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
    font-size: 0.85rem;
}

.btn-clear {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    transition: color 0.15s ease;
}

.btn-clear:hover {
    color: #ffffff;
}

.form-control, .form-select {
    background-color: #0c0c0e;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: #ffffff;
    padding: 9px 12px;
    font-size: 0.88rem;
    outline: none;
    width: 100%;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.form-select option {
    background-color: #121214;
    color: #ffffff;
}

/* Buttons */
.btn-primary {
    background-color: #0284c7;
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary:hover {
    background-color: #0369a1;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background-color: var(--bg-surface-elevated);
    color: #ffffff;
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-secondary:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--border-light);
    color: #ffffff;
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.3;
}

.badge-success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}

.badge-danger {
    background-color: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid var(--danger-border);
}

.badge-warning {
    background-color: var(--warning-bg);
    color: var(--warning-text);
    border: 1px solid var(--warning-border);
}

.badge-info {
    background-color: var(--info-bg);
    color: var(--info-text);
    border: 1px solid var(--info-border);
}

.badge-secondary {
    background-color: rgba(113, 113, 122, 0.15);
    color: var(--text-secondary);
    border: 1px solid rgba(113, 113, 122, 0.3);
}

/* Sub-panel drawer */
.sub-panel {
    background-color: #0c0c0e;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-top: 1rem;
}

.sub-panel-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Login Window Styles */
.login-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, #18181c 0%, #000000 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1.5rem;
}

.login-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.03);
    width: 100%;
    max-width: 420px;
    padding: 2.5rem 2rem;
}

.login-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
}

.login-subtitle {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.login-submit-btn {
    padding: 11px 16px;
    font-size: 0.95rem;
    font-weight: 600;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.alert-danger {
    background-color: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger-text);
}

.alert-icon {
    font-size: 1rem;
    line-height: 1;
}

/* Spinners */
.spinner-border {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    vertical-align: -0.125em;
    border: 0.2em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

.spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

@keyframes spinner-border {
    to {
        transform: rotate(360deg);
    }
}

/* Helpers & Utility Classes */
.d-flex { display: flex !important; }
.flex-column { flex-direction: column !important; }
.flex-wrap { flex-wrap: wrap !important; }
.align-items-center { align-items: center !important; }
.align-items-start { align-items: flex-start !important; }
.align-items-end { align-items: flex-end !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-center { justify-content: center !important; }

.gap-1 { gap: 0.25rem !important; }
.gap-2 { gap: 0.5rem !important; }
.gap-3 { gap: 1rem !important; }

.m-0 { margin: 0 !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-1 { margin-top: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }

.p-0 { padding: 0 !important; }
.p-3 { padding: 1rem !important; }
.p-4 { padding: 1.5rem !important; }
.py-3 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.py-5 { padding-top: 3rem !important; padding-bottom: 3rem !important; }
.px-3 { padding-left: 1rem !important; padding-right: 1rem !important; }
.px-4 { padding-left: 1.5rem !important; padding-right: 1.5rem !important; }
.ps-3 { padding-left: 1rem !important; }
.me-2 { margin-right: 0.5rem !important; }

.w-100 { width: 100% !important; }
.text-nowrap { white-space: nowrap !important; }
.text-center { text-align: center !important; }
.text-decoration-none { text-decoration: none !important; }

.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-light { color: #ffffff !important; }
.text-danger { color: var(--danger-text) !important; }
.text-info { color: var(--info-text) !important; }
.text-warning { color: var(--warning-text) !important; }
.text-success { color: var(--success-text) !important; }

.border-bottom { border-bottom: 1px solid var(--border-color) !important; }
.border-light { border-color: var(--border-color) !important; }

.small { font-size: 0.82rem !important; }
.fs-1 { font-size: 2.5rem !important; }

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Modals */
.modal-backdrop-custom {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-dialog-custom {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    overflow: hidden;
}
