/* Solidbus SPA Styles — Professional Data-Entry */
:root {
    --primary-color: #000;
    --primary-hover: #333;
    --danger-color: #c00;
    --success-color: #060;
    --warning-color: #c60;
    --bg-color: #fff;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --sidebar-hover: #334155;
    --border-color: #000;
    --border-light: #ccc;
    --text-color: #000;
    --text-muted: #555;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 13px;
    line-height: 1.4;
}

#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* =========================================================================
   Sidebar Navigation
   ========================================================================= */
#sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.logo {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}

.logo h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
}

#nav-groups {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.nav-group {
    margin-bottom: 4px;
}

.nav-group-header {
    padding: 6px 16px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.85rem;
}

.nav-item:hover {
    background: var(--sidebar-hover);
}

.nav-item.active {
    background: #475569;
    color: #fff;
    font-weight: 600;
}

.nav-item-icon {
    width: 18px;
    height: 18px;
    margin-right: 8px;
    opacity: 0.7;
    font-size: 14px;
}

/* =========================================================================
   Main Content Area
   ========================================================================= */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#view-container {
    flex: 1;
    min-height: 0;
    padding: 12px 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.welcome {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.welcome h2 {
    margin-bottom: 8px;
    color: var(--text-color);
}

/* =========================================================================
   SLD View Layout
   ========================================================================= */
.sld-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 8px;
}

.sld-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 4px;
    border-bottom: 2px solid #000;
}

.sld-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.sld-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.sld-list-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.data-grid-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Detail panel hidden by default — we use modals now */
.sld-detail-panel {
    display: none;
}

/* =========================================================================
   Filter Panel
   ========================================================================= */
.filter-panel {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: flex-end;
    background: #fafafa;
    flex-shrink: 0;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.filter-group label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-color);
    text-transform: uppercase;
}

.filter-group input,
.filter-group select {
    padding: 2px 4px;
    border: 1px solid var(--border-color);
    border-radius: 0;
    font-size: 12px;
    height: 24px;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: 2px solid #369;
    outline-offset: -1px;
}

/* =========================================================================
   Data Grid — div-based virtual scroll with CSS grid columns
   ========================================================================= */

/* Scroll container: spacers + row pool ONLY (header is outside).
   This is the ONLY element that scrolls. */
.grid-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    user-select: none;
}

/* Header row: fixed above scroll body — never scrolls. */
.grid-header-row {
    display: grid;
    flex-shrink: 0;
    background: #f0f0f0;
    border-bottom: 2px solid #000;
}

.grid-hcell {
    padding: 4px 6px;
    font-weight: 700;
    font-size: 11px;
    color: var(--text-color);
    white-space: nowrap;
    text-transform: uppercase;
    border-right: 1px solid var(--border-light);
    user-select: none;
    overflow: hidden;
    text-overflow: ellipsis;
}

.grid-hcell:last-child {
    border-right: 1px solid var(--border-light);
}

.grid-hcell.sortable {
    cursor: pointer;
}

.grid-hcell.sortable:hover {
    background: #e0e0e0;
}

.grid-hcell .sort-indicator {
    margin-left: 4px;
    opacity: 0.4;
    font-size: 10px;
}

.grid-hcell.sorted .sort-indicator {
    opacity: 1;
}

/* Runway: tall empty div whose height = total * ROW_HEIGHT.
   Creates the correct scrollbar. Rows are NOT inside this — they're
   in a sticky wrapper that stays pinned to the viewport. */
.grid-runway {
    /* height set dynamically by JS */
}

/* Data rows: CSS grid, fixed height for virtual scroll math. */
.grid-row {
    display: grid;
    height: 24px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
}

.grid-row:hover {
    background: #f5f5ff;
}

.grid-row.selected {
    background: #ddeeff;
}

.grid-cell {
    padding: 3px 6px;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-right: 1px solid #e8e8e8;
    line-height: 18px;
}

.grid-cell:last-child {
    border-right: 1px solid #e8e8e8;
}

