:root {
    --trex-navy: #1557b0;
    --trex-navy-2: #104a9a;
    --trex-ink: #1e293b;
    --trex-accent: #1a73e8;
    --trex-accent-hot: #1557b0;
    --trex-accent-2: #e8f0fe;
    --trex-surface: #f8f9fa;
    --trex-card: #ffffff;
    --trex-border: #e5e7eb;
    --trex-muted: #5f6368;
    --trex-sidebar-w: 240px;
}

body.trex-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    color: #1e293b;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Top nav */
.trex-topnav {
    background: #000;
    box-shadow: 0 2px 12px rgba(26, 115, 232, 0.18);
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
}

.trex-topnav .navbar-brand {
    color: #fff !important;
    letter-spacing: 0.2px;
}

.trex-topnav .navbar-brand i {
    color: #93c5fd;
}

.trex-topnav .nav-link {
    color: rgba(255, 255, 255, 0.78) !important;
    border-radius: 0.4rem;
    padding: 0.4rem 0.75rem !important;
}

.trex-topnav .nav-link:hover,
.trex-topnav .nav-link:focus {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.08);
}

.trex-topnav .dropdown-menu {
    border: 0;
    box-shadow: 0 10px 30px rgba(28, 25, 23, 0.16);
    border-radius: 0.65rem;
}

.btn-trex-accent {
    background: var(--trex-accent);
    border-color: var(--trex-accent);
    color: #fff;
    font-weight: 600;
}

.btn-trex-accent:hover {
    background: var(--trex-accent-hot);
    border-color: var(--trex-accent-hot);
    color: #fff;
}

/* App shell with sidebar */
.trex-app {
    display: flex;
    align-items: stretch;
    flex: 1 0 auto;
    min-height: 0;
}

.trex-sidebar {
    width: var(--trex-sidebar-w);
    flex-shrink: 0;
    background: #000;
    color: #fff;
    min-height: calc(100vh - 56px);
    position: sticky;
    top: 56px;
    align-self: flex-start;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.trex-sidebar-nav {
    padding: 1rem 0.75rem 1.5rem;
    gap: 0.15rem;
}

.trex-sidebar-label {
    margin: 1rem 0.65rem 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
}

.trex-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: rgba(255, 255, 255, 0.72);
    border-radius: 0.5rem;
    padding: 0.55rem 0.75rem;
    font-size: 0.92rem;
}

.trex-sidebar .nav-link i {
    font-size: 1.05rem;
    opacity: 0.9;
    width: 1.15rem;
    text-align: center;
}

.trex-sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.07);
}

.trex-sidebar .nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: inset 3px 0 0 #fff;
}

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

.trex-main-solo {
    flex: 1 0 auto;
}

.trex-footer {
    margin-top: auto;
    padding: 1rem 0;
    color: var(--trex-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--trex-border);
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(6px);
}

.footer-patch code {
    color: var(--trex-muted);
    background: #eef2f7;
    padding: 0.15rem 0.45rem;
    border-radius: 0.35rem;
    font-size: 0.8rem;
}

/* Cards / surfaces used across pages */
.admin-page,
.dashboard,
.auth-form,
.card-block,
.patch-summary,
.ticket-meta,
.ticket-description,
.stat-card {
    background: var(--trex-card);
    border: 1px solid var(--trex-border);
    border-radius: 0.85rem;
    box-shadow: 0 8px 24px rgba(28, 25, 23, 0.05);
}

.admin-page {
    padding: 1.25rem 1.35rem 1.5rem;
    overflow-x: auto;
}

.dashboard {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem 1.6rem;
}

.dashboard-info p {
    margin-bottom: 0.55rem;
    padding-bottom: 0.55rem;
    border-bottom: 1px solid var(--trex-border);
}

.dashboard-info p:last-child {
    border-bottom: 0;
    margin-bottom: 0;
    padding-bottom: 0;
}

.auth-form {
    max-width: 420px;
    margin: 2rem auto;
    padding: 2rem 1.75rem;
}

