/* Org Chart Viewer - Custom Styles (works alongside Tailwind/DaisyUI) */

/* ==================== LAYOUT ==================== */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: oklch(var(--b1));
}

.chart-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ==================== FLOATING HEADER ==================== */

.floating-header {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  overflow: visible;
}

.floating-header .card {
  border: 1px solid oklch(var(--bc) / 0.15);
  overflow: visible;
}

.floating-header .card-body {
  overflow: visible;
}

#visualization-view {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* ==================== CONTROLS (bottom-right) ==================== */

.controls {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  overflow: visible;
  align-items: flex-end;
}

.controls .dropdown {
  overflow: visible;
}

/* Force print menu to open upward */
.print-menu-top {
  bottom: 100% !important;
  top: auto !important;
  margin-bottom: 0.5rem;
}

/* ==================== BUTTON GROUPS (hover-expandable) ==================== */

.btn-group-hover {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Trigger button */
.btn-group-trigger {
  z-index: 2;
}

/* Menu that appears on hover - positioned above trigger */
.btn-group-menu {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 0.25rem;
  min-width: 160px;
  padding: 0.5rem;
  background: oklch(var(--b2));
  border: 1px solid oklch(var(--bc) / 0.15);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s 0.15s;
  pointer-events: none;
  z-index: 200;
}

/* Wide menu variant for dropdowns that need more space */
.btn-group-menu-wide {
  min-width: 240px;
}

/* Wider select for dropdown menus */
.select-wide {
  min-width: 120px;
}

/* Invisible bridge to prevent menu closing when moving mouse */
.btn-group-hover::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: -1rem;
  right: -1rem;
  height: 1.5rem;
  pointer-events: none;
}

.btn-group-hover:hover::before,
.btn-group-hover:focus-within::before {
  pointer-events: auto;
}

/* Show menu on hover - with delay for closing */
.btn-group-hover:hover .btn-group-menu,
.btn-group-hover:focus-within .btn-group-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s 0s;
}

/* Menu button items */
.btn-group-menu-btn {
  justify-content: flex-start;
  gap: 0.5rem;
  width: 100%;
  font-size: 0.75rem;
  padding: 0.375rem 0.5rem;
  height: auto;
  min-height: 1.75rem;
}

.btn-group-menu-btn svg {
  flex-shrink: 0;
}

.btn-group-menu-btn span {
  white-space: nowrap;
}

/* Form-like items in menu (with label + control) */
.btn-group-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
}

.btn-group-label {
  font-size: 0.7rem;
  opacity: 0.7;
  white-space: nowrap;
  min-width: 5rem;
}

.btn-group-item .select,
.btn-group-item .checkbox {
  flex: 1;
}

/* Section title in menu */
.btn-group-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.5;
  padding: 0.5rem 0.5rem 0.25rem;
  margin-top: 0.25rem;
}

.btn-group-section-title:first-child {
  margin-top: 0;
  padding-top: 0.25rem;
}

/* Divider in menu */
.btn-group-menu .divider {
  margin: 0.25rem 0;
  border-color: oklch(var(--bc) / 0.1);
}

/* ==================== BOTTOM LEFT STACK (legend + stats) ==================== */

.bottom-left-stack {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  top: 4rem; /* Below title bar */
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.5rem;
  align-items: flex-start;
  pointer-events: none;
}

.bottom-left-stack > * {
  pointer-events: auto;
}

/* ==================== LEGEND (bottom-left) ==================== */

.legend {
  max-width: 560px;
  border: 1px solid oklch(var(--bc) / 0.15);
}

.legend .card-body {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.75rem;
  position: relative;
}