/* Cell type formatting (used by renderGridCell HTML output) */
.cell-boolean {
    display: inline-block;
    font-weight: 700;
    font-size: 11px;
}

.cell-boolean.true {
    color: var(--success-color);
}

.cell-boolean.false {
    color: var(--text-muted);
}

.cell-currency {
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    text-align: right;
    font-size: 12px;
}

/* =========================================================================
   Grid Status Bar
   ========================================================================= */
.grid-status {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-top: 1px solid var(--border-color);
    background: #fafafa;
    font-size: 12px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.grid-limit-select {
    margin-right: 8px;
    padding: 1px 4px;
    font-size: 12px;
    border: 1px solid var(--border-light);
    background: #fff;
    color: var(--text-color);
}

.grid-row.active-row {
    outline: 2px solid #369;
    outline-offset: -2px;
}

.grid-cell.active-cell {
    background: #e0eeff;
}

.grid-status .btn-sm {
    padding: 2px 8px;
    font-size: 12px;
}

.grid-selection-status {
    font-size: 12px;
    color: var(--text-muted);
}

.multi-edit-field {
    display: flex;
    align-items: baseline;
    gap: 4px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-light);
}

.multi-edit-field:last-child {
    border-bottom: none;
}

.multi-edit-check {
    width: 24px;
    min-width: 24px;
    display: flex;
    align-items: center;
}

.multi-edit-control {
    flex: 1;
}


/* =========================================================================
   Detail Panel (legacy — now using modal)
   ========================================================================= */
.detail-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
}

.detail-form {
    flex: 1;
    padding: 0;
    overflow-y: auto;
}

.detail-actions {
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* =========================================================================
   Dense Form Fields — label:input rows
   ========================================================================= */
.field {
    display: flex;
    align-items: baseline;
    border-bottom: 1px solid var(--border-light);
}

.field:last-child {
    border-bottom: none;
}

.field-label {
    width: 140px;
    min-width: 140px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    background: #f8f8f8;
    border-right: 1px solid var(--border-light);
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 12px;
    font-family: inherit;
    padding: 4px 6px;
    background: #fff;
    color: var(--text-color);
    min-height: 26px;
}

.field-input:focus {
    background: #fffff0;
    outline: 2px solid #369;
    outline-offset: -2px;
}

.field-input:read-only,
.field-input:disabled {
    background: #f5f5f5;
    color: var(--text-muted);
}

.field-input[type="checkbox"] {
    width: auto;
    min-height: auto;
    margin: 4px 6px;
}

.field-select {
    flex: 1;
    border: none;
    outline: none;
    font-size: 12px;
    font-family: inherit;
    padding: 3px 4px;
    background: #fff;
    color: var(--text-color);
    min-height: 26px;
    border-radius: 0;
}

.field-select:focus {
    background: #fffff0;
    outline: 2px solid #369;
    outline-offset: -2px;
}

.field-select:disabled {
    background: #f5f5f5;
    color: var(--text-muted);
}

textarea.field-input {
    resize: vertical;
    min-height: 60px;
}

.field-required .field-label::before {
    content: '* ';
    color: #c00;
    font-weight: 700;
}

/* Dirty/batch indicator — narrow column left of the label. */
.field-indicator {
    width: 16px;
    min-width: 16px;
    text-align: center;
    font-size: 9px;
    line-height: 26px;
    color: transparent;
    user-select: none;
}

.field-dirty .field-indicator {
    color: #888;
}

/* Batch-mode checkbox inside the indicator cell. */
.field-indicator input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

/* Batch mode: widen the indicator so the include-checkbox has room. */
.modal-body .field-indicator {
    width: 28px;
    min-width: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Batch mode: give text inputs a visible border so they don't look empty. */
.modal-body .field-input {
    border: 1px solid var(--border-light) !important;
}

.modal-body .field-input:focus {
    border-color: #369 !important;
}

.field-prefix-suffix {
    flex: 1;
    display: flex;
    align-items: baseline;
}

.field-affix {
    font-size: 12px;
    padding: 4px 2px;
    color: var(--text-muted);
    white-space: nowrap;
}

.field-prefix-suffix .field-input {
    flex: 1;
}

/* Legacy form groups — keep for filter panel */
.form-group {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 3px 6px;
    border: 1px solid var(--border-color);
    border-radius: 0;
    font-size: 12px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: 2px solid #369;
    outline-offset: -1px;
}

.form-group input:read-only {
    background: #f5f5f5;
    color: var(--text-muted);
}

/* =========================================================================
   Buttons — minimal, professional
   ========================================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-radius: 0;
    cursor: pointer;
    background: #fff;
    color: var(--text-color);
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    background: #f0f0f0;
}

.btn:active:not(:disabled) {
    background: #e0e0e0;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: #000;
    color: #fff;
    border-color: #000;
}

.btn-primary:hover:not(:disabled) {
    background: #333;
}

.btn-secondary {
    background: #fff;
    color: var(--text-color);
    border-color: var(--border-light);
}

.btn-secondary:hover:not(:disabled) {
    background: #f0f0f0;
}

.btn-danger {
    background: #fff;
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.btn-danger:hover:not(:disabled) {
    background: #fff0f0;
}

.btn-sm {
    padding: 2px 8px;
    font-size: 11px;
}

.btn-icon {
    padding: 2px 6px;
    font-size: 14px;
    line-height: 1;
}

/* =========================================================================
   Toast Notifications
   ========================================================================= */
#toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toast {
    padding: 8px 16px;
    background: #fff;
    border: 1px solid var(--border-color);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideIn 0.15s ease;
    transition: opacity 0.2s, transform 0.2s;
}

.toast.removing {
    opacity: 0;
    transform: translateX(100%);
}

.toast.success {
    border-left: 3px solid var(--success-color);
}

.toast.error {
    border-left: 3px solid var(--danger-color);
}

.toast.warning {
    border-left: 3px solid var(--warning-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* =========================================================================
   Modal — for edit/create operations
   ========================================================================= */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 60px;
    z-index: 1001;
}

#modal-overlay.hidden {
    display: none;
}

#modal-content {
    background: #fff;
    border: 1px solid #000;
    width: 560px;
    max-width: 95vw;
    max-height: calc(100vh - 100px);
    overflow: auto;
}

