/* Header, filename sizing, compact mobile chrome */

.header-frame {
    background-color: var(--brand-secondary);
    color: var(--brand-primary);
    width: 100%;
    min-height: var(--layout-header-h);
    height: auto;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    box-shadow: var(--shadow-light);
    border-top: 3px solid var(--color-error);
    border-bottom: 2px solid var(--brand-primary);
    padding-top: var(--safe-top);
    box-sizing: border-box;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    max-width: var(--layout-max);
    min-height: calc(var(--layout-header-h) - 5px);
    margin: 0 auto;
    padding: 8px 14px;
    gap: 10px;
    box-sizing: border-box;
}

.header-left,
.header-center,
.header-right {
    display: flex;
    align-items: center;
}

.header-left {
    flex: 1 1 0;
    min-width: 0;
    gap: 8px;
}

.header-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.header-center {
    flex: 0 0 auto;
    justify-content: center;
}

.header-right {
    flex: 1 1 0;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}

.brand-mark-hindi {
    font-family: 'Noto Sans Devanagari', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--brand-primary);
    white-space: nowrap;
    letter-spacing: 0.02em;
    line-height: 1;
    flex-shrink: 0;
}

.doc-name-cluster {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1 1 140px;
    max-width: 420px;
}

/* Sync / new live in History */
.header-left > .drive-control,
.header-left > .add-template-btn {
    display: none;
}

.filename-resize-wrap {
    position: relative;
    display: inline-grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    flex: 0 1 auto;
    width: clamp(100px, var(--filename-w, 140px), var(--filename-max, 420px));
    min-width: 100px;
    max-width: min(420px, 100%);
    height: 36px;
    overflow: hidden;
    box-sizing: border-box;
    resize: none;
}

.filename-sizer {
    position: absolute;
    left: 0;
    top: 0;
    visibility: hidden;
    white-space: pre;
    font-family: "Roboto", Helvetica, sans-serif;
    font-size: 14px;
    font-weight: 500;
    padding: 0 12px;
    pointer-events: none;
    height: 36px;
    line-height: 36px;
}

.filename-input {
    grid-area: 1 / 1;
    height: 36px;
    width: 100%;
    min-width: 0;
    padding: 0 12px;
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    font-family: "Roboto", Helvetica, sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-primary);
    background: var(--brand-white);
    box-shadow: var(--shadow-light);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
    text-overflow: ellipsis;
}

/* Narrow desktop / tablet: stay single-line, tighten chrome */
@media (max-width: 1100px) {
    .header-content {
        gap: 8px;
        padding: 8px 12px;
    }

    .brand-mark-hindi {
        display: none;
    }

    .doc-name-cluster {
        flex-basis: 120px;
        max-width: 280px;
    }

    .segment-btn {
        padding: 0 10px;
        font-size: 12px;
    }

    #exportBtn span:not(.btn-icon) {
        display: none;
    }

    #exportBtn {
        padding: 0;
        width: 36px;
        justify-content: center;
    }

    .header-left,
    .header-right {
        gap: 6px;
    }
}

@media (max-width: 900px) {
    .doc-name-cluster {
        max-width: 200px;
    }

    .segment-btn {
        padding: 0 8px;
    }

    .header-content {
        gap: 6px;
    }
}

/*
 * Mobile only (≤768px):
 *  [panel+logo LEFT] [spacer] [filename | Letter/Diary] [spacer] [PDF RIGHT]
 * Spacers share free width; PDF stays flush right like desktop header-right.
 */
@media (max-width: 768px) {
    .header-content {
        position: relative;
        display: flex;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
        padding: 8px 10px;
        gap: 8px;
    }

    .header-left,
    .header-center,
    .header-right {
        display: contents;
    }

    .header-brand {
        position: static;
        top: auto;
        left: auto;
        transform: none;
        order: 1;
        flex: 0 0 auto;
        gap: 6px;
    }

    .brand-mark-hindi {
        display: none;
    }

    /* Leading spacer — free space after the brand */
    .header-content::before {
        content: '';
        order: 2;
        flex: 1 1 0;
        min-width: 4px;
        max-width: 100%;
    }

    .doc-name-cluster {
        order: 3;
        flex: 0 1 auto;
        min-width: 0;
        max-width: min(160px, 32vw);
    }

    #templateSegment {
        order: 4;
        flex: 0 0 auto;
    }

    #langSegment {
        display: none !important;
    }

    .translit-toggle-wrapper {
        display: none !important;
    }

    /* Trailing spacer — pushes PDF to the right edge */
    .header-content::after {
        content: '';
        order: 5;
        flex: 1 1 0;
        min-width: 4px;
        max-width: 100%;
    }

    #exportBtn {
        display: inline-flex !important;
        order: 6;
        flex: 0 0 auto;
        width: 36px;
        padding: 0;
        justify-content: center;
        margin-left: 0;
    }

    #exportBtn span:not(.btn-icon) {
        display: none;
    }

    .segment-btn {
        padding: 0 10px;
        font-size: 12px;
    }
}

@media (max-width: 420px) {
    .header-content {
        padding: 8px 8px;
        gap: 6px;
    }

    .doc-name-cluster {
        max-width: min(120px, 28vw);
    }

    #templateSegment .segment-btn {
        padding: 0 8px;
        font-size: 11px;
    }
}
