/* 
    # Copyright (c) 2026 Deni Hamdani
    # SPDX-License-Identifier: MIT

    ============================================
    Sidebar, Merge Panel, Preview Panel, Modals
    ============================================ 
*/

/* ── HEADER ── */
.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.logo {
    font-size: 22px;
}

.app-title {
    font-size: var(--fs-heading-md);
    font-weight: var(--fw-bold);
}

.app-version {
    font-family: var(--font-mono);
    font-size: var(--fs-badge);
    color: var(--text-disabled);
    padding: 1px 6px;
    background: var(--bg-hover);
    border-radius: var(--r-sm);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ── SIDEBAR ── */
.sidebar-search {
    padding: var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-search input {
    width: 100%;
    height: 32px;
    padding: 0 var(--space-3);
    font-family: var(--font-sans);
    font-size: var(--fs-body-sm);
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--r-md);
    outline: none;
}

.sidebar-search input:focus {
    border-color: var(--border-focus);
}

.sidebar-section {
    border-bottom: 1px solid var(--border-subtle);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-3) var(--space-2);
}

.section-header h2 {
    font-size: var(--fs-body-sm);
    font-weight: var(--fw-semibold);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.item-list {
    list-style: none;
    padding: 0 var(--space-2) var(--space-2);
    max-height: 250px;
    overflow-y: auto;
}

.item-list li {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background var(--t-fast);
    position: relative;
}

.item-list li:hover {
    background: var(--bg-hover);
}

.item-list li:hover .item-menu-btn {
    opacity: 1;
}

.item-list li.selected {
    background: var(--bg-selected);
    border-left: 3px solid var(--blue-500);
    padding-left: calc(var(--space-3) - 3px);
}

.item-list li.selected .item-title {
    color: var(--blue-500);
}

.item-emoji {
    font-size: 16px;
    flex-shrink: 0;
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-title {
    font-size: var(--fs-body-sm);
    font-weight: var(--fw-medium);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-snippet {
    font-size: var(--fs-caption);
    color: var(--text-disabled);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-menu-btn {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 2px;
    font-size: 16px;
    transition: opacity var(--t-fast);
}

.item-menu-btn:hover {
    color: var(--text-primary);
}

.in-merge-badge {
    font-size: 9px;
    padding: 1px 4px;
    background: var(--yellow-100);
    color: var(--yellow-500);
    border-radius: var(--r-sm);
    font-weight: var(--fw-semibold);
}

.empty-state {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    color: var(--text-disabled);
    font-size: var(--fs-body-sm);
}

.empty-state p {
    margin-bottom: var(--space-2);
}

.empty-state .hint {
    font-size: var(--fs-caption);
    color: var(--text-disabled);
}

/* ── MERGE PANEL ── */
.merge-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.panel-header h2 {
    font-size: var(--fs-heading-sm);
    font-weight: var(--fw-semibold);
}

.merge-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.merge-items-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
}

.merge-items {
    list-style: none;
}

.merge-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-sm);
    margin-bottom: var(--space-1);
    background: var(--bg-base);
    transition: background var(--t-fast);
}

.merge-item:hover {
    background: var(--bg-hover);
}

.merge-item .drag-handle {
    color: var(--text-disabled);
    cursor: grab;
    font-size: 14px;
    user-select: none;
}

.merge-item .item-order {
    width: 24px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: var(--fs-badge);
    color: var(--text-disabled);
    font-weight: var(--fw-semibold);
}

.merge-item .item-type-icon {
    font-size: 14px;
}

.merge-item .item-name {
    flex: 1;
    font-size: var(--fs-body-sm);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.merge-item .item-tokens {
    font-family: var(--font-mono);
    font-size: var(--fs-caption);
    color: var(--text-tertiary);
}

.merge-item .move-btn {
    background: none;
    border: none;
    color: var(--text-disabled);
    cursor: pointer;
    padding: 2px;
    font-size: 12px;
}

.merge-item .move-btn:hover {
    color: var(--text-primary);
}

.merge-item .remove-btn {
    background: none;
    border: none;
    color: var(--text-disabled);
    cursor: pointer;
    padding: 2px;
    font-size: 14px;
}

.merge-item .remove-btn:hover {
    color: var(--red-500);
}

.merge-item.selected {
    background: var(--bg-selected);
    border-color: var(--blue-500);
}

.merge-item.selected .item-name {
    color: var(--blue-500);
}

.merge-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-disabled);
    gap: var(--space-2);
    text-align: center;
}