.auth-form h1 {
    text-align: center;
    margin-bottom: 1.25rem;
    font-size: 1.6rem;
    color: var(--trex-ink);
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.page-header h1 {
    margin: 0;
    font-size: 1.55rem;
    color: var(--trex-ink);
    font-weight: 700;
}

h1, h2, h3 {
    color: var(--trex-ink);
}

/* Forms — keep existing .form-group markup working */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: #334155;
}

.form-group input,
.form-group select,
.form-group textarea,
.filter-select,
.filter-input {
    display: block;
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-size: 0.95rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.filter-select:focus,
.filter-input:focus {
    outline: 0;
    border-color: var(--trex-accent);
    box-shadow: 0 0 0 0.2rem rgba(23, 93, 220, 0.18);
}

.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 140px;
}

.form-actions {
    display: flex;
    gap: 0.65rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.checkbox-label {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    border-radius: 0.5rem;
    font-weight: 600;
}

.btn-primary {
    --bs-btn-bg: var(--trex-accent);
    --bs-btn-border-color: var(--trex-accent);
    --bs-btn-hover-bg: #1252b0;
    --bs-btn-hover-border-color: #1252b0;
    --bs-btn-active-bg: #0e4290;
    --bs-btn-active-border-color: #0e4290;
    background: var(--trex-accent);
    border-color: var(--trex-accent);
    color: #fff;
}

.btn-primary:hover,
.btn-primary:focus {
    background: #1252b0;
    border-color: #1252b0;
    color: #fff;
}

.btn-small,
.btn-sm.btn-small {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    background: #dbeafe;
    color: #1252b0;
    border: 1px solid #bfdbfe;
}

.btn-small:hover {
    background: #bfdbfe;
    color: #1e3a5f;
}

.btn-danger {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
}

.btn-danger:hover {
    background: #bb2d3b;
    border-color: #b02a37;
    color: #fff;
}

/* Tables */
.table {
    --bs-table-bg: #fff;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border-radius: 0.75rem;
    border: 1px solid var(--trex-border);
    background: #fff;
}

.table thead th {
    background: var(--trex-navy) !important;
    color: #fff !important;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 650;
    border: 0 !important;
    border-bottom: 2px solid var(--trex-accent) !important;
    padding: 0.85rem 1rem;
    white-space: nowrap;
}

.table td {
    padding: 0.8rem 1rem;
    vertical-align: middle;
    border-color: #edf2f7 !important;
}

.table-hover tbody tr:hover {
    background: #f8fafc;
}

/* Alerts / badges */
.alert {
    border-radius: 0.65rem;
    border: 0;
}

.alert-danger {
    background: #fde8ea;
    color: #9b1c2c;
}

.alert-success {
    background: #e6f6ed;
    color: #146c43;
}

.alert-warning {
    background: #fff6e0;
    color: #8a5a00;
}

.badge {
    display: inline-block;
    padding: 0.3em 0.65em;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-low { background: #e2e8f0; color: #475569; }
.badge-medium { background: #fff3cd; color: #856404; }
.badge-high { background: #ffe0cc; color: #b54708; }
.badge-urgent { background: #f8d7da; color: #b02a37; }
.badge-status { background: #d7f1f6; color: #0c5460; }
.badge-success { background: #d1e7dd; color: #0f5132; }
.badge-secondary { background: #e9ecef; color: #495057; }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.9rem;
    margin-bottom: 1.25rem;
}

.auth-form .display-6,
.auth-form .text-primary {
    color: var(--trex-accent) !important;
}

.stat-card {
    border-top: 3px solid var(--trex-accent-2);
    padding: 1.15rem 1rem;
    text-align: center;
}

.stat-card:nth-child(2) {
    border-top-color: #2b80e5;
}

.stat-card:nth-child(3) {
    border-top-color: var(--trex-accent);
}

.stat-card:nth-child(4) {
    border-top-color: var(--trex-muted);
}

.stat-number {
    font-size: 1.85rem;
    font-weight: 750;
    color: var(--trex-ink);
    line-height: 1.1;
}

.stat-number.stat-urgent { color: #c1121f; }
.stat-number.stat-high { color: #d9480f; }

.stat-label {
    margin-top: 0.35rem;
    font-size: 0.72rem;
    color: var(--trex-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 650;
}

/* Ticket / misc legacy */
.filter-bar {
    display: flex;
    gap: 0.65rem;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

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

.ticket-meta {
    padding: 1rem 1.15rem;
    margin-bottom: 1rem;
    background: #f8fafc;
}

.ticket-description {
    padding: 1rem 1.15rem;
}

.attachment-list {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: 0.5rem;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-top: 0.4rem;
}

.attachment-thumb {
    max-width: 150px;
    max-height: 100px;
    border-radius: 0.4rem;
    border: 1px solid var(--trex-border);
}

.attachment-link {
    color: var(--trex-ink);
}

.error-page {
    text-align: center;
    padding: 5rem 1rem;
}

.error-page h1 {
    font-size: 4rem;
    color: #cbd5e1;
}

/* Patch manager */
.patch-summary {
    display: flex;
    justify-content: space-between;
    gap: 1.25rem;
    padding: 1.2rem 1.35rem;
    margin-bottom: 1.25rem;
}

.patch-label {
    font-size: 1.45rem;
    font-weight: 750;
    color: var(--trex-ink);
}

.patch-grid {
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 1.1rem;
}

.card-block {
    padding: 1.15rem 1.25rem;
    margin-bottom: 1.1rem;
}

.card-block h2 {
    font-size: 1.05rem;
    margin-bottom: 0.85rem;
    font-weight: 700;
}

.card-block h3 {
    font-size: 0.95rem;
    margin: 0.85rem 0 0.5rem;
}

.patch-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.patch-list li {
    margin-bottom: 0.65rem;
    font-size: 0.9rem;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.85rem;
}

.text-muted { color: var(--trex-muted) !important; }
.small { font-size: 0.85rem; }
.text-end { text-align: right; }
.text-nowrap { white-space: nowrap; }

/* ===== Dark mode ===== */
body.dark,
body.dark .trex-topnav,
body.dark .trex-topnav .dropdown-menu {
    --trex-ink: #e1e4e8;
    --trex-card: #1c1e26;
    --trex-border: #2d3139;
    --trex-muted: #9ca3af;
}

body.dark {
    background: #121317;
    color: #e1e4e8;
}

body.dark .trex-topnav {
    background: #121317;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

body.dark .trex-sidebar {
    background: #0c0d10;
    border-right-color: #2d3139;
}

body.dark .trex-footer {
    background: #121317;
    border-top-color: #2d3139;
}

body.dark .footer-patch code {
    background: #2d3139;
    color: #9ca3af;
}

body.dark .trex-topnav .dropdown-menu {
    background: #1c1e26;
    border: 1px solid #2d3139;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

body.dark .admin-page,
body.dark .dashboard,
body.dark .auth-form,
body.dark .card-block,
body.dark .patch-summary,
body.dark .ticket-meta,
body.dark .ticket-description,
body.dark .stat-card {
    background: #1c1e26;
    border-color: #2d3139;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

body.dark h1, body.dark h2, body.dark h3 {
    color: #e1e4e8;
}

body.dark .auth-form h1,
body.dark .page-header h1,
body.dark .patch-label,
body.dark .stat-number,
body.dark .attachment-link {
    color: #e1e4e8;
}

body.dark .form-group label {
    color: #c9cdd3;
}

body.dark .form-group input,
body.dark .form-group select,
body.dark .form-group textarea,
body.dark .filter-select,
body.dark .filter-input {
    background: #25272e;
    border-color: #3b3e47;
    color: #e1e4e8;
}

body.dark .form-group input:focus,
body.dark .form-group select:focus,
body.dark .form-group textarea:focus,
body.dark .filter-select:focus,
body.dark .filter-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(26, 115, 232, 0.35);
}

body.dark .table {
    --bs-table-bg: #1c1e26;
    background: #1c1e26;
    border-color: #2d3139;
}

body.dark .table td {
    border-color: #2d3139 !important;
    color: #d1d5db;
}

body.dark .table-hover tbody tr:hover {
    background: #25272e;
}

body.dark .alert-danger {
    background: #3b1219;
    color: #fca5a5;
}

body.dark .alert-success {
    background: #0d2818;
    color: #86efac;
}

body.dark .alert-warning {
    background: #3b2e0a;
    color: #fde68a;
}

body.dark .badge-low { background: #374151; color: #9ca3af; }
body.dark .badge-medium { background: #422006; color: #fbbf24; }
body.dark .badge-high { background: #431407; color: #fb923c; }
body.dark .badge-urgent { background: #450a0a; color: #fca5a5; }
body.dark .badge-status { background: #0c2d48; color: #67e8f9; }
body.dark .badge-success { background: #052e16; color: #86efac; }
body.dark .badge-secondary { background: #374151; color: #d1d5db; }

body.dark .btn-small,
body.dark .btn-sm.btn-small {
    background: #1e3a5f;
    color: #93c5fd;
    border-color: #2563eb33;
}

body.dark .btn-small:hover {
    background: #1e40af;
    color: #bfdbfe;
}

body.dark .ticket-meta,
body.dark .attachment-list {
    background: #25272e;
}

body.dark .ticket-message {
    background: #25272e;
}

body.dark .message-date {
    color: #6b7280;
}

body.dark .error-page h1 {
    color: #4b5563;
}

body.dark .dashboard-info p {
    border-bottom-color: #2d3139;
}

body.dark .attachment-thumb {
    border-color: #3b3e47;
}

body.dark .stat-card:nth-child(2) {
    border-top-color: #60a5fa;
}

body.dark .stat-card:nth-child(3) {
    border-top-color: #1a73e8;
}

body.dark .stat-card:nth-child(4) {
    border-top-color: #6b7280;
}

body.dark .stat-number.stat-urgent { color: #fca5a5; }
body.dark .stat-number.stat-high { color: #fb923c; }

body.dark .theme-toggle {
    color: rgba(255, 255, 255, 0.78);
}

body.dark .theme-toggle:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.theme-toggle {
    background: none;
    border: 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: 1.1rem;
    padding: 0.4rem 0.6rem;
    border-radius: 0.4rem;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    line-height: 1;
}

.theme-toggle:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

/* Inline styles in PHP templates */
body.dark .ticket-description[style*="background"],
body.dark [style*="background: #f9f9f9"],
body.dark [style*="background:#f9f9f9"],
body.dark [style*="background: #fafafa"],
body.dark [style*="background:#fafafa"],
body.dark [style*="background:#f0f0f0"],
body.dark [style*="background: #f0f0f0"] {
    background: #25272e !important;
}

body.dark [style*="color: #666"] {
    color: #9ca3af !important;
}

body.dark [style*="color: #999"] {
    color: #6b7280 !important;
}

body.dark .pre,
body.dark pre {
    background: #25272e;
}

/* Wider content when sidebar present */
.has-sidebar .trex-main .container-fluid {
    max-width: 1400px;
}

@media (max-width: 991.98px) {
    .trex-app {
        flex-direction: column;
    }

    .trex-sidebar {
        width: 100%;
        position: static;
        max-height: none;
        min-height: 0;
        border-right: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    .trex-sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0.65rem;
    }

    .trex-sidebar-label {
        display: none;
    }

    .trex-sidebar .nav-link {
        padding: 0.4rem 0.7rem;
        font-size: 0.85rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .patch-grid {
        grid-template-columns: 1fr;
    }

    .patch-summary {
        flex-direction: column;
    }

    .text-end {
        text-align: left;
    }
}

@media (max-width: 575.98px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}
