/* ===================================================================
   toolbar.css  –  Top ribbon (tabs + button groups) & left tool strip
   =================================================================== */

/* ------------------------------------------------------------------ */
/*  Ribbon container                                                    */
/* ------------------------------------------------------------------ */
#ribbon {
    background: var(--bg-ribbon);
    flex-shrink: 0;
    user-select: none;
    position: relative;   /* anchor for #file-menu absolute positioning */
}

/* ------------------------------------------------------------------ */
/*  Tab row                                                             */
/* ------------------------------------------------------------------ */
#ribbon-tabs {
    display: flex;
    align-items: flex-end;
    height: var(--tab-height);
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border-color);
    padding: 0 4px;
    gap: 1px;
}

.ribbon-tab {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 14px;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    background: transparent;
    border-radius: 3px 3px 0 0;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    position: relative;
    border: 1px solid transparent;
    border-bottom: none;
    letter-spacing: 0.01em;
}

.ribbon-tab:hover {
    color: var(--text-primary);
    background: var(--hover-bg);
}

.ribbon-tab.active {
    color: var(--text-primary);
    background: var(--bg-ribbon);
    border-color: var(--border-color);
    /* Merge visually with ribbon body */
    margin-bottom: -1px;
}

.ribbon-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0; right: 0;
    height: 1px;
    background: var(--bg-ribbon);
}

/* ------------------------------------------------------------------ */
/*  Ribbon body – button panels                                        */
/* ------------------------------------------------------------------ */
#ribbon-body {
    display: flex;
    align-items: stretch;
    height: var(--ribbon-body-height);
    padding: 0 4px;
    gap: 1px;
    overflow: hidden;   /* clips content when ribbon is dragged short */
}

#ribbon-body.ribbon-libraries,
#ribbon-body.ribbon-referrals {
    height: auto;
    min-height: var(--ribbon-body-height);
    overflow: visible;
}

/* A panel is a named group of related buttons, e.g. "Draw", "Modify" */
.ribbon-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 48px;
    position: relative;
    padding: 4px 4px 0;
    border-right: 1px solid var(--border-color);
}

.ribbon-panel:last-child {
    border-right: none;
}

.ribbon-panel-buttons {
    display: flex;
    align-items: flex-start;
    gap: 2px;
    flex: 1;
}

/* Panel label at the bottom */
.ribbon-panel-label {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    text-align: center;
    padding: 2px 0 3px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ------------------------------------------------------------------ */
/*  Ribbon buttons                                                      */
/* ------------------------------------------------------------------ */
.ribbon-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 40px;
    padding: 4px 6px;
    border-radius: 3px;
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    transition: background 0.1s, color 0.1s;
    cursor: pointer;
    text-align: center;
}

.ribbon-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.ribbon-btn:active {
    background: #3c3c3c;
}

.ribbon-btn .btn-icon {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ribbon-btn .btn-icon svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ribbon-btn .btn-label {
    line-height: 1;
    white-space: nowrap;
}

/* Large ribbon button (single prominent action) */
.ribbon-btn.large {
    min-width: 48px;
    padding: 6px 8px;
}

.ribbon-btn.large .btn-icon {
    width: 28px;
    height: 28px;
}

.ribbon-btn.large .btn-icon svg {
    width: 24px;
    height: 24px;
}

/* Active / pressed state */
.ribbon-btn.active {
    background: rgba(0, 120, 212, 0.25);
    color: var(--text-accent);
}

/* ------------------------------------------------------------------ */
/*  Left tool strip                                                     */
/* ------------------------------------------------------------------ */
#left-toolbar {
    width: var(--toolbar-width);
    background: var(--bg-toolbar);
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    overflow: visible;   /* tooltips extend rightward */
    user-select: none;
}

/* Inner section — grows to fill, no scrolling */
#left-toolbar-scroll {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    flex: 1;
    overflow: hidden;
    width: 100%;
    user-select: none;
}

.tool-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--text-muted);
    transition: background 0.1s, color 0.1s;
    cursor: pointer;
    position: relative;
}