.legend-header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.legend-section {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.legend-collapsed {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.legend-collapsed.hidden {
  display: none;
}

.legend-toggle-btn {
  padding: 0 0.25rem;
  min-height: 1.25rem;
  height: 1.25rem;
  font-size: 1rem;
  margin-left: auto;
}

.legend-content {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 1.5rem;
}

.legend-content.hidden {
  display: none;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
}

.legend-color {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Split color swatch showing employee (top-left) and contractor (bottom-right) */
.legend-color-split {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.legend-color-split::before,
.legend-color-split::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
}

/* Top-left triangle (employee) */
.legend-color-split::before {
  top: 0;
  left: 0;
  border-style: solid;
  border-width: 18px 18px 0 0;
  border-color: var(--employee-color) transparent transparent transparent;
}

/* Bottom-right triangle (contractor) */
.legend-color-split::after {
  bottom: 0;
  right: 0;
  border-style: solid;
  border-width: 0 0 18px 18px;
  border-color: transparent transparent var(--contractor-color) transparent;
}

.legend-border {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid currentColor;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  background-color: var(--scope-bg, #f0ede5);
}

[data-theme="dark"] .legend-border {
  background-color: #2d2f38;
}

.legend-border.dashed {
  border-style: dashed;
}

.legend-border.dotted {
  border-style: dotted;
}

/* Pattern backgrounds for type swatches */
.legend-border.pattern-stripes {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 40' width='80' height='40'%3E%3Cpath fill='%239C92AC' fill-opacity='0.6' d='M0 40a19.96 19.96 0 0 1 5.9-14.11 20.17 20.17 0 0 1 19.44-5.2A20 20 0 0 1 20.2 40H0zM65.32.75A20.02 20.02 0 0 1 40.8 25.26 20.02 20.02 0 0 1 65.32.76zM.07 0h20.1l-.08.07A20.02 20.02 0 0 1 .75 5.25 20.08 20.08 0 0 1 .07 0zm1.94 40h2.53l4.26-4.24v-9.78A17.96 17.96 0 0 0 2 40zm5.38 0h9.8a17.98 17.98 0 0 0 6.67-16.42L7.4 40zm3.43-15.42v9.17l11.62-11.59c-3.97-.5-8.08.3-11.62 2.42zm32.86-.78A18 18 0 0 0 63.85 3.63L43.68 23.8zm7.2-19.17v9.15L62.43 2.22c-3.96-.5-8.05.3-11.57 2.4zm-3.49 2.72c-4.1 4.1-5.81 9.69-5.13 15.03l6.61-6.6V6.02c-.51.41-1 .85-1.48 1.33zM17.18 0H7.42L3.64 3.78A18 18 0 0 0 17.18 0zM2.08 0c-.01.8.04 1.58.14 2.37L4.59 0H2.07z'%3E%3C/path%3E%3C/svg%3E");
  background-size: 20px 10px;
}

.legend-border.pattern-dots {
  background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%239C92AC' fill-opacity='0.65' fill-rule='evenodd'%3E%3Ccircle cx='3' cy='3' r='3'/%3E%3Ccircle cx='13' cy='13' r='3'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 6px 6px;
}

.legend-border.pattern-crosshatch {
  background-image: url("data:image/svg+xml,%3Csvg width='64' height='64' viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 16c4.418 0 8-3.582 8-8s-3.582-8-8-8-8 3.582-8 8 3.582 8 8 8zm0-2c3.314 0 6-2.686 6-6s-2.686-6-6-6-6 2.686-6 6 2.686 6 6 6zm33.414-6l5.95-5.95L45.95.636 40 6.586 34.05.636 32.636 2.05 38.586 8l-5.95 5.95 1.414 1.414L40 9.414l5.95 5.95 1.414-1.414L41.414 8zM40 48c4.418 0 8-3.582 8-8s-3.582-8-8-8-8 3.582-8 8 3.582 8 8 8zm0-2c3.314 0 6-2.686 6-6s-2.686-6-6-6-6 2.686-6 6 2.686 6 6 6zM9.414 40l5.95-5.95-1.414-1.414L8 38.586l-5.95-5.95L.636 34.05 6.586 40l-5.95 5.95 1.414 1.414L8 41.414l5.95 5.95 1.414-1.414L9.414 40z' fill='%23a3a9b4' fill-opacity='0.6' fill-rule='evenodd'/%3E%3C/svg%3E");
  background-size: 16px 16px;
}

/* Scope type icons */
.legend-scope-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 16px;
  font-size: 14px;
  opacity: 0.8;
  flex-shrink: 0;
}

/* SVG scope type icons in legend */
.legend-scope-svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--fallback-bc, oklch(var(--bc) / 0.7));
}

.legend-scope-svg.infinity {
  width: 18px;
  height: 10px;
}

/* Octagon swatch for domain types */
.legend-hexagon {
  width: 18px;
  height: 16px;
  flex-shrink: 0;
  clip-path: polygon(25% 0%, 75% 0%, 100% 25%, 100% 75%, 75% 100%, 25% 100%, 0% 75%, 0% 25%);
}

/* Domain type colors - light mode (darker pastels) */
/* Blue = services, Green = apps, Orange = other */
.legend-hexagon[data-domain-type="cloud-service"] {
  background-color: #4a7098;
}
.legend-hexagon[data-domain-type="on-premise-service"] {
  background-color: #6088a8;
}
.legend-hexagon[data-domain-type="web-app"] {
  background-color: #4a8868;
}
.legend-hexagon[data-domain-type="mobile"] {
  background-color: #60a080;
}
.legend-hexagon[data-domain-type="integration"] {
  background-color: #b88050;
}

/* Domain type colors - dark mode (lighter pastels) */
[data-theme="dark"] .legend-hexagon[data-domain-type="cloud-service"] {
  background-color: #88b8d8;
}
[data-theme="dark"] .legend-hexagon[data-domain-type="on-premise-service"] {
  background-color: #a0c8e0;
}
[data-theme="dark"] .legend-hexagon[data-domain-type="web-app"] {
  background-color: #88c0a0;
}
[data-theme="dark"] .legend-hexagon[data-domain-type="mobile"] {
  background-color: #a0d0b8;
}
[data-theme="dark"] .legend-hexagon[data-domain-type="integration"] {
  background-color: #e0b088;
}

/* ==================== FILTER PANEL ==================== */

.filter-panel {
  width: 320px;
  border: 1px solid oklch(var(--bc) / 0.2);
  font-size: 0.75rem;
  background-color: oklch(var(--b2));
}

.filter-panel .card-body {
  padding: 0.75rem;
}

.filter-section {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid oklch(var(--bc) / 0.1);
}

.filter-section:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.filter-section-header {
  margin-bottom: 0.5rem;
}

.filter-chips {
  gap: 0.25rem;
}

.filter-chip {
  font-size: 0.65rem;
  height: 1.5rem;
  min-height: 1.5rem;
  padding: 0 0.5rem;
  border-radius: 9999px;
}

.filter-chip.btn-active {
  background-color: oklch(var(--p));
  border-color: oklch(var(--p));
  color: oklch(var(--pc));
}

.filter-toggles {
  gap: 0.5rem;
}

.filter-toggle select {
  font-size: 0.65rem;
  height: 1.75rem;
  min-height: 1.75rem;
  padding-left: 0.5rem;
  padding-right: 1.5rem;
}

/* Filter badge in header */
#filterBtn .filter-badge {
  font-size: 0.6rem;
  padding: 0 0.3rem;
  height: 1rem;
  min-height: 1rem;
}

