.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); gap: 16px; min-height: 100vh; padding: 16px; transition: grid-template-columns 180ms ease; }
.sidebar, .content { min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: 12px; }
.content { display: flex; flex-direction: column; gap: 14px; overflow-x: hidden; }
.brand, .panel, .drop-section, .status-row, .metric, .analytics-section, .pivot-section, .data-section, .chart-panel, .modal-content { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.brand { padding: 16px; }
.brand-kicker, .section-label { display: block; margin-bottom: 4px; color: var(--primary); font-family: var(--font-mono); font-size: 0.76rem; font-weight: 700; letter-spacing: 0; }
.brand h1, .workspace-header h2, .section-title-row h2, .panel h2 { margin: 0; }
.brand h1 { font-size: 1.2rem; line-height: 1.35; }
.brand p, .hint { margin: 8px 0 0; color: var(--muted); font-size: 0.9rem; }
.panel { padding: 14px; }
.panel h2, .section-title-row h2 { font-size: 1rem; }
.button-stack { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.button { min-height: 44px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 7px; cursor: pointer; font-weight: 700; transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease; }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button.secondary, .button.ghost { background: var(--surface); color: var(--text); }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button:hover { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14); }
.button:focus-visible, select:focus-visible, .dropzone:focus-visible, .table-wrap:focus-visible, .switch:focus-within .slider { outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent); outline-offset: 2px; }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; color: var(--text); font-weight: 600; }
.switch { position: relative; display: inline-flex; width: 48px; height: 28px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.slider { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background-color 180ms ease; }
.slider::before { content: ''; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35); transition: transform 180ms ease; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.field { margin-top: 12px; }
.field label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
select, input[type="date"] { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); }
select[multiple] { min-height: 112px; padding: 6px; }
select[multiple] option { padding: 5px 6px; border-radius: 5px; }
.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.compact-row { margin-bottom: 4px; }
.workspace-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 4px 2px; }
.workspace-header h2 { font-size: 1.45rem; line-height: 1.2; }
.drop-section { padding: 12px; }
.dropzone { min-height: 106px; display: grid; place-items: center; gap: 4px; padding: 18px; border: 2px dashed var(--primary-weak); border-radius: var(--radius); background: var(--surface-soft); color: var(--muted); text-align: center; cursor: pointer; transition: background-color 180ms ease, border-color 180ms ease; }
.dropzone strong { color: var(--text); font-size: 1.05rem; }
.dropzone.dragover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.hidden-file { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.status-row { display: flex; align-items: center; gap: 12px; padding: 12px; }
.status { min-height: 44px; flex: 1; display: flex; align-items: center; padding: 8px 10px; border-left: 4px solid var(--primary); background: var(--surface-soft); color: var(--text); font-weight: 600; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.metric { padding: 14px; }
.metric span { display: block; color: var(--muted); font-size: 0.86rem; font-weight: 700; }
.metric strong { display: block; margin-top: 6px; font-family: var(--font-mono); font-size: 1.45rem; line-height: 1.15; overflow-wrap: anywhere; }
.metric strong.up { color: var(--success); }
.metric strong.down { color: var(--danger); }
.metric strong.neutral { color: var(--muted); }
.metric.accent { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.analytics-section, .pivot-section, .data-section, .chart-panel { padding: 14px; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-title-row .button { min-height: 36px; padding: 6px 10px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; min-width: 840px; border-collapse: collapse; background: var(--surface); }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table th { position: sticky; top: 0; z-index: 1; background: var(--surface-strong); color: var(--text); font-size: 0.84rem; }
.data-table td { color: var(--text); font-size: 0.9rem; }
.data-table tbody tr:nth-child(even) { background: var(--row-alt); }
.data-table tbody tr:hover { background: var(--row-hover); }
.empty { text-align: center; color: var(--muted); }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.chart { width: 100%; max-width: 100%; min-width: 0; height: 280px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-soft); }
.large-chart { height: 360px; }
.analysis-controls { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.pivot-section .analysis-controls { grid-template-columns: repeat(5, minmax(140px, 1fr)); }
#pivot-row[draggable="true"], #pivot-column[draggable="true"] { cursor: grab; }
.pivot-wrap { max-height: 460px; }
.pivot-table { min-width: 720px; }
.pivot-table th[scope='row'] { position: sticky; left: 0; z-index: 2; background: var(--surface-strong); }
.pivot-table .total-row th, .pivot-table .total-row td { background: color-mix(in srgb, var(--primary) 10%, var(--surface)); font-weight: 700; }
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(15, 23, 42, 0.62); }
.modal[hidden] { display: none; }
.modal-content { width: min(520px, 100%); padding: 18px; }
.modal-content h2 { margin: 0 0 8px; }
.modal-content p { margin: 0 0 10px; color: var(--muted); }
.modal-content code { display: block; padding: 10px; border-radius: 7px; background: var(--surface-soft); font-family: var(--font-mono); }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; } }
@media (max-width: 980px) { .app-shell { grid-template-columns: 1fr; } .sidebar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); } .brand { grid-column: 1 / -1; } .kpi-grid, .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .analysis-controls, .pivot-section .analysis-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .app-shell { padding: 10px; } .sidebar, .kpi-grid, .chart-grid, .analysis-controls, .pivot-section .analysis-controls, .field-pair { grid-template-columns: 1fr; } .workspace-header, .status-row { align-items: stretch; flex-direction: column; } .button-stack { grid-template-columns: 1fr; } .workspace-header h2 { font-size: 1.2rem; } .large-chart { height: 320px; } }