.tool-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.tool-btn.active {
    background: rgba(79, 195, 247, 0.18);
    color: #4fc3f7;
    box-shadow: inset 3px 0 0 0 #4fc3f7, inset 0 0 0 1px rgba(79, 195, 247, 0.3);
}

.tool-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Tooltip on hover */
.tool-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: #111;
    color: var(--text-primary);
    font-size: var(--fs-xs);
    padding: 3px 8px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 500;
    border: 1px solid var(--border-color);
}

.tool-btn:hover::after {
    opacity: 1;
}

/* Divider between tool groups */
.tool-divider {
    width: 24px;
    height: 1px;
    background: var(--border-color);
    margin: 3px 0;
}

/* Static tool section — transparent wrapper, inherits flex column layout */
#static-tool-section {
    display: contents;   /* children participate directly in parent flex flow */
}

/* ---- Quick access buttons in left toolbar ---- */
#qa-section {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
    gap: 2px;
    width: 100%;
    padding: 2px;
}

.qa-btn {
    width: 100%;
    justify-content: center;
    gap: 0;
    padding: 0;
}

/* Text abbreviation badge (for non-tool commands) */
.qa-abbrev {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: currentColor;
    text-transform: uppercase;
    line-height: 1;
    text-align: center;
}

/* Text label (only visible in wide mode) */
.qa-label {
    display: none;
    flex: 1;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

/* Drag handle — only visible in edit mode */
.qa-drag {
    display: none;
    flex-shrink: 0;
    font-size: 13px;
    color: #444;
    cursor: grab;
    padding: 0 2px;
    line-height: 1;
}
.qa-drag:hover { color: #888; }
/* Show drag handle when QA section is in edit mode */
#qa-section.qa-edit-mode .qa-drag { display: flex; }

/* Remove × button — top-right corner, only visible in settings mode */
.qa-remove {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    border-radius: 2px;
    color: #888;
    background: transparent;
    opacity: 0;
    transition: opacity 0.1s, background 0.1s, color 0.1s;
    cursor: pointer;
    pointer-events: none;
    user-select: none;
}
.qa-remove:hover {
    background: rgba(220,60,60,0.3);
    color: #ff6b6b;
}

/* Drag-and-drop states */
.qa-btn.qa-dragging { opacity: 0.4; }
.qa-btn.qa-drag-over { outline: 2px solid #4fc3f7; outline-offset: -2px; }

/* Edit mode: remove × always visible */
#qa-section.qa-edit-mode .qa-remove {
    opacity: 1;
    pointer-events: auto;
}

/* Wide mode: single column with text labels */
#left-toolbar.wide #qa-section {
    grid-template-columns: 1fr;
}
#left-toolbar.wide .qa-btn {
    justify-content: flex-start;
    padding: 0 8px;
    gap: 6px;
    height: 30px;
    width: 100%;
}
#left-toolbar.wide .qa-label { display: block; }
#left-toolbar.wide .qa-abbrev { font-size: 11px; min-width: 20px; text-align: center; }
#left-toolbar.wide .qa-remove { top: 7px; right: 4px; }

/* Settings button — pinned at the bottom of the toolbar */
#qa-settings-btn {
    flex-shrink: 0;
    width: 100%;
    border-top: 1px solid var(--border-color);
    border-radius: 0;
}
#left-toolbar.wide #qa-settings-btn {
    width: 100%;
}

/* ------------------------------------------------------------------ */
/*  Small (horizontal) ribbon buttons + column container               */
/* ------------------------------------------------------------------ */

/* Stacks 2-3 small buttons in a vertical column */
.ribbon-btn-col {
    display: flex;
    flex-direction: column;
    gap: 1px;
    align-self: stretch;
    justify-content: center;
}

/* Small: icon left + label right (one row) */
.ribbon-btn.small {
    flex-direction: row;
    justify-content: flex-start;
    gap: 5px;
    min-width: 84px;
    max-width: 130px;
    height: 17px;
    padding: 0 5px;
    text-align: left;
    font-size: var(--fs-xs);
}

.ribbon-btn.small .btn-icon {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

.ribbon-btn.small .btn-icon svg {
    width: 12px;
    height: 12px;
}