#filterBtn.btn-active {
  background-color: oklch(var(--p) / 0.2);
}

/* ==================== STATS PANEL ==================== */

.stats-panel {
  border: 1px solid oklch(var(--bc) / 0.15);
  font-size: 0.75rem;
  max-height: 100%;
  overflow-y: auto;
  flex-shrink: 1;
}

.stats-panel .card-body {
  padding: 0.5rem 0.75rem;
}

.stats-collapsed {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.stats-content {
  width: 320px;
}

.stats-collapsed.hidden {
  display: none;
}

.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.stats-title {
  font-weight: 600;
  font-size: 0.8rem;
}

.stats-content.hidden {
  display: none;
}

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stats-block {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.stats-block-title {
  font-weight: 600;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.6;
}

.stats-block-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.125rem;
}

.stats-block-header .stats-block-title {
  margin-bottom: 0;
  flex-shrink: 0;
}

.stats-hr {
  flex: 1;
  border: none;
  border-top: 1px solid oklch(var(--bc) / 0.15);
  margin: 0;
}

.stats-block-total {
  font-weight: 600;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.125rem 0;
}

.stats-label {
  opacity: 0.7;
}

.stats-value {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.stats-row.stats-warn .stats-value {
  color: #dc2626;
  font-weight: 600;
}

.stats-health {
  padding: 0.25rem 0.5rem;
  background: oklch(var(--er) / 0.1);
  border-radius: 0.25rem;
}

.stats-health-items {
  font-size: 0.7rem;
}

.stats-list-items {
  font-size: 0.7rem;
  opacity: 0.8;
  line-height: 1.4;
}

/* Appetite distribution bar */
.stats-appetite {
  margin-top: 0.25rem;
}

.appetite-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin: 0.25rem 0;
}

.appetite-bar-segment {
  transition: width 0.3s ease;
}

.appetite-legend {
  display: flex;
  gap: 0.5rem;
  font-size: 0.65rem;
  opacity: 0.7;
}

.appetite-legend-item {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.appetite-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

/* Adjust legend position when stats panel is visible */
.legend.with-stats {
  bottom: auto;
  top: 1rem;
}

/* ==================== SIDE PANEL ==================== */

.side-panel {
  position: fixed;
  right: -420px;
  top: 1rem; /* Align with floating header */
  bottom: 70px; /* Leave space for controls */
  width: 400px;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  margin-right: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid oklch(var(--bc) / 0.15);
}

.side-panel.open {
  right: 0;
}

/* ==================== SETTINGS MODAL ==================== */

.settings-modal {
  position: fixed;
  inset: 0;
  background: oklch(0% 0 0 / 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.settings-modal.open {
  opacity: 1;
  visibility: visible;
}

.settings-container {
  width: 560px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}

.settings-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings-options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.settings-options-row .form-option {
  flex: 1;
  min-width: 140px;
}

.settings-options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}

.form-option {
  display: flex;
  align-items: flex-start;
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: oklch(var(--b3) / 0.2);
  gap: 0.75rem;
}

.form-option:hover {
  background: oklch(var(--b3) / 0.3);
}

.side-panel .card-body {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  padding-bottom: 0;
}

.panel-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Sticky button footer in forms */
.panel-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.panel-form-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem;
  min-height: 0;
}

.panel-form-actions {
  flex-shrink: 0;
  padding: 1rem 0 0.5rem 0;
  margin-top: 1rem;
  border-top: 1px solid oklch(var(--bc) / 0.1);
  display: flex;
  gap: 0.5rem;
}

/* Make entire button clickable (icons/emoji should not block clicks) */
.btn {
  position: relative;
}

.btn svg,
.btn span,
.btn::before,
.btn::after,
.btn > * {
  pointer-events: none;
}

/* Double-click delete button styles */
.btn-error.armed {
  animation: pulse-error 0.5s ease-in-out infinite;
  background: oklch(var(--er) / 0.9) !important;
}

@keyframes pulse-error {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* ==================== QUOTE ==================== */

.quote {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
}

/* ==================== LENS BUTTONS ==================== */

.lens-btn {
  background: oklch(var(--b1));
  border: 1px solid oklch(var(--bc) / 0.2);
}

.lens-btn:hover {
  background: oklch(var(--b2));
}

.lens-btn.active {
  background: oklch(var(--p)) !important;
  color: oklch(var(--pc)) !important;
  border-color: oklch(var(--p)) !important;
}

/* ==================== GLOBAL SEARCH ==================== */

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: oklch(var(--b2) / 0.95);
  backdrop-filter: blur(8px);
  color: oklch(var(--bc));
  border: 1px solid oklch(var(--bc) / 0.15);
  border-radius: 0.5rem;
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 1000;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

.search-results.visible {
  display: block;
}

.search-result-item {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-bottom: 1px solid oklch(var(--bc) / 0.1);
  transition: background 0.15s;
  color: oklch(var(--bc));
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.selected {
  background: oklch(var(--p) / 0.15);
}

.search-result-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  flex-shrink: 0;
}

.search-result-icon.person {
  background: #f090ff;
  color: #1f2937;
}

.search-result-icon.scope {
  background: #A2C382;
  color: #1f2937;
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-weight: 500;
  font-size: 0.8rem;
  color: oklch(var(--bc));
}

.search-result-meta {
  font-size: 0.7rem;
  color: oklch(var(--bc) / 0.6);
}

.search-result-detail {
  font-size: 0.65rem;
  color: oklch(var(--bc) / 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* ==================== SEARCHABLE MULTI-SELECT ==================== */

.searchable-multi-select {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.searchable-multi-select .options-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid oklch(var(--bc) / 0.15);
  border-radius: 0.375rem;
  background: oklch(var(--b1));
}

[data-theme="dark"] .searchable-multi-select .options-list {
  background: oklch(var(--b2));
}

.form-multi-option,
.form-allocation-option,
.form-lead-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.form-multi-option:hover,
.form-allocation-option:hover,
.form-lead-option:hover {
  background: oklch(var(--b2));
}

[data-theme="dark"] .form-multi-option:hover,
[data-theme="dark"] .form-allocation-option:hover,
[data-theme="dark"] .form-lead-option:hover {
  background: oklch(var(--b3));
}

.form-multi-option.hidden,
.form-allocation-option.hidden,
.form-lead-option.hidden {
  display: none;
}

.form-allocation-option .scope-name,
.form-lead-option .scope-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sole lead toggle in leads list */
.sole-lead-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
  padding-left: 0.5rem;
}

.sole-lead-toggle.disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* ==================== FORM SECTIONS ==================== */

.form-section {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid oklch(var(--bc) / 0.1);
}

.form-section:last-of-type {
  border-bottom: none;
  margin-bottom: 0.5rem;
}

.form-group.vertical {
  display: flex;
  flex-direction: column;
}

.form-group.hidden {
  display: none;
}

/* ==================== SVG/D3 SPECIFIC ==================== */

.connection {
  fill: none;
  pointer-events: none;
}

.node-shape {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.ghost-indicator {
  pointer-events: none;
}

.group-bg {
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.2));
}

/* ==================== DRAG AND DROP OVERLAY ==================== */

.drop-overlay {
  position: fixed;
  inset: 0;
  background: oklch(var(--b1) / 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.drop-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.drop-overlay-content {
  text-align: center;
  padding: 3rem;
  border: 3px dashed oklch(var(--p));
  border-radius: 1rem;
  background: oklch(var(--b2));
}

.drop-overlay-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.drop-overlay-text {
  font-size: 1.25rem;
  font-weight: 500;
}

/* ==================== DROP NOTIFICATION ==================== */

.drop-notification {
  position: fixed;
  top: 5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  z-index: 10000;
  animation: slideDown 0.3s ease-out;
}

.drop-notification.success {
  background: oklch(var(--su));
  color: oklch(var(--suc));
}

.drop-notification.error {
  background: oklch(var(--er));
  color: oklch(var(--erc));
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ==================== DATA EDITOR MODAL ==================== */

.data-editor-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.data-editor-modal.open {
  opacity: 1;
  visibility: visible;
}

.data-editor-container {
  width: calc(100vw - 24px);
  height: calc(100vh - 24px);
  background: oklch(var(--b2));
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.data-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid oklch(var(--b3));
  background: oklch(var(--b1));
}

.data-editor-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.data-editor-title h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.data-editor-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.data-editor-tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid oklch(var(--b3));
  background: oklch(var(--b1));
}

.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: oklch(var(--bc) / 0.6);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover {
  color: oklch(var(--bc));
  background: oklch(var(--b2));
}

.tab-btn.active {
  color: oklch(var(--p));
  border-bottom-color: oklch(var(--p));
}

.data-editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: oklch(var(--b2));
  border-bottom: 1px solid oklch(var(--b3));
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-box input {
  width: 250px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.data-editor-content {
  flex: 1;
  overflow: auto;
  padding: 0;
}

.table-container {
  min-height: 100%;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: oklch(var(--b1));
}

.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: oklch(var(--bc) / 0.7);
  border-bottom: 1px solid oklch(var(--b3));
  white-space: nowrap;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.data-table th.sortable:hover {
  color: oklch(var(--bc));
  background: oklch(var(--b2));
}

.data-table td {
  padding: 8px 16px;
  border-bottom: 1px solid oklch(var(--b3) / 0.5);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: oklch(var(--b3) / 0.3);
}

.data-table .cell-readonly {
  color: oklch(var(--bc) / 0.6);
}

.data-table .editable-cell,
.data-table .editable-select {
  background: oklch(var(--b1));
}

.data-table .actions-cell {
  text-align: center;
}

/* Typeahead styles */
.typeahead-cell {
  position: relative;
}

.typeahead-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: oklch(var(--b1));
  border: 1px solid oklch(var(--b3));
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 10;
  margin-top: 2px;
}

.typeahead-dropdown.hidden {
  display: none;
}

.typeahead-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid oklch(var(--b3) / 0.5);
}

.typeahead-item:last-child {
  border-bottom: none;
}

.typeahead-item:hover,
.typeahead-item.selected {
  background: oklch(var(--p) / 0.15);
}

.typeahead-name {
  font-weight: 500;
  font-size: 0.875rem;
  flex: 1;
}

.typeahead-id {
  font-size: 0.75rem;
  color: oklch(var(--bc) / 0.5);
  font-family: monospace;
}

.typeahead-label {
  font-size: 0.75rem;
  color: oklch(var(--bc) / 0.6);
}

.data-editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-top: 1px solid oklch(var(--b3));
  background: oklch(var(--b1));
}

.row-count {
  color: oklch(var(--bc) / 0.6);
  font-size: 0.875rem;
}

.footer-actions {
  display: flex;
  gap: 8px;
}

/* History Panel */
.history-panel {
  position: fixed;
  right: -360px;
  top: 24px;
  bottom: 24px;
  width: 340px;
  background: oklch(var(--b2));
  border-radius: 12px 0 0 12px;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  z-index: 2001;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.history-panel.open {
  right: 0;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid oklch(var(--b3));
}

.history-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.history-timeline {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.history-date {
  font-size: 0.75rem;
  font-weight: 600;
  color: oklch(var(--bc) / 0.5);
  margin: 16px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-date:first-child {
  margin-top: 0;
}

.history-item {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 4px;
}

.history-item:hover {
  background: oklch(var(--b3) / 0.3);
}

.history-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: oklch(var(--b3));
  border-radius: 6px;
  color: oklch(var(--bc) / 0.7);
}

.history-content {
  flex: 1;
  min-width: 0;
}

.history-desc {
  font-size: 0.875rem;
  color: oklch(var(--bc));
  word-break: break-word;
}

.history-time {
  font-size: 0.75rem;
  color: oklch(var(--bc) / 0.5);
  margin-top: 2px;
}

.history-empty {
  text-align: center;
  color: oklch(var(--bc) / 0.5);
  padding: 40px 20px;
}

.history-actions {
  padding: 12px 16px;
  border-top: 1px solid oklch(var(--b3));
}

/* Long-press delete progress ring */
.delete-row-btn {
  position: relative;
}

.delete-row-btn {
  position: relative;
}

/* Delete button confirmation animation */
@keyframes pulse-delete {
  0%, 100% { 
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.6);
  }
  50% { 
    transform: scale(1.15);
    box-shadow: 0 0 0 6px rgba(248, 113, 113, 0.3);
  }
}

@keyframes pulse-delete-error {
  0%, 100% { 
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.6);
  }
  50% { 
    transform: scale(1.05);
    box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.3);
  }
}

/* Data editor table delete button - armed state */
.delete-row-btn.armed {
  animation: pulse-delete 0.5s ease-in-out infinite;
  background-color: rgba(248, 113, 113, 0.15) !important;
  border: 2px solid #f87171 !important;
  border-radius: 50%;
}

/* Side panel delete button - armed state */
.btn-error.armed {
  animation: pulse-delete-error 0.5s ease-in-out infinite;
  background-color: rgba(248, 113, 113, 0.3) !important;
  border-color: #f87171 !important;
}

/* ==================== NO DATA MODAL ==================== */

.no-data-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: oklch(var(--b1) / 0.9);
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.no-data-modal.visible {
  opacity: 1;
  visibility: visible;
}

.no-data-container {
  max-width: 400px;
  border: 1px solid oklch(var(--bc) / 0.2);
}

.no-data-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.no-data-dropzone {
  width: 100%;
  padding: 2rem 1.5rem;
  border: 2px dashed oklch(var(--bc) / 0.2);
  border-radius: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.no-data-dropzone:hover {
  border-color: oklch(var(--p) / 0.5);
  background: oklch(var(--p) / 0.05);
}

.no-data-dropzone.dragover {
  border-color: oklch(var(--p));
  background: oklch(var(--p) / 0.1);
  border-style: solid;
}

.no-data-dropzone svg {
  transition: transform 0.2s;
}

.no-data-dropzone:hover svg,
.no-data-dropzone.dragover svg {
  transform: translateY(-2px);
  opacity: 0.7;
}

/* Column visibility dropdown */
#columnsMenu {
  max-height: 400px;
  overflow-y: auto;
}

#columnsMenu label {
  white-space: nowrap;
}

/* ==================== PROJECT AUTH ==================== */

.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: oklch(var(--b1));
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
  background: oklch(var(--b2));
  border-radius: 1rem;
  border: 1px solid oklch(var(--bc) / 0.1);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo {
  margin: 0 auto 1rem;
}

.auth-header h1 {
  font-size: 1.875rem;
  font-weight: 700;
  color: oklch(var(--bc));
  margin: 0;
}

.auth-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: oklch(var(--bc));
  margin: 0;
}

