/* BaseApp admin theme — CSS variables up top so a forked project can
   re-skin the whole thing by editing this block only. */
:root {
    --ba-primary: #4f46e5;
    --ba-primary-dark: #4338ca;
    --ba-sidebar-bg: #111827;
    --ba-sidebar-bg-active: #1f2937;
    --ba-sidebar-text: #cbd5e1;
    --ba-sidebar-text-muted: #6b7280;
    --ba-topbar-bg: #ffffff;
    --ba-body-bg: #f3f4f6;
    --ba-card-bg: #ffffff;
    --ba-border: #e5e7eb;
    --ba-text: #1f2937;
    --ba-text-muted: #6b7280;
    --ba-hover-bg: #f8f9fa;
    --ba-radius: 0.6rem;
    --ba-sidebar-width: 250px;
    --ba-topbar-height: 58px;
}

/* Per-user Light/Dark preference (see api/controllers/AuthController.php::theme(),
   admin/includes/header.php -- data-bs-theme is rendered server-side from the
   session so there's no flash of the wrong theme on load). Bootstrap's own
   components (cards, tables, modals, forms, DataTables' bootstrap5 styling)
   already respond to data-bs-theme automatically; this block re-points every
   *custom* --ba-* variable and hardcoded color in this file so the whole
   shell -- topbar, body, footer, tree view, icon picker, everything below --
   switches too, not just Bootstrap's native pieces. */
[data-bs-theme="dark"] {
    --ba-topbar-bg: #1f2937;
    --ba-body-bg: #0f172a;
    --ba-card-bg: #1f2937;
    --ba-border: #374151;
    --ba-text: #e5e7eb;
    --ba-text-muted: #9ca3af;
    --ba-hover-bg: rgba(255, 255, 255, 0.05);
}

html, body {
    /* A centered flex container (.login-shell, etc.) drifts visibly off-center
       on narrow phones if anything inside it is even a pixel wider than the
       viewport -- the browser centers against the overflowed width, not the
       visible one. This is a safety net so that can never happen silently. */
    overflow-x: hidden;
}

body {
    background: var(--ba-body-bg);
    color: var(--ba-text);
    font-size: 0.925rem;
}

/* ---------- Shell layout ---------- */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--ba-topbar-height);
    background: var(--ba-topbar-bg);
    border-bottom: 1px solid var(--ba-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--ba-text);
    text-decoration: none;
    font-size: 1.05rem;
}

.topbar-brand i { color: var(--ba-primary); }

.topbar-logo {
    height: 28px;
    width: auto;
    max-width: 140px;
    object-fit: contain;
}

.topbar-spacer { flex: 1; }

.btn-topbar {
    background: transparent;
    border: none;
    color: var(--ba-text-muted);
}
.btn-topbar:hover { color: var(--ba-primary); }

.app-body {
    display: flex;
    flex: 1;
    min-height: calc(100vh - var(--ba-topbar-height));
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--ba-sidebar-width);
    background: var(--ba-sidebar-bg);
    flex-shrink: 0;
    overflow-y: auto;
    transition: margin-left 0.2s ease;
}

.sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 0.75rem 0;
}

.sidebar-menu .menu-heading {
    color: var(--ba-sidebar-text-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    padding: 0.75rem 1.1rem 0.35rem;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 1.1rem;
    color: var(--ba-sidebar-text);
    text-decoration: none;
    font-size: 0.875rem;
    border-radius: 0;
}

.sidebar-menu a i { width: 1.1rem; text-align: center; opacity: 0.85; }

.sidebar-menu a:hover { background: var(--ba-sidebar-bg-active); color: #fff; }

.sidebar-menu a.active {
    background: var(--ba-sidebar-bg-active);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--ba-primary);
}

.sidebar-menu .submenu a { padding-left: 2.5rem; font-size: 0.83rem; }

.sidebar-menu .submenu-toggle::after {
    content: "\f078";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    margin-left: auto;
    font-size: 0.65rem;
    transition: transform 0.15s ease;
}

.sidebar-menu li.open > .submenu-toggle::after { transform: rotate(180deg); }

.sidebar-menu .submenu { display: none; list-style: none; padding: 0; margin: 0; background: rgba(0,0,0,0.15); }
.sidebar-menu li.open > .submenu { display: block; }

body.sidebar-collapsed .sidebar { margin-left: calc(var(--ba-sidebar-width) * -1); }

@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: var(--ba-topbar-height); bottom: 0; z-index: 1040; margin-left: calc(var(--ba-sidebar-width) * -1); }
    body.sidebar-collapsed .sidebar { margin-left: 0; }
}

