/* ══════════════════════════════════════════════════════════════════════════════
   Fusion 360-style parametric ribbon toolbar
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── Layout: ribbon lives inside #app grid, row "ribbon" ───────────────────── */
.ribbon-bar {
  width: 100%;
  background: #1c2128;
  border-bottom: 2px solid #30363d;
  user-select: none;
  /* Visually attach to the header above it */
  border-top: 1px solid #21262d;
}

/* ── Toggle row (tabs + status + chevron) ───────────────────────────────────── */
.ribbon-toggle-row {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 34px;
  padding: 0 8px 0 0;
  background: #161b22;
  border-bottom: 1px solid #21262d;
}

/* ── Category tabs ─────────────────────────────────────────────────────────── */
.ribbon-tabs {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 0;
}

.ribbon-tab {
  border: none;
  border-right: 1px solid transparent;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #8b949e;
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 0 14px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  white-space: nowrap;
}

.ribbon-tab:hover {
  color: #e6edf3;
  background: #21262d;
}

.ribbon-tab.active {
  color: #e6edf3;
  border-bottom-color: #58a6ff;
  background: #21262d;
}

/* ── Status / right section ─────────────────────────────────────────────────── */
.ribbon-status-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 8px;
  min-width: 0;
  overflow: hidden;
}

/* ── View control buttons (far right of toggle row) ─────────────────────────── */
.ribbon-view-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  border-left: 1px solid #30363d;
  flex-shrink: 0;
}

.ribbon-view-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 3px 7px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #8b949e;
  cursor: pointer;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
  white-space: nowrap;
  line-height: 1;
}

.ribbon-view-btn:hover {
  color: #e6edf3;
  background: #21262d;
  border-color: #30363d;
}

.ribbon-view-btn.active,
.ribbon-view-btn[aria-pressed="true"] {
  color: #58a6ff;
  background: #1c2d3f;
  border-color: #1f6feb;
}