.auth-subtitle {
  font-size: 0.875rem;
  color: oklch(var(--bc) / 0.6);
  margin-top: 0.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: oklch(var(--bc));
}

.form-group input[type="text"],
.form-group input[type="password"] {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  background: oklch(var(--b1));
  border: 1px solid oklch(var(--bc) / 0.2);
  border-radius: 0.5rem;
  color: oklch(var(--bc));
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: oklch(var(--p));
}

.form-group small {
  font-size: 0.75rem;
  color: oklch(var(--bc) / 0.5);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
}

.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-primary {
  background: oklch(var(--p));
  color: oklch(var(--pc));
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: oklch(var(--b3));
  color: oklch(var(--bc));
}

.btn-secondary:hover {
  background: oklch(var(--b1));
}

.btn-ghost {
  background: transparent;
  color: oklch(var(--bc) / 0.7);
}

.btn-ghost:hover {
  color: oklch(var(--bc));
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0;
  color: oklch(var(--bc) / 0.4);
  font-size: 0.875rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: oklch(var(--bc) / 0.2);
}

.auth-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 2px solid oklch(var(--bc) / 0.2);
  border-top-color: oklch(var(--p));
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-error {
  background: oklch(var(--er));
  color: oklch(var(--erc));
}

.toast-success {
  background: oklch(var(--su));
  color: oklch(var(--suc));
}

