/* ==============================================
   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 .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; }

.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);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar { width: var(--sidebar-collapsed-width); }
    .sidebar .sidebar-label, .sidebar .section-header span, .sidebar .menu-item-label { display: none; }
    .main-wrapper { margin-left: var(--sidebar-collapsed-width); max-width: calc(100vw - var(--sidebar-collapsed-width)); }
    .submenu-sidebar { display: none; }
    .main-wrapper.has-submenu {
        margin-left: var(--sidebar-collapsed-width);
        max-width: calc(100vw - var(--sidebar-collapsed-width));
    }
    .form-row { grid-template-columns: 1fr; }
    .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; }
}