/* ---------- Content ---------- */
.content {
    flex: 1;
    padding: 1.5rem;
    min-width: 0;
}

/* ---------- Footer ----------
   Sits in normal document flow, after the page's own content -- scrolls
   with the page instead of staying pinned to the viewport. */
.app-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-top: 2rem;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--ba-border);
    font-size: 0.75rem;
    color: var(--ba-text-muted);
}

.app-footer-copyright {
    grid-column: 2;
    text-align: center;
}

.app-footer-meta {
    grid-column: 3;
    justify-self: end;
    font-size: 0.65rem;
    color: var(--ba-text-muted);
    opacity: 0.8;
}

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

.page-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
}

.page-header .breadcrumb { margin: 0.15rem 0 0; font-size: 0.8rem; }

/* ---------- Cards ---------- */
.card {
    border: 1px solid var(--ba-border);
    border-radius: var(--ba-radius);
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.card-header {
    background: var(--ba-card-bg);
    border-bottom: 1px solid var(--ba-border);
    font-weight: 600;
}

/* ---------- Stat / total cards ---------- */
.stat-card {
    border: 1px solid var(--ba-border);
    border-radius: var(--ba-radius);
    background: var(--ba-card-bg);
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #fff;
    flex-shrink: 0;
}

.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { color: var(--ba-text-muted); font-size: 0.8rem; }

/* Palette used for stat-icon backgrounds, matches app_dash_totals.color values */
.bg-purple { background: #7c3aed; }
.bg-blue   { background: #2563eb; }
.bg-green  { background: #16a34a; }
.bg-orange { background: #ea580c; }
.bg-red    { background: #dc2626; }
.bg-teal   { background: #0d9488; }

/* ---------- Buttons ---------- */
.btn-primary {
    background: var(--ba-primary);
    border-color: var(--ba-primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--ba-primary-dark);
    border-color: var(--ba-primary-dark);
}

/* ---------- Tables / DataTables tweaks ---------- */
table.dataTable { width: 100% !important; font-size: 0.875rem; }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select { border-radius: 0.4rem; border: 1px solid var(--ba-border); }
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--ba-primary) !important;
    border-color: var(--ba-primary) !important;
    color: #fff !important;
}

/* ---------- Icon picker grid ---------- */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 0.5rem; }
.icon-grid .icon-tile {
    border: 1px solid var(--ba-border);
    border-radius: 0.5rem;
    padding: 0.75rem 0.25rem;
    text-align: center;
    cursor: pointer;
    background: var(--ba-card-bg);
}
.icon-grid .icon-tile:hover { border-color: var(--ba-primary); color: var(--ba-primary); }
.icon-grid .icon-tile i { font-size: 1.25rem; display: block; margin-bottom: 0.35rem; }
.icon-grid .icon-tile .icon-name { font-size: 0.65rem; word-break: break-all; color: var(--ba-text-muted); }

/* ---------- DataTable export toolbar (icon-only, compact) ---------- */
.dt-export-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    line-height: 1;
}

/* ---------- Misc ---------- */
.login-shell {
    min-height: 100vh;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    background: linear-gradient(135deg, var(--ba-primary) 0%, #111827 100%);
}
.login-card { width: 100%; max-width: 380px; border-radius: var(--ba-radius); border: none; box-sizing: border-box; }
.required::after { content: " *"; color: #dc2626; }

/* ---------- Menu tree (modules.php) ---------- */
.tree-row:hover { background: var(--ba-hover-bg); }
.tree-drag-handle { cursor: grab; opacity: 0.4; }
.tree-drag-handle:hover { opacity: 1; }
.tree-row:active .tree-drag-handle { cursor: grabbing; }
.ui-sortable-helper { background: var(--ba-card-bg); box-shadow: 0 2px 8px rgba(0,0,0,0.15); border-radius: 0.35rem; }
.tree-drag-placeholder {
    background: var(--ba-primary);
    opacity: 0.15;
    border: 1px dashed var(--ba-primary);
    border-radius: 0.35rem;
    height: 2rem;
    margin-bottom: 0.25rem;
}