/* Save status indicator */
.save-status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.7;
  vertical-align: middle;
}

.save-status-indicator.saving {
  color: oklch(var(--wa));
}

.save-status-indicator.saved {
  color: oklch(var(--su));
}

.save-status-indicator.error {
  color: oklch(var(--er));
  cursor: help;
}

.spinner-tiny {
  width: 12px;
  height: 12px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

/* Read-only input styling */
.input-readonly {
  background: oklch(var(--b1) / 0.5) !important;
  color: oklch(var(--bc) / 0.7);
  cursor: not-allowed;
  font-family: monospace;
  letter-spacing: 0.05em;
}

/* Full-width button */
.btn-block {
  width: 100%;
}

/* Success icon */
.success-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: oklch(var(--su));
  color: oklch(var(--suc));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 1rem;
}

/* Share URL box */
.project-share-info {
  margin: 1.5rem 0;
}

.project-share-info label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: oklch(var(--bc));
}

.share-url-box {
  display: flex;
  gap: 0.5rem;
}

.share-url-box input {
  flex: 1;
  font-size: 0.75rem;
}

.project-share-info small {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: oklch(var(--bc) / 0.6);
}

.project-share-info code {
  background: oklch(var(--b1));
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-family: monospace;
}

/* Empty project modal */
.empty-project-modal {
  position: fixed;
  inset: 0;
  background: oklch(var(--b1) / 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.empty-project-card {
  background: oklch(var(--b2));
  padding: 2rem;
  border-radius: 1rem;
  text-align: center;
  max-width: 400px;
  border: 1px solid oklch(var(--bc) / 0.1);
}

.empty-project-card h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: oklch(var(--bc));
}

.empty-project-card p {
  color: oklch(var(--bc) / 0.7);
  margin-bottom: 1.5rem;
}

.empty-project-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* Toast success variant */
.toast-success {
  background: oklch(var(--su));
  color: oklch(var(--suc));
}

/* Error icon */
.error-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: oklch(var(--er));
  color: oklch(var(--erc));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: bold;
  margin: 0 auto 1rem;
}