/* Dashboard builder pages */
.page-tabs { display: grid; grid-template-columns: 1fr; gap: 8px; }
.tab-button { min-height: 44px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); cursor: pointer; font-weight: 700; text-align: left; transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease; }
.tab-button.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 13%, var(--surface)); color: var(--primary); }
.tab-button:hover { border-color: var(--primary-weak); }
.view-panel { display: flex; flex-direction: column; gap: 14px; }
.view-panel[hidden], .dashboard-only[hidden] { display: none; }
.import-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.dashboard-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.dashboard-toolbar h2 { margin: 0; font-size: 1.1rem; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.dashboard-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; width: 100%; min-width: 0; overflow: hidden; }
.dashboard-card { min-width: 0; max-width: 100%; overflow: hidden; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.dashboard-card.width-full { grid-column: 1 / -1; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; min-width: 0; }
.card-title-input { width: min(360px, 100%); min-height: 40px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); font-weight: 700; }
.card-subtitle { display: block; margin-top: 4px; color: var(--muted); font-size: 0.82rem; }
.card-actions { flex: 0 0 auto; display: flex; flex-wrap: nowrap; gap: 4px; justify-content: flex-end; }
.icon-button { min-width: 34px; min-height: 34px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 0.88rem; font-weight: 800; line-height: 1; white-space: nowrap; }
.icon-button:hover { border-color: var(--primary-weak); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12); }
.danger-text { color: var(--danger); }
.card-controls { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 8px; margin-bottom: 10px; }
.card-controls label { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.card-controls select { margin-top: 4px; min-height: 38px; }
.card-warning, .chart-config-warning { border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border)); border-radius: 7px; background: color-mix(in srgb, var(--danger) 9%, var(--surface)); color: var(--danger); font-size: 0.86rem; font-weight: 700; line-height: 1.45; }
.card-warning { margin-bottom: 10px; padding: 8px 10px; }
.chart-config-warning { display: grid; min-height: 100%; place-items: center; padding: 18px; text-align: center; }
.pivot-builder-controls { grid-template-columns: repeat(6, minmax(130px, 1fr)); }
.chart > div, .chart canvas { max-width: 100%; }
.leaflet-dashboard-map { position: relative; width: 100%; height: 100%; min-height: 380px; overflow: hidden; border: 1px solid var(--border); border-radius: 8px; background: #dbeafe; }
.leaflet-dashboard-map .leaflet-container { width: 100%; height: 100%; min-height: inherit; font-family: inherit; }
.leaflet-map-title { position: absolute; top: 10px; left: 50px; right: 10px; z-index: 410; max-width: calc(100% - 64px); padding: 7px 10px; border: 1px solid rgba(15, 23, 42, 0.12); border-radius: 7px; background: rgba(255, 255, 255, 0.92); color: #0f172a; font-weight: 800; box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12); pointer-events: none; }
.leaflet-map-empty { display: grid; min-height: 380px; place-items: center; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-weight: 800; background: var(--surface-strong); }
.leaflet-popup-content { margin: 10px 12px; font-family: inherit; line-height: 1.45; }
.leaflet-popup-content strong { display: block; margin-bottom: 4px; }
.leaflet-marker-icon.leaflet-interactive, .leaflet-interactive { cursor: pointer; }
@media (max-width: 980px) { .import-grid, .dashboard-card-grid { grid-template-columns: 1fr; } .dashboard-toolbar { align-items: stretch; flex-direction: column; } .toolbar-actions { justify-content: flex-start; } .card-actions { justify-content: flex-end; } .card-controls, .pivot-builder-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .card-controls, .pivot-builder-controls { grid-template-columns: 1fr; } .dashboard-toolbar { padding: 12px; } .card-title-input { width: 100%; } }

.selection-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: color-mix(in srgb, var(--primary) 7%, var(--surface)); color: var(--text); font-weight: 700; }
.selection-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.selection-actions .button:disabled { cursor: not-allowed; opacity: 0.48; box-shadow: none; }
@media (max-width: 640px) { .selection-bar { align-items: stretch; flex-direction: column; } .selection-actions { flex-direction: column; } }

.relationship-panel { padding: 14px; }
.relationship-form { display: grid; gap: 12px; }
.relationship-form-grid { display: grid; grid-template-columns: repeat(3, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.relationship-enabled-row { min-height: 44px; margin-top: 12px; padding: 0 2px; }
.relationship-form-actions { justify-content: flex-start; }
.relationship-list { display: grid; gap: 10px; margin-top: 12px; }
.relationship-empty { margin: 0; padding: 12px; border: 1px dashed var(--border); border-radius: 7px; color: var(--muted); font-weight: 700; }
.relationship-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-soft); }
.relationship-item.disabled { opacity: 0.72; }
.relationship-item h3 { margin: 0; font-size: 0.98rem; line-height: 1.35; overflow-wrap: anywhere; }
.relationship-stats { margin: 6px 0 0; color: var(--muted); font-size: 0.88rem; font-weight: 700; }
.relationship-errors { margin-top: 8px; padding: 8px 10px; border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border)); border-radius: 7px; background: color-mix(in srgb, var(--danger) 9%, var(--surface)); color: var(--danger); font-size: 0.86rem; font-weight: 700; }
.relationship-actions { display: flex; flex-wrap: wrap; gap: 8px; align-content: start; justify-content: flex-end; }
@media (max-width: 980px) { .relationship-form-grid, .relationship-item { grid-template-columns: 1fr; } .relationship-actions { justify-content: flex-start; } }