.modal-header {
    padding: 8px 12px;
    border-bottom: 2px solid #000;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
}

.modal-body {
    padding: 0;
}

.modal-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* =========================================================================
   Loading Spinner
   ========================================================================= */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-light);
    border-top-color: #000;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =========================================================================
   Empty State
   ========================================================================= */
.empty-state {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.empty-state-icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.4;
}

/* =========================================================================
   Login Screen
   ========================================================================= */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 48px);
    padding: 24px;
}

.login-card {
    background: #fff;
    border: 2px solid #000;
    padding: 32px;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #000;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 13px;
}

.account-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.account-btn {
    display: block;
    width: 100%;
    padding: 12px;
    background: #fff;
    border: 1px solid #000;
    cursor: pointer;
    text-align: left;
}

.account-btn:hover {
    background: #f5f5f5;
}

.account-name {
    font-size: 1rem;
    font-weight: 700;
    color: #000;
    margin-bottom: 2px;
}

.account-description {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.account-roles {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.role-tag {
    display: inline-block;
    padding: 1px 6px;
    background: #000;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
}

/* =========================================================================
   User Info in Sidebar
   ========================================================================= */
.user-info {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.15);
    margin-top: auto;
}

.user-info-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 2px;
}

.user-info-roles {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-bottom: 8px;
}

