/* ==============================================
   Business Engine - Core Stylesheet
   Uses CSS variables for theming.
   ============================================== */

:root {
    --primary: #1a1a2e;
    --secondary: #16213e;
    --accent: #0f3460;
    --text: #e0e0e0;
    --sidebar-bg: #1a1a2e;
    --topbar-bg: #16213e;
    --danger: #e94560;
    --success: #27ae60;
    --warning: #f39c12;
    --info: #3498db;
    --light: #f5f5f5;
    --dark: #333;
    --border: #2a2a4a;
    --card-bg: #fff;
    --body-bg: #f0f2f5;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 60px;
    --submenu-width: 220px;
    --topbar-height: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--body-bg);
    color: var(--dark);
    line-height: 1.6;
    font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Auth Pages ---- */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
}
.auth-card {
    background: #fff;
    border-radius: 8px;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.auth-card h1 { text-align: center; margin-bottom: 1.5rem; color: var(--primary); font-size: 1.5rem; }
.auth-card .logo { text-align: center; margin-bottom: 1rem; }
.auth-card .logo img { max-height: 60px; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--text);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    transition: width 0.3s ease;
    z-index: 100;
    display: flex;
    flex-direction: column;
}
.sidebar.collapsed { width: var(--sidebar-collapsed-width); }
.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .section-header .section-label,
.sidebar.collapsed .menu-item-label { display: none; }

.sidebar-header {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border);
    min-height: var(--topbar-height);
}
.sidebar-header img { max-height: 32px; }
.sidebar-header .sidebar-title { font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; }

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0.5rem;
    font-size: 1.2rem;
    margin-left: auto;
}

.sidebar-nav { flex: 1; padding: 0.5rem 0; overflow-y: auto; min-height: 0; }