.visual-builder-view { display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.visual-builder-view[hidden], .visual-builder-sidebar[hidden] { display: none; }
.visual-builder-sidebar { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.app-shell.app-sidebar-collapsed { grid-template-columns: 72px minmax(0, 1fr); }
.app-shell.app-sidebar-collapsed .sidebar { gap: 8px; }
.app-shell.app-sidebar-collapsed .brand { min-height: 56px; padding: 10px 8px; text-align: center; }
.app-shell.app-sidebar-collapsed .brand-kicker,
.app-shell.app-sidebar-collapsed .brand h1,
.app-shell.app-sidebar-collapsed .brand p,
.app-shell.app-sidebar-collapsed .page-tabs,
.app-shell.app-sidebar-collapsed .builder-settings-section { display: none; }
.app-shell.app-sidebar-collapsed .brand::after { content: 'LBA'; display: block; color: var(--primary); font-family: var(--font-mono); font-weight: 800; }
.app-shell.app-sidebar-collapsed .visual-builder-sidebar { display: flex; }
.app-shell.app-sidebar-collapsed .sidebar-toggle { writing-mode: vertical-rl; min-width: 44px; padding: 10px 6px; }
.sidebar-toggle { width: 100%; }
.builder-section-body .analysis-controls,
.builder-section-body .pivot-builder-controls { grid-template-columns: 1fr; margin-bottom: 0; }
.builder-settings-section { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.builder-section-toggle { width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border); background: var(--surface-strong); color: var(--text); cursor: pointer; font-weight: 800; text-align: left; }
.builder-section-toggle:hover { color: var(--primary); }
.builder-settings-section.collapsed .builder-section-body { display: none; }
.builder-section-body { padding: 10px; }
.builder-section-body > .panel { border: 0; box-shadow: none; padding: 0; background: transparent; }
.selected-chart-panel .empty { padding: 12px; border: 1px dashed var(--border); border-radius: 7px; white-space: normal; }
.selected-chart-form { display: grid; gap: 10px; }
.selected-chart-form .button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.card-select { flex: 1 1 auto; appearance: none; width: 100%; min-width: 0; padding: 0; border: 0; background: transparent; color: var(--text); cursor: pointer; text-align: left; }
.card-select strong { display: block; font-size: 1rem; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent), var(--shadow); }
@media (max-width: 1280px) { .icon-button { min-width: 32px; padding-inline: 7px; font-size: 0.8rem; } .card-actions { gap: 3px; } }
@media (max-width: 760px) { .icon-button .action-label { display: none; } }
@media (max-width: 980px) { .app-shell.app-sidebar-collapsed { grid-template-columns: 1fr; } .app-shell.app-sidebar-collapsed .sidebar { display: flex; } .app-shell.app-sidebar-collapsed .sidebar-toggle { writing-mode: horizontal-tb; } }
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: var(--color-background, #f4f7fb);
}

.auth-shell[hidden],
#dashboard-app[hidden],
.cloud-session-bar[hidden] {
  display: none;
}

.auth-card {
  width: min(100%, 28rem);
  padding: 2rem;
  border: 1px solid var(--color-border, #d9e2ef);
  border-radius: 1rem;
  background: var(--color-surface, #fff);
  box-shadow: 0 1rem 3rem rgb(15 23 42 / 10%);
}

.auth-card-wide {
  width: min(100%, 64rem);
}

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

.organization-member-table {
  min-width: 42rem;
}

.member-assignment-fieldset {
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.member-assignment-options {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.member-assignment-row {
  display: grid;
  grid-template-columns: auto minmax(10rem, 1fr) minmax(9rem, 0.7fr);
  align-items: center;
  gap: 0.75rem;
}

.assignment-results {
  display: grid;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
  padding-left: 1.25rem;
}

.auth-form {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

.cloud-session-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border, #d9e2ef);
  background: var(--color-surface, #fff);
}

.cloud-session-bar select {
  max-width: 22rem;
}