.logout-btn {
    display: block;
    width: 100%;
    padding: 4px 8px;
    background: rgba(255,255,255,0.1);
    color: var(--sidebar-text);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 0;
    font-size: 0.8rem;
    cursor: pointer;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* =========================================================================
   Layout Engine — Recursive Split
   ========================================================================= */
.layout-split-horizontal {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
}

.layout-split-vertical {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.layout-pane {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.layout-slot {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* =========================================================================
   UIControl — self-contained field wrappers
   ========================================================================= */
.ui-control {
    display: flex;
    align-items: baseline;
    border-bottom: 1px solid var(--border-light);
}

.ui-control:last-child {
    border-bottom: none;
}

.ui-control .validation {
    color: var(--danger-color);
    font-size: 11px;
    padding: 2px 8px;
}

/* =========================================================================
   v2 Component Classes
   ========================================================================= */

/* SLD Composite */
.sld-composite {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 8px;
}

.sld-composite h2 {
    font-size: 1.1rem;
    font-weight: 700;
    padding-bottom: 4px;
    border-bottom: 2px solid #000;
    margin: 0;
}

/* Data Grid */
.data-grid {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.data-grid .grid-header {
    display: grid;
    width: max-content;
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f0f0f0;
    border-bottom: 2px solid #000;
}

.data-grid .grid-hcell {
    position: relative;
}

.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    z-index: 1;
}

.col-resize-handle:hover {
    background: rgba(0, 0, 0, 0.15);
}

.data-grid .grid-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.data-grid .grid-row {
    width: max-content;
}

/* Filter Bar */
.filter-bar {
    padding: 6px 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: flex-end;
    background: #fafafa;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.filter-field label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-color);
    text-transform: uppercase;
}

.filter-field input {
    padding: 2px 4px;
    border: 1px solid var(--border-color);
    border-radius: 0;
    font-size: 12px;
    height: 24px;
}

.filter-field input:focus {
    outline: 2px solid #369;
    outline-offset: -1px;
}

.filter-bar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-radius: 0;
    cursor: pointer;
    background: #fff;
    color: var(--text-color);
    height: 24px;
}

.filter-bar button:hover {
    background: #f0f0f0;
}

/* Data Form */
.data-form {
    padding: 0;
}

.data-form .form-field {
    display: flex;
    align-items: baseline;
    border-bottom: 1px solid var(--border-light);
}

.data-form .form-field:last-child {
    border-bottom: none;
}

.data-form .form-field label {
    width: 140px;
    min-width: 140px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    background: #f8f8f8;
    border-right: 1px solid var(--border-light);
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-form .form-field input,
.data-form .form-field textarea {
    flex: 1;
    border: none;
    outline: none;
    font-size: 12px;
    font-family: inherit;
    padding: 4px 6px;
    background: #fff;
    color: var(--text-color);
    min-height: 26px;
}

.data-form .form-field input:focus,
.data-form .form-field textarea:focus {
    background: #fffff0;
    outline: 2px solid #369;
    outline-offset: -2px;
}

.data-form .form-field input:read-only,
.data-form .form-field input:disabled {
    background: #f5f5f5;
    color: var(--text-muted);
}

.data-form .form-field input[type="checkbox"] {
    width: auto;
    min-height: auto;
    margin: 4px 6px;
}

/* Primitives mounted inside form-field: fill remaining width. */
.data-form .form-field .field {
    flex: 1;
    min-width: 0;
}

.data-form .form-field .field-input-container {
    flex: 1;
    display: flex;
    min-width: 0;
}

.data-form .form-field textarea {
    resize: vertical;
    min-height: 60px;
}

.data-form .required {
    color: #c00;
    font-weight: 700;
}

/* SLD Form Container */
.sld-form-container {
    border: 1px solid var(--border-color);
}

/* Modal — class-based (v2) */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 60px;
    z-index: 1001;
}

.modal-content {
    background: #fff;
    border: 1px solid #000;
    width: 560px;
    max-width: 95vw;
    max-height: calc(100vh - 100px);
    overflow: auto;
}

/* Nav group title for v2 sidebar */
.nav-group-title {
    padding: 6px 16px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: -220px;
        height: 100vh;
        z-index: 100;
        transition: left 0.2s;
    }

    #sidebar.open {
        left: 0;
    }
}