.merge-empty .hint {
    font-size: var(--fs-caption);
    color: var(--text-disabled);
}

.action-bar {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

/* ── PREVIEW PANEL ── */
.preview-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.preview-controls {
    display: flex;
    gap: var(--space-1);
}

.preview-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
}

.preview-content pre {
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    line-height: var(--lh-relaxed);
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

#preview-rendered {
    font-family: var(--font-sans);
    font-size: var(--fs-body-md);
    line-height: var(--lh-relaxed);
}

#preview-rendered h1,
#preview-rendered h2,
#preview-rendered h3 {
    margin-bottom: var(--space-2);
}

#preview-rendered pre {
    background: var(--bg-base);
    padding: var(--space-3);
    border-radius: var(--r-sm);
    overflow-x: auto;
}

#preview-rendered hr {
    border: none;
    border-top: 1px solid var(--border-default);
    margin: var(--space-3) 0;
}

#preview-rendered code {
    background: var(--bg-hover);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}

/* ── STATUS BAR ── */
.status-left,
.status-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.separator {
    color: var(--text-disabled);
}

.save-indicator {
    color: var(--green-500);
}

/* ── MODAL OVERLAY ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-overlay);
    z-index: 1000;
    animation: fade-in 150ms ease;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    animation: modal-in 200ms ease-out;
}

@keyframes modal-in {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-shortcuts {
    width: 560px;
}

.modal-danger {
    border-left: 3px solid var(--red-500);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
    font-size: var(--fs-heading-md);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-5);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-subtle);
}

.warning-text {
    color: var(--red-500);
    font-size: var(--fs-body-sm);
    margin-top: var(--space-3);
}

.import-info {
    margin-bottom: var(--space-4);
    padding: var(--space-3);
    background: var(--bg-base);
    border-radius: var(--r-md);
    font-family: var(--font-mono);
    font-size: var(--fs-caption);
    color: var(--text-secondary);
    line-height: var(--lh-relaxed);
}

.import-mode {
    margin-top: var(--space-3);
}

/* ── SHORTCUTS OVERLAY ── */
.shortcuts-body h4 {
    margin: var(--space-4) 0 var(--space-2);
    color: var(--yellow-500);
    font-size: var(--fs-body-sm);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.shortcuts-body h4:first-child {
    margin-top: 0;
}

.shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-1) 0;
    font-size: var(--fs-body-sm);
    color: var(--text-secondary);
}

.shortcut-row span {
    flex-grow: 2;
    color: var(--text-primary);
}

.shortcut-row kbd {
    margin-left: 2px;
}

/* ── DRAG & DROP ── */
.drop-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 128, 255, 0.08);
    z-index: 1200;
    border: 3px dashed var(--blue-500);
}

.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-8) var(--space-12);
    background: var(--bg-surface);
    border: 2px solid var(--blue-500);
    border-radius: var(--r-lg);
    color: var(--text-primary);
}

.drop-icon {
    font-size: 48px;
}

.drop-zone p {
    font-size: var(--fs-heading-sm);
}