.ribbon-view-label {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.ribbon-status {
  font-size: 0.72rem;
  color: #8b949e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(400px, 50vw);
  cursor: default;
}

.ribbon-status.error {
  cursor: pointer;
}

.ribbon-status.loading { color: #d29922; }
.ribbon-status.ok      { color: #3fb950; }
.ribbon-status.error   { color: #f85149; }

.ribbon-status-copy {
  flex-shrink: 0;
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(248, 81, 73, 0.45);
  background: rgba(248, 81, 73, 0.12);
  color: #f85149;
  cursor: pointer;
}

.ribbon-status-copy:hover:not(:disabled) {
  background: rgba(248, 81, 73, 0.22);
}

.ribbon-status-copy--hidden {
  display: none;
}

/* ── Reset button ────────────────────────────────────────────────────────────── */
.ribbon-reset {
  font-size: 0.72rem;
  padding: 4px 10px;
  flex-shrink: 0;
}

/* ── Collapse chevron ────────────────────────────────────────────────────────── */
.ribbon-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: transparent;
  color: #8b949e;
  font-size: 0.9rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}

.ribbon-chevron:hover {
  background: #21262d;
  color: #e6edf3;
}

/* ── Body (collapsible) ──────────────────────────────────────────────────────── */
.ribbon-body {
  display: flex;
  align-items: flex-start;
  gap: 0;
  overflow: hidden;
  max-height: 120px;
  transition: max-height 0.22s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.22s ease;
  padding: 6px 8px;
  background: #1c2128;
}

.ribbon-body--collapsed {
  max-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-top-color: transparent;
}

/* ── Panels (one per category tab) ─────────────────────────────────────────── */
.ribbon-panels {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #30363d transparent;
}

.ribbon-panel {
  display: none;
  align-items: flex-start;
  flex-wrap: nowrap;
  gap: 4px;
  padding-right: 12px;
}

.ribbon-panel--active {
  display: flex;
}

/* ── Individual tool buttons ────────────────────────────────────────────────── */
.ribbon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 62px;
  min-width: 62px;
  padding: 6px 4px 5px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  color: #c9d1d9;
}

.ribbon-btn:hover {
  background: #21262d;
  border-color: #30363d;
  color: #e6edf3;
}

.ribbon-btn:active {
  background: #1f6feb33;
  border-color: #388bfd;
}

.rb-icon {
  font-size: 1.3rem;
  line-height: 1;
  display: block;
}

/* Raster/SVG tool icons (icon pack) */
img.rb-icon {
  width: 30px;
  height: 30px;
  object-fit: contain;
  display: block;
  pointer-events: none;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.ribbon-btn:hover img.rb-icon {
  transform: translateY(-1px) scale(1.05);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}

.ribbon-btn:active img.rb-icon {
  transform: translateY(0) scale(0.98);
}

.rb-label {
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: center;
}

/* ── Vertical dividers between button groups ───────────────────────────────── */
.ribbon-divider {
  width: 1px;
  align-self: stretch;
  background: #30363d;
  margin: 0 6px;
  flex-shrink: 0;
}

/* ── Feature tree ────────────────────────────────────────────────────────────── */
.ribbon-tree-wrap {
  flex-shrink: 0;
  width: 220px;
  border-left: 1px solid #30363d;
  padding-left: 10px;
  overflow-y: auto;
  max-height: 106px;
  scrollbar-width: thin;
  scrollbar-color: #30363d transparent;
}

.ribbon-tree-label {
  display: block;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8b949e;
  margin-bottom: 4px;
}

.feature-tree {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ft-empty {
  font-size: 0.68rem;
  color: #8b949e;
  font-style: italic;
  padding: 2px 0;
}

.ft-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 4px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 0.72rem;
  color: #c9d1d9;
  cursor: default;
  transition: background 0.1s;
}

.ft-item:hover {
  background: #21262d;
  border-color: #30363d;
}

.ft-icon {
  font-size: 0.82rem;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.ft-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ft-del {
  flex-shrink: 0;
  background: none;
  border: none;
  color: transparent;
  cursor: pointer;
  font-size: 0.65rem;
  padding: 0 2px;
  line-height: 1;
  border-radius: 3px;
  transition: color 0.1s;
}

.ft-item:hover .ft-del {
  color: #8b949e;
}

.ft-del:hover {
  color: #f85149 !important;
  background: #f8514918;
}

/* ══════════════════════════════════════════════════════════════════════════════
   Ribbon parameter dialog
   ══════════════════════════════════════════════════════════════════════════════ */
.ribbon-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ribbon-dialog {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  width: 360px;
  max-width: 96vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rdlg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid #21262d;
  flex-shrink: 0;
}

.rdlg-icon {
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
}

img.rdlg-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
}

.rdlg-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: #e6edf3;
  flex-shrink: 0;
}

.rdlg-desc {
  font-size: 0.72rem;
  color: #8b949e;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rdlg-close {
  background: none;
  border: none;
  color: #8b949e;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s;
}

.rdlg-close:hover {
  color: #f85149;
  background: #f8514918;
}

.rdlg-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.rdlg-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rdlg-row label {
  font-size: 0.75rem;
  color: #8b949e;
  margin: 0;
}

.rdlg-row input[type="number"],
.rdlg-row select {
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  color: #e6edf3;
  border-radius: 6px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 0.82rem;
  transition: border-color 0.15s;
}

.rdlg-row input[type="number"]:focus,
.rdlg-row select:focus {
  outline: none;
  border-color: #58a6ff;
  box-shadow: 0 0 0 2px #58a6ff22;
}

.rdlg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid #21262d;
  flex-shrink: 0;
}

.rdlg-tip {
  flex: 1;
  font-size: 0.68rem;
  color: #8b949e;
}

.rdlg-cancel,
.rdlg-ok {
  padding: 6px 16px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* ── Small scrollbar tweaks ──────────────────────────────────────────────────── */
.ribbon-panels::-webkit-scrollbar,
.ribbon-tree-wrap::-webkit-scrollbar,
.rdlg-form::-webkit-scrollbar {
  height: 5px;
  width: 5px;
}

.ribbon-panels::-webkit-scrollbar-thumb,
.ribbon-tree-wrap::-webkit-scrollbar-thumb,
.rdlg-form::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

/* ── Sketch environment (Fusion 360) ─────────────────────────────────────── */
.ribbon-btn--finish-sketch {
  background: linear-gradient(180deg, #3d9a47 0%, #2d7a35 100%) !important;
  border-color: #256b2c !important;
  color: #fff !important;
  min-width: 78px;
}

.ribbon-btn--finish-sketch:hover {
  background: linear-gradient(180deg, #47ad52 0%, #32853c 100%) !important;
  border-color: #2d8a38 !important;
  color: #fff !important;
}

.ribbon-btn--finish-sketch .rb-label {
  color: #fff !important;
  font-weight: 700;
}

.ribbon-btn--cancel-sketch {
  border-color: #bdbdbd !important;
}

.ribbon-btn.ribbon-btn--active {
  background: #e8f2fc !important;
  border-color: #0066cc !important;
  color: #0066cc !important;
}

.ribbon-btn.ribbon-btn--active .rb-label {
  color: #0066cc !important;
}

.ribbon-btn.ribbon-btn--active .rb-icon {
  filter: none;
}

.rb-icon-sketch {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 4px;
  background: #e8f2fc;
  color: #0066cc;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.ribbon-btn:hover .rb-icon-sketch {
  background: #d6e9fa;
}
