/* =====================================================
   Header: Title Bar + Ribbon Tabs + Ribbon Panels
===================================================== */

/* ═══════════════════════════════════════════════════════════════
   HEADER  (Title Bar + Ribbon)
═══════════════════════════════════════════════════════════════ */
#header {
    flex-shrink: 0;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    z-index: 200;
    border-bottom: 1px solid var(--border);
    overflow: visible;
    /* MUST be visible so ribbon labels don't clip */
}

/* ─── Title Bar ───────────────────────────────────────────── */
.title-bar {
    height: var(--title-h);
    background: #ffffff;
    border-bottom: 2px solid #0000ff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    gap: 10px;
}

.title-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.title-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.logo-icon {
    width: 28px;
    height: 28px;
    background: #0000ff;
    color: white;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 15px;
    box-shadow: 0 2px 6px rgba(0, 0, 255, .35);
    letter-spacing: -1px;
}

.logo-text {
    color: #000000;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.title-sep {
    width: 1px;
    height: 22px;
    background: #d4d4d4;
    margin: 0 4px;
}

.project-name {
    border: 1px solid #d4d4d4;
    background: #f5f5f5;
    color: #000000;
    font-weight: 600;
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 5px;
    width: 200px;
    transition: all .2s;
}

.project-name::placeholder {
    color: #999;
}

.project-name:hover {
    border-color: #0000ff;
    background: #fff;
}

.project-name:focus {
    border-color: #0000ff;
    background: #fff;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 0, 255, .12);
}

/* Quick Access Toolbar */
.qat {
    display: flex;
    align-items: center;
    gap: 3px;
}

.qat-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 5px;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}

.qat-btn:hover {
    background: #ebebff;
    color: #0000ff;
}

.btn-tutorial {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    background: #ebebff;
    border: 1px solid #b3b3ff;
    border-radius: 5px;
    color: #0000ff;
    font-size: 12px;
    font-weight: 600;
    transition: all .15s;
}

.btn-tutorial:hover {
    background: #0000ff;
    color: white;
}

.btn-export-png,
.btn-export-pdf {
    padding: 5px 14px;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 700;
    transition: all .15s;
    cursor: pointer;
}

.btn-export-png {
    background: #ffffff;
    color: #0000ff;
    border: 1.5px solid #0000ff;
}

.btn-export-pdf {
    background: #ffffff;
    color: #000000;
    border: 1.5px solid #000000;
}

.btn-export-png:hover {
    background: #0000ff;
    color: white;
}

.btn-export-pdf:hover {
    background: #000000;
    color: white;
}

/* File Tab Styling */
.rtab-file {
    background: #0055ff !important;
    color: white !important;
    font-weight: 700;
    margin-right: 4px;
    border-radius: 4px 4px 0 0;
    border: none !important;
}

.rtab-file:hover {
    background: #0044cc !important;
}

/* File Dropdown Styling */
.file-menu-wrap {
    position: relative;
    display: flex;
    align-items: flex-end;
}

.file-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    min-width: 220px;
    padding: 8px;
    z-index: 10000;
    display: none;
    flex-direction: column;
    margin-top: 5px;
    animation: dropdownFadeIn 0.2s ease-out;
}

.file-dropdown.show {
    display: flex;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fd-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #334155;
    text-align: left;
    width: 100%;
    cursor: pointer;
    transition: all 0.15s;
}

.fd-item:hover {
    background: #f1f5f9;
    color: #0055ff;
}

.fd-item svg {
    color: #64748b;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.fd-item:hover svg {
    color: #0055ff;
}

.fd-sep {
    height: 1px;
    background: #f1f5f9;
    margin: 6px 8px;
}

/* ─── Ribbon Shell ────────────────────────────────────────── */
.ribbon-shell {
    background: var(--surface);
    overflow: visible;
    /* never clip group labels */
    position: relative;
}

/* Tab Strip */
.ribbon-tabs {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    padding: 0 8px;
    border-bottom: 1px solid var(--border);
    height: 32px;
}

.rtab {
    padding: 0 14px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    border-radius: 6px 6px 0 0;
    border-bottom: 2px solid transparent;
    transition: all .15s;
}

.rtab:hover {
    color: var(--blue);
    background: var(--blue-light);
}

.rtab.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
    background: white;
}