.drop-zone .hint {
    font-size: var(--fs-caption);
    color: var(--text-tertiary);
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE: DRAWER TOGGLE (Tablet Only)
   ═══════════════════════════════════════════════════ */

.drawer-toggle {
    display: none;
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE: SIDEBAR SEGMENTED CONTROL
   ═══════════════════════════════════════════════════ */

.sidebar-segmented {
    display: none;
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE: BOTTOM TAB BAR
   ═══════════════════════════════════════════════════ */

.bottom-tab-bar {
    display: none;
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE: TABLET (768–1023px)
   ═══════════════════════════════════════════════════ */

@media (min-width: 768px) and (max-width: 1023px) {

    /* Header: show drawer toggle */
    .header-left {
        gap: var(--space-3);
    }

    .drawer-toggle {
        display: inline-flex;
    }
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE: MOBILE (<768px)
   ═══════════════════════════════════════════════════ */

@media (max-width: 767px) {

    /* ── Header: icon-only buttons ── */
    .header-right .btn-label {
        display: none;
    }

    .header-right .btn {
        width: var(--h-touch);
        height: var(--h-touch);
        padding: 0;
        justify-content: center;
        font-size: 18px;
    }

    @media (max-width: 479px) {
        .app-version {
            display: none;
        }
    }

    /* ── Sidebar Segmented Control ── */
    .sidebar-segmented {
        display: flex;
        padding: var(--space-2) var(--space-3);
        gap: 0;
        border-bottom: 1px solid var(--border-subtle);
    }

    .seg-btn {
        flex: 1;
        height: var(--h-touch);
        background: var(--bg-base);
        border: 1px solid var(--border-default);
        color: var(--text-secondary);
        font-family: var(--font-sans);
        font-size: var(--fs-body-sm);
        font-weight: var(--fw-semibold);
        cursor: pointer;
        transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
    }

    .seg-btn:first-child {
        border-radius: var(--r-md) 0 0 var(--r-md);
    }

    .seg-btn:last-child {
        border-radius: 0 var(--r-md) var(--r-md) 0;
    }

    .seg-btn+.seg-btn {
        border-left: none;
    }

    .seg-btn.active {
        background: var(--blue-500);
        color: var(--text-primary);
        border-color: var(--blue-500);
    }

    .seg-btn:focus-visible {
        outline: 2px solid var(--yellow-500);
        outline-offset: -2px;
        z-index: 1;
    }

    /* Show only active section */
    .sidebar-section {
        display: none;
    }

    .sidebar-section.active {
        display: block;
    }

    .item-list {
        max-height: none;
    }

    /* ── Merge Item Row ── */
    .merge-item .drag-handle {
        display: none;
    }

    .merge-item .item-tokens {
        display: none;
    }

    .merge-item .move-btn,
    .merge-item .remove-btn {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
    }

    .merge-item {
        gap: var(--space-1);
    }

    .merge-controls {
        flex-wrap: wrap;
    }

    .merge-controls .select-input {
        flex: 1;
        min-width: 0;
    }

    /* ── Action Bar (sticky in Merge tab) ── */
    .action-bar {
        position: sticky;
        bottom: 0;
        padding: var(--space-2) var(--space-3);
        background: var(--bg-surface);
        z-index: 10;
    }

    .action-bar .btn {
        height: var(--h-touch);
    }

    .action-bar .btn-copy {
        flex: 1;
    }

    /* ── Modal → Bottom Sheet ── */
    .modal-overlay {
        align-items: flex-end;
    }

    .modal {
        width: 100%;
        max-height: 90dvh;
        border-radius: var(--r-lg) var(--r-lg) 0 0;
        animation: modal-sheet-in 250ms ease-out;
    }

    .modal-shortcuts {
        width: 100%;
    }

    .modal-header {
        padding: var(--space-3) var(--space-4);
    }

    .modal-body {
        padding: var(--space-4);
    }

    .modal-footer {
        padding: var(--space-3) var(--space-4);
        padding-bottom: calc(var(--space-3) + var(--safe-bottom));
        background: var(--bg-elevated);
        border-top: 1px solid var(--border-subtle);
    }

    /* ── Context Menu → Action Sheet ── */
    .context-menu {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        min-width: 0;
        border-radius: var(--r-lg) var(--r-lg) 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding-bottom: var(--safe-bottom);
        animation: ctx-sheet-in 200ms ease-out;
    }

    .ctx-item {
        min-height: var(--h-touch);
        padding: 12px var(--space-4);
    }

    /* ── Item Menu Button: always visible ── */
    .item-list li .item-menu-btn {
        opacity: 1;
    }

    /* ── Bottom Tab Bar ── */
    .bottom-tab-bar {
        display: flex;
        flex: 0 0 auto;
        height: calc(var(--h-tabbar) + var(--safe-bottom));
        padding-bottom: var(--safe-bottom);
        background: var(--bg-surface);
        border-top: 1px solid var(--border-default);
        z-index: 100;
    }

    .tab-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: none;
        border: none;
        color: var(--text-tertiary);
        cursor: pointer;
        font-family: var(--font-sans);
        transition: color var(--t-fast);
    }

    .tab-btn .tab-icon {
        font-size: 20px;
    }

    .tab-btn .tab-label {
        font-size: var(--fs-caption);
    }

    .tab-btn.active {
        color: var(--blue-500);
    }

    .tab-btn:focus-visible {
        outline: 2px solid var(--yellow-500);
        outline-offset: -2px;
    }

    /* ── Preview panel full width ── */
    .preview-content pre {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
}

/* ═══════════════════════════════════════════════════
   ANIMATIONS: Mobile Bottom Sheet
   ═══════════════════════════════════════════════════ */

@keyframes modal-sheet-in {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

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

@keyframes ctx-sheet-in {
    from {
        transform: translateY(16px);
        opacity: 0;
    }

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