/* ==================== VERSION SELECTOR ==================== */

#version-selector {
  position: relative;
}

#version-selector .dropdown-content {
  max-height: 400px;
  overflow-y: auto;
}

.version-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-radius: 0.375rem;
}

.version-item:hover {
  background: oklch(var(--b3));
}

.version-item.active {
  background: oklch(var(--p) / 0.15);
}

.version-item-new {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-radius: 0.375rem;
}

.version-item-new:hover {
  background: oklch(var(--p) / 0.1);
}

/* ==================== UNIFIED TIMELINE ==================== */

.timeline-container {
  position: relative;
  padding-left: 24px;
}

.timeline-container::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: oklch(var(--bc) / 0.2);
}

.timeline-item {
  position: relative;
  padding: 0.5rem 0;
  display: flex;
  gap: 0.75rem;
}

.timeline-marker {
  position: absolute;
  left: -20px;
  top: 0.75rem;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  z-index: 1;
}

.timeline-item.savepoint .timeline-marker,
.timeline-item.version .timeline-marker {
  width: 20px;
  height: 20px;
  left: -24px;
  font-size: 10px;
  background: oklch(var(--su)) !important;
}

.timeline-content {
  flex: 1;
  background: oklch(var(--b3) / 0.5);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid oklch(var(--bc) / 0.1);
}

.timeline-item.unsaved .timeline-content {
  border-left: 3px solid oklch(var(--wa));
}

.timeline-item.version .timeline-content {
  border-left: 3px solid oklch(var(--su));
}

.timeline-item.version.current .timeline-content {
  background: oklch(var(--su) / 0.1);
  border-color: oklch(var(--su) / 0.3);
}

.timeline-item.savepoint .timeline-content {
  background: oklch(var(--su) / 0.05);
  border: 1px dashed oklch(var(--su) / 0.3);
  padding: 0.25rem 0.75rem;
}