.section-header {
    padding: 0.75rem 1rem 0.25rem;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.section-header .section-icon { width: 20px; text-align: center; flex-shrink: 0; }
.section-header:hover { color: rgba(255,255,255,0.85); }
.section-header-link { text-decoration: none; }
.section-header-link.active { background: var(--accent); color: #fff; }
.section-header-link.active:hover { color: #fff; }

.menu-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem 0.5rem 1.5rem;
    color: var(--text);
    transition: background 0.2s;
    gap: 0.5rem;
}
.menu-item:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.menu-item.active { background: var(--accent); }
.menu-item .menu-icon { width: 20px; text-align: center; flex-shrink: 0; }

/* Main content area */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease, max-width 0.3s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden;
}
.sidebar.collapsed ~ .main-wrapper {
    margin-left: var(--sidebar-collapsed-width);
    max-width: calc(100vw - var(--sidebar-collapsed-width));
}

/* Top bar */
.topbar {
    background: var(--topbar-bg);
    color: var(--text);
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 90;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.topbar-left { display: flex; align-items: center; gap: 1rem; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 1rem; margin-left: auto; flex-shrink: 0; }

.topbar a { color: var(--text); }
.topbar a:hover { color: #fff; text-decoration: none; }

.topbar .topbar-link {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
}
.topbar .topbar-link:hover { background: rgba(255,255,255,0.1); }

/* Breadcrumb navigation */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    min-width: 0;
    overflow: hidden;
}
.breadcrumb-item {
    color: rgba(255,255,255,0.65);
    white-space: nowrap;
    transition: color 0.2s;
}
.breadcrumb-item:hover {
    color: #fff;
    text-decoration: none;
}
.breadcrumb-separator {
    color: rgba(255,255,255,0.3);
    font-size: 0.7rem;
    flex-shrink: 0;
}
.breadcrumb-current {
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar .user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.topbar .user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
}

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

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.page-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}
.page-header h1 { font-size: 1.5rem; color: var(--primary); }
.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #6c757d;
    background: transparent;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-back:hover {
    background: #f0f2f5;
    color: var(--primary);
    border-color: #aaa;
    text-decoration: none;
}

/* ---- Cards ---- */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card-header { font-weight: 600; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid #eee; }

/* ---- Stats Grid ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-card .stat-label { font-size: 0.85rem; color: #777; }

/* ---- Tables ---- */
.table-container { overflow-x: auto; max-width: 100%; }
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
th, td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid #eee; white-space: nowrap; }
th { background: #f8f9fa; font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: #555; }
tr:hover { background: #f5f7fa; }
tr:last-child td { border-bottom: none; }

/* ---- Forms ---- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 600; font-size: 0.85rem; color: #555; }
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}
.form-control:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(15,52,96,0.1); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    text-decoration: none;
    color: #fff;
}
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn-primary { background: var(--accent); }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-warning { background: var(--warning); color: #333; }
.btn-secondary { background: #6c757d; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.btn-outline { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.btn-outline:hover { background: var(--accent); color: #fff; }

/* ---- Alerts ---- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-success { background: var(--success); color: #fff; }
.badge-danger { background: var(--danger); color: #fff; }
.badge-warning { background: var(--warning); color: #333; }
.badge-info { background: var(--info); color: #fff; }
.badge-secondary { background: #6c757d; color: #fff; }

/* ---- Pagination ---- */
.pagination { display: flex; gap: 0.25rem; margin-top: 1rem; }
.pagination a, .pagination span {
    padding: 0.4rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.85rem;
}
.pagination a:hover { background: #f0f0f0; text-decoration: none; }
.pagination .active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- Color Picker ---- */
input[type="color"] { width: 60px; height: 36px; padding: 2px; cursor: pointer; }
.color-group { display: flex; align-items: center; gap: 0.75rem; }
.color-group .color-label { min-width: 120px; }

/* ---- Checkbox group ---- */
.checkbox-group { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.5rem; }
.checkbox-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0; }
.checkbox-item input[type="checkbox"] { width: 16px; height: 16px; }

/* ---- Plugin cards ---- */
.plugin-card { border: 1px solid #eee; border-radius: 8px; padding: 1.25rem; margin-bottom: 1rem; }
.plugin-card.enabled { border-left: 4px solid var(--success); }
.plugin-card.disabled { border-left: 4px solid #ccc; }
.plugin-meta { display: flex; gap: 1rem; flex-wrap: wrap; margin: 0.5rem 0; font-size: 0.85rem; color: #777; }
.plugin-actions { margin-top: 0.75rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---- Form Helpers ---- */
.form-help { font-size: 0.8rem; color: #777; margin-top: 0.25rem; }
.form-control-sm { max-width: 200px; }
.form-control-md { max-width: 400px; }

/* ---- Button / Action Groups ---- */
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-group-sm { display: flex; gap: 0.25rem; flex-wrap: wrap; }

/* ---- Detail Grid (read-only key/value display) ---- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1.5rem; margin-bottom: 1.25rem; }
.detail-item { }
.detail-label { font-size: 0.75rem; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }
.detail-value { font-weight: 500; }

/* ---- Utility ---- */
.text-muted { color: #777; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.hidden { display: none; }

/* Animated section collapse/expand */
.section-items {
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}
.section-items.collapsed {
    max-height: 0;
    opacity: 0;
}

/* ---- Core Table Filters ---- */
.core-table-filters { display: flex; flex-direction: column; gap: 0.75rem; }
.filter-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.filter-search { flex: 1; max-width: 400px; min-width: 200px; }
.filter-search .form-control { margin: 0; }

/* Collapsible column filter panel */
.column-filters-panel { border-top: 1px solid #eee; padding-top: 0.75rem; margin-top: 0.25rem; }
.column-filters-toggle { white-space: nowrap; }

/* Filter table: label | input, aligned rows */
.column-filters-table {
    width: auto;
    border-collapse: collapse;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
    margin: 0;
}
.column-filters-table tr:hover { background: transparent; }
.column-filters-table td {
    padding: 0.2rem 0.5rem;
    border-bottom: none;
    white-space: nowrap;
    vertical-align: middle;
}
.column-filter-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    text-align: right;
    padding-right: 0.75rem !important;
    width: 1%;
}
.column-filter-input { width: 280px; }
.column-filter-input .form-control {
    padding: 0.3rem 0.5rem;
    font-size: 0.82rem;
    width: 100%;
}
.column-filters-actions { padding-top: 0.5rem; }

/* Sort headers in tables */
.sort-header {
    color: #555;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}
.sort-header:hover { color: var(--accent); text-decoration: none; }
.sort-header.sorted { color: var(--accent); font-weight: 700; }
.sort-indicator { font-size: 0.7rem; }

/* Results info line */
.results-info { font-size: 0.85rem; }

/* ---- Searchable Select ---- */
.searchable-select-wrapper { position: relative; }
.searchable-select-wrapper .searchable-select-search {
    margin-bottom: 0.25rem;
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 100%;
}
.searchable-select-wrapper .searchable-select-search:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(15,52,96,0.1);
}
.searchable-select-wrapper select.form-control {
    width: 100%;
}

/* ---- Submenu Sidebar (Secondary Navigation Panel) ---- */
.menu-item.has-submenu { position: relative; }
.menu-item.has-submenu .submenu-arrow {
    margin-left: auto;
    font-size: 0.7rem;
    opacity: 0.5;
    transition: opacity 0.2s;
}
.menu-item.has-submenu:hover .submenu-arrow,
.menu-item.has-submenu.submenu-active .submenu-arrow { opacity: 1; }
.menu-item.has-submenu.submenu-active { background: rgba(255,255,255,0.12); }

/* The secondary sidebar panel */
.submenu-sidebar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    width: var(--submenu-width);
    height: 100vh;
    background: var(--secondary);
    border-right: 1px solid var(--border);
    z-index: 99;
    overflow-y: auto;
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s ease, left 0.3s ease;
}
.submenu-sidebar.open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

/* Shift when primary sidebar is collapsed */
.sidebar.collapsed ~ .submenu-sidebar { left: var(--sidebar-collapsed-width); }

/* Submenu content blocks — only the active one is shown */
.submenu-content { display: none; }
.submenu-content.active { display: block; }

/* Submenu header with title and close button */
.submenu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    min-height: var(--topbar-height);
    border-bottom: 1px solid var(--border);
}
.submenu-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255,255,255,0.5);
}
.submenu-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.4);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.submenu-close:hover { color: #fff; background: rgba(255,255,255,0.1); }

.submenu-nav { padding: 0.5rem 0; }

/* Submenu navigation items */
.submenu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    color: var(--text);
    font-size: 0.85rem;
    transition: background 0.15s;
    white-space: nowrap;
}
.submenu-item:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.submenu-item.active { background: var(--accent); color: #fff; }
.submenu-icon { width: 18px; text-align: center; flex-shrink: 0; font-size: 0.9rem; }

/* Main wrapper shifts when submenu is open */
.main-wrapper.has-submenu {
    margin-left: calc(var(--sidebar-width) + var(--submenu-width));
    max-width: calc(100vw - var(--sidebar-width) - var(--submenu-width));
}
.sidebar.collapsed ~ .submenu-sidebar.open ~ .main-wrapper.has-submenu {
    margin-left: calc(var(--sidebar-collapsed-width) + var(--submenu-width));
    max-width: calc(100vw - var(--sidebar-collapsed-width) - var(--submenu-width));
}

/* ---- Core Table Builder ---- */
.builder-field-list { display: flex; flex-direction: column; gap: 0.75rem; }

.builder-field-card {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 1rem;
    background: #fafbfc;
    position: relative;
    transition: box-shadow 0.2s, border-color 0.2s;
}
.builder-field-card:hover { border-color: #bbb; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.builder-field-card.dragging { opacity: 0.5; border-style: dashed; }
.builder-field-card.drag-over { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(15,52,96,0.2); }
.builder-field-card.is-pk {
    background: #f0f4f8;
    border-left: 3px solid var(--accent);
}

.builder-field-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.builder-drag-handle {
    cursor: grab;
    color: #aaa;
    font-size: 1.1rem;
    padding: 0.25rem;
    user-select: none;
    flex-shrink: 0;
}
.builder-drag-handle:active { cursor: grabbing; }
.builder-field-title {
    font-weight: 600;
    font-size: 0.9rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.builder-field-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    background: var(--accent);
    color: #fff;
    flex-shrink: 0;
}
.builder-field-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    flex-shrink: 0;
    transition: background 0.15s;
}
.builder-field-remove:hover { background: rgba(233,69,96,0.1); }

.builder-field-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.builder-field-body .full-width { grid-column: 1 / -1; }

.builder-field-body label {
    display: block;
    font-weight: 600;
    font-size: 0.78rem;
    color: #555;
    margin-bottom: 0.2rem;
}
.builder-field-body .form-control { font-size: 0.85rem; padding: 0.4rem 0.6rem; }
.builder-field-body select.form-control { font-size: 0.85rem; }

.builder-conditional { display: none; }
.builder-conditional.visible { display: block; }

.builder-add-field {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border: 2px dashed #ccc;
    border-radius: 6px;
    cursor: pointer;
    color: #888;
    font-size: 0.9rem;
    transition: border-color 0.2s, color 0.2s;
    background: transparent;
    width: 100%;
}
.builder-add-field:hover { border-color: var(--accent); color: var(--accent); }

.builder-options-section {
    background: #f8f9fa;
    border: 1px solid #eee;
    border-radius: 6px;
    padding: 1rem;
    margin-top: 0.75rem;
}

.builder-checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0;
}
.builder-checkbox-row input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }
.builder-checkbox-row label { font-weight: 500; font-size: 0.85rem; color: #555; margin-bottom: 0; }
.builder-checkbox-row .text-muted { font-size: 0.78rem; }

/* JSON preview panel */
.builder-json-preview {
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: 6px;
    padding: 1rem;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre;
    max-height: 500px;
    overflow-y: auto;
    line-height: 1.5;
}

/* Export page */
.export-table-list { display: flex; flex-direction: column; gap: 0.5rem; }
.export-table-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid #eee;
    border-radius: 4px;
    transition: background 0.15s;
}
.export-table-item:hover { background: #f5f7fa; }
.export-table-item input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }
.export-table-item.disabled { opacity: 0.5; }
.export-table-meta { font-size: 0.8rem; color: #777; margin-left: auto; }

/* Menu Order page */
.menu-order-list { display: flex; flex-direction: column; gap: 0.5rem; }
.menu-order-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    transition: box-shadow 0.15s, border-color 0.15s;
    cursor: default;
    user-select: none;
}
.menu-order-item:hover { background: #f5f7fa; }
.menu-order-item.dragging { opacity: 0.5; border-style: dashed; }
.menu-order-item.drag-over { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(15,52,96,0.2); }
.menu-order-handle {
    cursor: grab;
    color: #aaa;
    font-size: 1.1rem;
    padding: 0.25rem;
    flex-shrink: 0;
}
.menu-order-handle:active { cursor: grabbing; }
.menu-order-position {
    display: inline-block;
    width: 1.5rem;
    text-align: center;
    font-weight: 600;
    color: #999;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.menu-order-icon { font-size: 1rem; flex-shrink: 0; }
.menu-order-label { font-weight: 600; flex: 1; }
.menu-order-table { font-size: 0.8rem; }
.menu-order-hidden { opacity: 0.5; background: #f9f9f9; }
.menu-order-hidden .menu-order-label { text-decoration: line-through; }
.menu-visibility-form { display: inline; margin: 0; flex-shrink: 0; }

/* Multi-file attachment list */
.file-attachment-list { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.5rem; }
.file-attachment-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--bg-secondary, #f5f5f5);
    border-radius: 4px;
    font-size: 0.9rem;
}
.file-attachment-icon { font-size: 1.1rem; flex-shrink: 0; }
.file-attachment-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-attachment-size { font-size: 0.8rem; flex-shrink: 0; }
.file-attachment-remove {
    margin: 0;
    font-size: 0.8rem;
    color: #dc3545;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}
.file-attachment-remove input { margin-right: 0.2rem; }

/* ---- Clickable Table Rows ---- */
.clickable-row { cursor: pointer; transition: background 0.15s; }
.clickable-row:hover { background: #e8f0fe; }

/* ---- Record View Page ---- */
.record-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.3;
}
.record-subtitle {
    font-size: 0.85rem;
    font-weight: 500;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.15rem;
}

.record-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #888;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #eee;
}

.record-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem 2rem;
    margin-bottom: 1.25rem;
}
.record-detail-item { min-width: 0; }
.record-detail-full { grid-column: 1 / -1; }

.record-detail-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #888;
    margin-bottom: 0.2rem;
}
.record-detail-value {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--dark);
    word-break: break-word;
}
.record-detail-text {
    white-space: pre-wrap;
    line-height: 1.5;
    font-weight: 400;
}

/* Timestamps row at bottom of details card */
.record-timestamps {
    display: flex;
    gap: 2rem;
    padding-top: 0.75rem;
    border-top: 1px solid #eee;
    font-size: 0.8rem;
    color: #888;
}
.record-timestamp-label {
    font-weight: 600;
    margin-right: 0.25rem;
}

/* Attachment groups within the view page */
.record-attachment-group {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid #f0f0f0;
}
.record-attachment-group:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}
.record-attachment-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #666;
    margin-bottom: 0.5rem;
}

/* ---- Child Record Cards ---- */
.child-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.child-card-item {
    display: block;
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    background: var(--bg-primary, #fff);
    transition: box-shadow 0.15s, border-color 0.15s;
}
.child-card-item:hover {
    border-color: var(--primary-color, #4a90d9);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.child-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary, #333);
}
.child-card-field {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.15rem 0;
    font-size: 0.85rem;
}
.child-card-label {
    color: #888;
    flex-shrink: 0;
    margin-right: 0.5rem;
}
.child-card-value {
    text-align: right;
    color: var(--text-primary, #333);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Clickable table rows ---- */
tr.clickable-row {
    cursor: pointer;
    transition: background-color 0.1s;
}
tr.clickable-row:hover {
    background-color: rgba(74, 144, 217, 0.06);
}

/* ---- Markdown Editor ---- */
.markdown-editor-wrapper {
    border: 1px solid var(--border-color, #ddd);
    border-radius: 6px;
    overflow: hidden;
}
.markdown-editor-wrapper .form-control {
    border: none;
    border-radius: 0;
    border-top: 1px solid var(--border-color, #ddd);
}
.markdown-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px 6px;
    background: var(--bg-secondary, #f5f5f5);
    flex-wrap: wrap;
}
.md-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 26px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-primary, #333);
    transition: background 0.15s, border-color 0.15s;
}
.md-btn:hover {
    background: var(--bg-primary, #fff);
    border-color: var(--border-color, #ddd);
}
.md-separator {
    width: 1px;
    height: 18px;
    background: var(--border-color, #ddd);
    margin: 0 4px;
}
.md-preview-toggle.active {
    background: var(--primary-color, #4a90d9);
    color: #fff;
    border-color: var(--primary-color, #4a90d9);
}
.markdown-preview {
    padding: 0.75rem 1rem;
    min-height: 120px;
    border-top: 1px solid var(--border-color, #ddd);
    background: var(--bg-primary, #fff);
}
.markdown-preview.hidden {
    display: none;
}

/* ---- Rendered Markdown Content ---- */
.markdown-rendered {
    line-height: 1.6;
}
.markdown-rendered h1 { font-size: 1.4rem; margin: 1rem 0 0.5rem; font-weight: 600; }
.markdown-rendered h2 { font-size: 1.2rem; margin: 0.9rem 0 0.4rem; font-weight: 600; }
.markdown-rendered h3 { font-size: 1.05rem; margin: 0.8rem 0 0.4rem; font-weight: 600; }
.markdown-rendered h4, .markdown-rendered h5, .markdown-rendered h6 { font-size: 0.95rem; margin: 0.7rem 0 0.3rem; font-weight: 600; }
.markdown-rendered p { margin: 0 0 0.6rem; }
.markdown-rendered ul, .markdown-rendered ol { margin: 0 0 0.6rem; padding-left: 1.5rem; }
.markdown-rendered li { margin-bottom: 0.2rem; }
.markdown-rendered blockquote {
    border-left: 3px solid var(--primary-color, #4a90d9);
    margin: 0 0 0.6rem;
    padding: 0.4rem 0.8rem;
    color: #666;
    background: rgba(74, 144, 217, 0.04);
}
.markdown-rendered pre {
    background: var(--bg-secondary, #f5f5f5);
    border: 1px solid var(--border-color, #ddd);
    border-radius: 4px;
    padding: 0.6rem 0.8rem;
    overflow-x: auto;
    margin: 0 0 0.6rem;
    font-size: 0.85rem;
}
.markdown-rendered code {
    background: var(--bg-secondary, #f5f5f5);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    font-size: 0.88em;
}
.markdown-rendered pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}
.markdown-rendered table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 0.6rem;
}
.markdown-rendered th, .markdown-rendered td {
    border: 1px solid var(--border-color, #ddd);
    padding: 0.35rem 0.6rem;
    text-align: left;
}
.markdown-rendered th {
    background: var(--bg-secondary, #f5f5f5);
    font-weight: 600;
}
.markdown-rendered hr {
    border: none;
    border-top: 1px solid var(--border-color, #ddd);
    margin: 1rem 0;
}
.markdown-rendered a {
    color: var(--primary-color, #4a90d9);
    text-decoration: none;
}
.markdown-rendered a:hover {
    text-decoration: underline;
}
.markdown-rendered img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

/* ---- Activity Timeline & Comments ---- */
.activity-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.activity-item {
    display: flex;
    gap: 0.6rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color, #eee);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
    flex-shrink: 0;
    width: 24px;
    text-align: center;
    color: #aaa;
    font-size: 0.6rem;
    padding-top: 0.3rem;
}
.activity-icon.comment-icon {
    font-size: 0.9rem;
    color: var(--primary-color, #4a90d9);
}
.activity-content {
    flex: 1;
    min-width: 0;
}
.activity-audit .activity-content {
    font-size: 0.85rem;
    color: #888;
}
.activity-action {
    font-family: monospace;
    font-size: 0.8rem;
    background: var(--bg-secondary, #f5f5f5);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
}
.activity-time {
    font-size: 0.75rem;
    margin-left: 0.5rem;
}
.comment-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.25rem;
}
.comment-body {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary, #333);
}
.btn-comment-delete {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.25rem;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.15s;
}
.btn-comment-delete:hover { opacity: 1; }

/* ---- File Version History ---- */
.version-history {
    margin-top: 0.5rem;
}
.version-history-toggle {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--primary-color, #4a90d9);
    user-select: none;
}
.version-history-toggle:hover { text-decoration: underline; }
.version-history-list {
    margin-top: 0.5rem;
    border: 1px solid var(--border-color, #eee);
    border-radius: 4px;
    overflow: hidden;
}
.version-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.6rem;
    font-size: 0.82rem;
    border-bottom: 1px solid var(--border-color, #eee);
    flex-wrap: wrap;
}
.version-item:last-child { border-bottom: none; }
.version-item.version-current { background: rgba(74, 144, 217, 0.04); }
.version-number {
    font-weight: 600;
    min-width: 28px;
    color: var(--primary-color, #4a90d9);
}
.version-filename {
    font-family: monospace;
    font-size: 0.8rem;
}
.version-meta {
    font-size: 0.75rem;
    flex: 1;
}

/* ---- Workflow Status Badges ---- */
.workflow-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.workflow-transition-arrow {
    color: #aaa;
    margin: 0 0.25rem;
    font-size: 0.8rem;
}
.workflow-info {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.25rem;
}
.workflow-blocked {
    color: #dc3545;
    font-size: 0.85rem;
}

/* ---- Dashboard Widgets ---- */
.widget-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}
.widget-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    overflow: hidden;
}
.widget-card.widget-small { grid-column: span 1; }
.widget-card.widget-medium { grid-column: span 1; }
.widget-card.widget-large { grid-column: span 3; }
.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
}
.widget-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #333;
    margin: 0;
}
.widget-link {
    font-size: 1.1rem;
    color: var(--accent, #0f3460);
    text-decoration: none;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.widget-link:hover { opacity: 1; }
.widget-body {
    padding: 1rem;
}
.widget-error {
    font-size: 0.85rem;
    font-style: italic;
}

/* Record Count Widget */
.widget-count-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}
.widget-big-number {
    font-size: 2.2rem;
    font-weight: 700;
    color: #1a1a2e;
    line-height: 1;
}
.widget-count-label {
    font-size: 0.8rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Status Breakdown Widget */
.widget-status-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.widget-status-row {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.widget-status-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}
.widget-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.widget-status-label {
    flex: 1;
    color: #444;
}
.widget-status-count {
    font-weight: 600;
    color: #333;
}
.widget-status-bar-bg {
    height: 4px;
    background: #f0f0f0;
    border-radius: 2px;
    overflow: hidden;
}
.widget-status-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}
.widget-total {
    font-size: 0.8rem;
    color: #888;
    text-align: right;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #f0f0f0;
}

/* Overdue Widget */
.widget-overdue-display {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
}
.widget-overdue-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
}
.widget-overdue-danger { background: #fff5f5; }
.widget-overdue-danger .widget-big-number { color: #dc3545; }
.widget-overdue-warning { background: #fffbeb; }
.widget-overdue-warning .widget-big-number { color: #f59e0b; }
.widget-overdue-label {
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Recent Records Widget */
.widget-recent-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.widget-recent-table th {
    text-align: left;
    font-weight: 600;
    color: #666;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #e0e0e0;
}
.widget-recent-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #f0f0f0;
    color: #444;
}
.widget-recent-table .clickable-row { cursor: pointer; }
.widget-recent-table .clickable-row:hover { background: #f8f9fa; }

/* ---- Virtual / Computed Columns ---- */
.virtual-col-header {
    background: #f8f0ff;
}
.virtual-col-cell {
    background: rgba(248, 240, 255, 0.3);
}
.virtual-count {
    font-weight: 600;
    color: #555;
}
.virtual-days {
    color: #555;
}

/* ---- Admin: Reorder List ---- */
.reorder-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.reorder-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}
.reorder-handle {
    cursor: grab;
    color: #aaa;
    font-size: 1.1rem;
}
.reorder-btns {
    margin-left: auto;
    display: flex;
    gap: 0.25rem;
}

/* ==============================================
   Mobile Drawer (hidden on desktop, shown on mobile)
   ============================================== */
.mobile-drawer-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.mobile-drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.mobile-drawer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    background: var(--sidebar-bg);
    color: var(--text);
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    flex-direction: column;
    pointer-events: none;
}
.mobile-drawer.open {
    transform: translateX(0);
    pointer-events: auto;
}

.mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    min-height: var(--topbar-height);
    flex-shrink: 0;
}
.mobile-drawer-title {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mobile-drawer-close {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s;
}
.mobile-drawer-close:hover { background: rgba(255,255,255,0.1); }

.mobile-drawer-nav {
    flex: 1;
    padding: 0.5rem 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Mobile nav items */
.mobile-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s;
    min-height: 44px;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    font: inherit;
    font-size: 0.9rem;
}
.mobile-nav-item:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: var(--text); }
.mobile-nav-item.active { background: var(--accent); color: #fff; }

.mobile-nav-icon { width: 22px; text-align: center; flex-shrink: 0; font-size: 1rem; }

/* Section headers in mobile drawer */
.mobile-nav-section { border-top: 1px solid var(--border); }
.mobile-nav-section:first-child { border-top: none; }

.mobile-nav-section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    min-height: 44px;
    transition: background 0.15s;
}
.mobile-nav-section-header:hover { background: rgba(255,255,255,0.05); }

.mobile-nav-chevron {
    margin-left: auto;
    font-size: 0.7rem;
    transition: transform 0.25s ease;
    opacity: 0.5;
}
.mobile-nav-section-header.expanded .mobile-nav-chevron,
.mobile-nav-submenu-trigger.expanded .mobile-nav-chevron {
    transform: rotate(90deg);
    opacity: 1;
}

/* Collapsible section items */
.mobile-nav-section-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.mobile-nav-section-items.open {
    max-height: 2000px;
}

/* Submenu groups (nested accordion) */
.mobile-nav-submenu-group { }
.mobile-nav-submenu-trigger {
    position: relative;
}

.mobile-nav-submenu-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(0, 0, 0, 0.15);
}
.mobile-nav-submenu-items.open {
    max-height: 1000px;
}

.mobile-nav-subitem {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem 0.65rem 2.5rem;
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.15s;
    min-height: 40px;
}
.mobile-nav-subitem:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.mobile-nav-subitem.active { background: var(--accent); color: #fff; }

/* Mobile user section at bottom of drawer */
.mobile-nav-user {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding: 0.25rem 0;
}
.mobile-nav-logout {
    color: var(--text);
    opacity: 0.7;
}
.mobile-nav-logout:hover { opacity: 1; }

/* Hamburger button in topbar (hidden on desktop) */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.mobile-menu-toggle:hover { background: rgba(255,255,255,0.1); }

/* Prevent body scroll when drawer is open */
body.mobile-drawer-open { overflow: hidden; }

/* ==============================================
   Responsive: Desktop-only topbar username class
   ============================================== */
.topbar-username { white-space: nowrap; }

/* ==============================================
   Responsive: 1200px - Tablet landscape
   ============================================== */
@media (max-width: 1200px) {
    .widget-grid { grid-template-columns: repeat(2, 1fr); }
    .widget-card.widget-large { grid-column: span 2; }
}

/* ==============================================
   Responsive: 768px - Tablet / Mobile
   ============================================== */
@media (max-width: 768px) {
    /* ---- Hide desktop sidebar and submenu ---- */
    .sidebar { display: none; }
    .submenu-sidebar { display: none; }

    /* ---- Show mobile drawer elements ---- */
    .mobile-drawer-backdrop { display: block; }
    .mobile-drawer { display: flex; }
    .mobile-menu-toggle { display: inline-flex; }

    /* ---- Main content: full width, no sidebar margin ---- */
    .main-wrapper {
        margin-left: 0 !important;
        max-width: 100vw !important;
    }
    .main-wrapper.has-submenu {
        margin-left: 0 !important;
        max-width: 100vw !important;
    }

    /* ---- Topbar: compact mobile layout ---- */
    .topbar {
        padding: 0 0.75rem;
        gap: 0.5rem;
    }
    .topbar-username { display: none; }
    .topbar-logout { font-size: 0.78rem; }

    /* Breadcrumb: show only current page on mobile */
    .breadcrumb-item { display: none; }
    .breadcrumb-separator { display: none; }
    .breadcrumb-current {
        font-size: 0.85rem;
    }

    /* ---- Content area: tighter padding ---- */
    .content-area {
        padding: 1rem;
    }

    /* ---- Page header: stack on mobile ---- */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .page-header h1 { font-size: 1.25rem; }
    .page-header-left { width: 100%; }

    /* ---- Forms: single column ---- */
    .form-row { grid-template-columns: 1fr; }
    .form-actions { flex-wrap: wrap; }

    /* ---- Grids: single column ---- */
    .stats-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .record-detail-grid { grid-template-columns: 1fr; }
    .record-timestamps { flex-direction: column; gap: 0.5rem; }

    /* ---- Dashboard widgets: single column ---- */
    .widget-grid { grid-template-columns: 1fr; }
    .widget-card.widget-large { grid-column: span 1; }
    .widget-card.widget-medium { grid-column: span 1; }

    /* ---- Tables: better mobile scrolling ---- */
    .table-container {
        position: relative;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    th, td {
        padding: 0.6rem 0.75rem;
        font-size: 0.82rem;
    }

    /* ---- Buttons: touch-friendly sizing ---- */
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
        min-height: 44px;
    }
    .btn-sm {
        padding: 0.45rem 0.75rem;
        font-size: 0.78rem;
        min-height: 36px;
    }
    .btn-group { gap: 0.5rem; }
    .btn-group-sm { gap: 0.25rem; flex-wrap: wrap; }

    /* ---- Cards: tighter on mobile ---- */
    .card { padding: 1rem; margin-bottom: 1rem; }

    /* ---- Filter row: stack vertically ---- */
    .core-table-filters { gap: 0.5rem; }
    .filter-row { flex-direction: column; align-items: stretch; }
    .filter-search { max-width: 100%; min-width: 0; }
    .column-filter-input { width: 100%; }
    .column-filters-table td { display: block; padding: 0.15rem 0; }
    .column-filter-label { text-align: left; padding-right: 0 !important; }

    /* ---- Builder field body: single column ---- */
    .builder-field-body { grid-template-columns: 1fr; }

    /* ---- Plugin cards ---- */
    .plugin-meta { flex-direction: column; gap: 0.25rem; }
    .plugin-actions { flex-direction: column; }
    .plugin-actions .btn { width: 100%; justify-content: center; }

    /* ---- Pagination: wrap on mobile ---- */
    .pagination { flex-wrap: wrap; }

    /* ---- Export table items ---- */
    .export-table-meta { margin-left: 0; }

    /* ---- Record view ---- */
    .record-title { font-size: 1.25rem; }

    /* ---- Child cards: single column on mobile ---- */
    .child-cards-grid { grid-template-columns: 1fr; }

    /* ---- File attachment items: wrap filename ---- */
    .file-attachment-name { white-space: normal; word-break: break-all; }

    /* ---- Version history items: stack ---- */
    .version-item { flex-direction: column; align-items: flex-start; gap: 0.25rem; }

    /* ---- Checkbox group: single column ---- */
    .checkbox-group { grid-template-columns: 1fr; }

    /* ---- Overdue widget: stack ---- */
    .widget-overdue-display { flex-direction: column; gap: 0.75rem; }

    /* ---- Color picker group: stack ---- */
    .color-group { flex-direction: column; align-items: flex-start; }
    .color-group .color-label { min-width: auto; }

    /* ---- Searchable select: ensure full width ---- */
    .searchable-select-wrapper { width: 100%; }

    /* ---- Menu order / reorder items: touch-friendly ---- */
    .menu-order-item { padding: 0.75rem; min-height: 44px; }
    .reorder-item { padding: 0.65rem 0.75rem; min-height: 44px; }

    /* ---- Activity timeline ---- */
    .comment-header { font-size: 0.82rem; }

    /* ---- Markdown toolbar: wrap ---- */
    .markdown-toolbar { gap: 1px; padding: 3px 4px; }
    .md-btn { min-width: 32px; height: 32px; }
}

/* ==============================================
   Responsive: 480px - Small phones
   ============================================== */
@media (max-width: 480px) {
    /* Even tighter content padding */
    .content-area { padding: 0.75rem; }

    /* Stack form actions fully */
    .form-actions {
        flex-direction: column;
    }
    .form-actions .btn { width: 100%; justify-content: center; }

    /* Auth card: tighter on tiny screens */
    .auth-card { padding: 1.5rem; margin: 1rem; }
    .auth-card h1 { font-size: 1.25rem; }

    /* Stat cards: smaller text */
    .stat-card .stat-value { font-size: 1.5rem; }

    /* Table cells: even more compact */
    th, td { padding: 0.5rem 0.6rem; font-size: 0.78rem; }

    /* Widget body padding */
    .widget-body { padding: 0.75rem; }
    .widget-header { padding: 0.6rem 0.75rem; }

    /* Mobile drawer: wider */
    .mobile-drawer { width: 280px; }

    /* Record detail label stacking */
    .record-detail-value { font-size: 0.9rem; }

    /* Page header */
    .page-header h1 { font-size: 1.1rem; }

    /* Builder add field button */
    .builder-add-field { padding: 0.6rem; font-size: 0.85rem; }

    /* JSON preview */
    .builder-json-preview { font-size: 0.72rem; padding: 0.75rem; }
}
