/* Tab bar — browser-style diagram tabs */

.sf-tabs {
  display: flex;
  align-items: center;
  background: var(--bg-canvas);
  flex-shrink: 0;
  height: 36px;
  padding: 0 4px;
  gap: 2px;
  overflow: visible;
  position: relative;
}

.sf-tabs__list {
  display: flex;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  align-self: stretch;
}

.sf-tabs__list::-webkit-scrollbar {
  height: 0;
}

/* Individual tab */
.sf-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  margin-top: 4px;
  border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  max-width: 180px;
  min-width: 0;
  transition: background var(--transition-fast), color var(--transition-fast);
  position: relative;
  user-select: none;
}

.sf-tab:hover {
  background: var(--toolbar-button-hover);
  color: var(--text-secondary);
}

/* Active tab — side+top borders, NO bottom border */
.sf-tab--active {
  background: var(--bg-canvas);
  color: var(--text-primary);
  border-color: var(--border-color);
  border-bottom: none;
  font-weight: 600;
}

/* Bottom border line segments positioned by JS on .sf-tabs */
.sf-tab-line {
  position: absolute;
  bottom: 0;
  height: 1px;
  background: var(--border-color);
  pointer-events: none;
}

/* Tab drag-and-drop reorder */
.sf-tab--dragging {
  opacity: 0.4;
}

.sf-tab--drag-over {
  box-shadow: inset 2px 0 0 var(--color-primary);
}

.sf-tab__label {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Dot indicator for unsaved changes */
.sf-tab__dirty {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  display: none;
}

.sf-tab--dirty .sf-tab__dirty {
  display: block;
}

.sf-tab__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  opacity: 0;
  transition: opacity var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
}

.sf-tab:hover .sf-tab__close,
.sf-tab--active .sf-tab__close {
  opacity: 1;
}

.sf-tab__close:hover {
  background: var(--toolbar-button-hover);
  color: var(--text-primary);
}

/* New tab button */
.sf-tabs__new {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  margin-left: 8px;
  height: 28px;
  border: 1px dashed var(--color-primary);
  border-radius: var(--border-radius-sm);
  background: transparent;
  color: var(--color-primary);
  cursor: pointer;
  flex-shrink: 0;
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.sf-tabs__new:hover {
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  color: var(--color-primary);
  border-color: var(--color-primary);
  border-style: solid;
}

/* ── New Diagram Modal ─────────────────────────────────── */

.sf-new-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sf-new-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.sf-new-modal__dialog {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0,0,0,0.3));
  padding: 32px;
  max-width: 820px;
  width: 90vw;
}

.sf-new-modal__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 24px;
  text-align: center;
}

.sf-new-modal__grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
}

/* Top row: 3 cards, each spanning 2 columns */
.sf-new-modal__card:nth-child(1) { grid-column: 1 / 3; }
.sf-new-modal__card:nth-child(2) { grid-column: 3 / 5; }
.sf-new-modal__card:nth-child(3) { grid-column: 5 / 7; }
/* Bottom row: 2 cards centered */
.sf-new-modal__card:nth-child(4) { grid-column: 1 / 4; max-width: 220px; justify-self: end; }
.sf-new-modal__card:nth-child(5) { grid-column: 4 / 7; max-width: 220px; justify-self: start; }

.sf-new-modal__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-app);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  text-align: center;
  font-family: var(--font-family);
}

.sf-new-modal__card:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(29, 115, 201, 0.15);
  transform: translateY(-2px);
}

[data-theme="dark"] .sf-new-modal__card:hover {
  box-shadow: 0 0 0 3px rgba(218, 78, 85, 0.15);
}

.sf-new-modal__icon {
  width: 80px;
  height: 60px;
}

.sf-new-modal__card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.sf-new-modal__card-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Mobile tabs ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sf-tabs {
    height: 32px;
    padding: 0 2px;
  }

  .sf-tab {
    padding: 3px 6px;
    height: 26px;
    gap: 4px;
    max-width: 100px;
    font-size: var(--font-size-xs);
  }

  .sf-tab__close {
    width: 14px;
    height: 14px;
  }

  .sf-tabs__new {
    height: 24px;
    padding: 2px 8px;
    font-size: var(--font-size-xs);
  }

  .sf-tabs__new span {
    display: none;
  }
}

/* Diagram type icon in tab */
.sf-tab__type-icon {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  opacity: 0.6;
}