/* Ribbon Panel — compact, no overflow-y clipping */
.ribbon-panel {
    display: none;
    align-items: stretch;
    gap: 0;
    height: var(--ribbon-h);
    padding: 0 4px;
    overflow-x: auto;
    overflow-y: visible;
}

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

.ribbon-panel::-webkit-scrollbar {
    height: 3px;
}

.ribbon-panel::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: 3px;
}

.rg {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    padding: 0 6px;
    height: 100%;
    /* fill full ribbon height */
    justify-content: space-between;
    /* push label to bottom */
}

.rg:last-child {
    border-right: none;
}

.rg-body {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 1;
    padding: 4px 0 2px;
}

/* Group label: always pinned at bottom, never clipped */
.rg-label {
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    color: #444;
    /* Darker for better visibility */
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 4px 2px;
    flex-shrink: 0;
    border-top: 1px solid #e0e0e0;
    width: 100%;
    white-space: nowrap;
    background: #fdfdfd;
}

/* Large vertical button — COMPACT (icon top, text bottom, no overflow) */
.rb-large {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 8px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 6px;
    min-width: 48px;
    max-width: 62px;
    color: var(--text);
    font-size: 9.5px;
    font-weight: 600;
    transition: all .15s;
    height: 58px;
    /* reduced from 76px */
    overflow: hidden;
    /* prevent icon spill */
    white-space: nowrap;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.rb-large svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.rb-large span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
}

.rb-large:hover {
    background: var(--blue-light);
    border-color: var(--blue-mid);
    color: var(--blue);
}

.rb-large.active {
    background: var(--blue-light);
    border-color: var(--blue-mid);
    color: var(--blue);
}

.rb-large.rb-danger:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #dc2626;
}

/* Small horizontal button */
.rb-sm {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    transition: all .15s;
    white-space: nowrap;
}

.rb-sm svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.rb-sm:hover {
    background: var(--blue-light);
    border-color: var(--blue-mid);
    color: var(--blue);
}

/* Column of 2-3 small buttons */
.rb-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 62px;
    /* prevents text clipping in column layout */
}

/* Tiny xs button */
.rb-xs {
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid var(--border-2);
    background: white;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-2);
}

.rb-xs:hover {
    background: var(--blue-light);
    border-color: var(--blue-mid);
    color: var(--blue);
}

/* Format buttons (B I U S) */
.rb-fmt {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 5px;
    font-size: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}

.rb-fmt:hover {
    background: var(--blue-light);
    border-color: var(--blue-mid);
    color: var(--blue);
}

.rb-fmt.active {
    background: var(--blue-light);
    border-color: var(--blue);
    color: var(--blue);
}

/* Icon-only small button (alignment, lists) */
.rb-icon {
    width: 28px;
    height: 28px;
    padding: 4px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 5px;
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.rb-icon svg {
    width: 16px;
    height: 16px;
}

.rb-icon:hover {
    background: var(--blue-light);
    border-color: var(--blue-mid);
    color: var(--blue);
}

.rb-icon.active {
    background: var(--blue-light);
    border-color: var(--blue);
    color: var(--blue);
}

/* Ribbon selects */
.r-select {
    height: 26px;
    border: 1px solid var(--border-2);
    border-radius: 5px;
    font-size: 12px;
    padding: 0 6px;
    background: white;
    color: var(--text);
}

.r-select-lg {
    width: 130px;
}

.r-num {
    width: 52px;
    height: 26px;
    border: 1px solid var(--border-2);
    border-radius: 5px;
    font-size: 12px;
    text-align: center;
    padding: 0 4px;
}

.r-num:focus,
.r-select:focus {
    border-color: var(--blue);
    outline: none;
}

/* Ribbon divider */
.r-divider {
    width: 1px;
    height: 22px;
    background: var(--border-2);
    margin: 0 2px;
}

/* Ribbon checkbox */
.r-check {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    cursor: pointer;
}

.r-check input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--blue);
}

/* Color Swatch */
.color-swatch {
    position: relative;
    width: 30px;
    height: 28px;
    border: 1px solid var(--border-2);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: white;
    overflow: hidden;
    color: var(--text);
}

.color-swatch input[type="color"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.color-swatch:hover {
    border-color: var(--blue);
    background: var(--blue-light);
}

