/**
 * layout.css - App header, action bar, panels, and layout styles
 */

/* ============================================
   APP HEADER
   ============================================ */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}

.app-header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

/* Mode Switcher */
.mode-switcher {
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 3px;
    gap: 2px;
}

.mode-btn {
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
}

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

.mode-btn.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.mode-btn svg {
    width: 14px;
    height: 14px;
}

/* Icon Button (settings) */
.icon-btn {
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

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

/* ============================================
   ACTION BAR
   ============================================ */

.action-bar {
    display: flex;
    align-items: center;
    height: var(--action-bar-height);
    padding: 0 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 4px;
}

.action-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

.action-btn svg {
    width: 14px;
    height: 14px;
}

.action-btn.dropdown-trigger {
    padding-right: 6px;
}

.action-btn .dropdown-arrow {
    width: 10px;
    height: 10px;
    margin-left: 2px;
    transition: transform 0.15s;
}

.dropdown.open .action-btn .dropdown-arrow {
    transform: rotate(180deg);
}

/* Icon-only buttons */
.action-btn.icon-only {
    padding: 6px;
    gap: 2px;
}

.action-btn.icon-only svg {
    width: 16px;
    height: 16px;
}

.action-btn.icon-only .dropdown-arrow {
    width: 8px;
    height: 8px;
    margin-left: 0;
}

/* Toolbar strip - grouped buttons */
.toolbar-strip {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 2px;
    gap: 1px;
}

.toolbar-strip .action-btn {
    border-radius: 4px;
}

.toolbar-strip .action-btn:hover {
    background: var(--bg-tertiary);
}

.toolbar-strip .dropdown {
    display: flex;
}

/* Format tools within edit-tools */
.edit-tools .toolbar-strip {
    margin: 0;
}

.edit-tools > .action-btn,
.edit-tools > .dropdown {
    margin: 0;
}

.action-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 6px;
}

.action-spacer {
    flex: 1;
}

/* Stats in action bar */
.stats-group {
    gap: 10px;
}

.stat-item {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Sync Toggle in action bar */
.sync-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
    user-select: none;
}

.sync-toggle:hover {
    background: var(--bg-primary);
}

.sync-toggle input {
    display: none;
}

.sync-indicator {
    width: 28px;
    height: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    position: relative;
    transition: background 0.2s;
}

.sync-indicator::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.sync-toggle input:checked + .sync-indicator {
    background: var(--accent-color);
}

.sync-toggle input:checked + .sync-indicator::after {
    transform: translateX(12px);
}

/* Edit tools visibility */
body.mode-read .edit-tools {
    display: none;
}

/* ============================================
   APP CONTAINER (Main Layout)
   ============================================ */

.app-container {
    display: flex;
    height: calc(100vh - var(--header-height) - var(--action-bar-height));
    height: calc(100dvh - var(--header-height) - var(--action-bar-height));
    background: var(--bg-secondary);
    overflow: hidden;
    position: relative;
}

/* ============================================
   EDITOR PANEL
   ============================================ */

.editor-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    min-width: 0;
    transition: width 0.2s ease, flex 0.2s ease;
    overflow: hidden;
}

.editor-wrapper {
    flex: 1;
    overflow: hidden;
}

/* ============================================
   RESIZER
   ============================================ */

.resizer {
    width: 6px;
    background: var(--bg-tertiary);
    cursor: col-resize;
    transition: background 0.15s;
    position: relative;
    flex-shrink: 0;
}

.resizer:hover,
.resizer.dragging {
    background: var(--accent-color);
}

.resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 30px;
    background: var(--text-secondary);
    border-radius: 1px;
    opacity: 0.3;
}

.resizer:hover::after,
.resizer.dragging::after {
    background: white;
    opacity: 0.8;
}

/* ============================================
   PREVIEW PANEL
   ============================================ */

.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0;
    transition: flex 0.2s ease;
}

.preview-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    min-height: 0;
}

/* ============================================
   MODE STATES
   ============================================ */

/* Edit Mode */
body.mode-edit .toc-panel,
body.mode-edit .toc-toggle-btn {
    display: none;
}

body.mode-edit .preview-panel,
body.mode-edit .resizer {
    display: none;
}

body.mode-edit .editor-panel {
    flex: 1;
    border-right: none;
}

/* Split Mode */
body.mode-split .editor-panel {
    width: var(--editor-width, 50%);
    flex-shrink: 0;
}

/* Read Mode */
body.mode-read .editor-panel,
body.mode-read .resizer {
    display: none;
}

body.mode-read .preview-panel {
    flex: 1;
}

/* ============================================
   MOBILE SETTINGS PANEL
   ============================================ */

.mobile-settings-btn {
    display: none;
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
}

.mobile-settings-btn svg {
    width: 18px;
    height: 18px;
}

.settings-panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1500;
}

.settings-panel-overlay.visible {
    display: block;
}

.settings-panel {
    position: fixed;
    top: 0;
    right: -280px;
    width: 260px;
    height: 100%;
    background: var(--bg-primary);
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    z-index: 1600;
    transition: right 0.3s ease;
    overflow-y: auto;
    padding: 12px 14px;
}

.settings-panel.visible {
    right: 0;
}

.settings-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.settings-panel-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.settings-panel-close {
    padding: 6px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
}

.settings-panel-close:hover {
    background: var(--bg-secondary);
}

.settings-panel-close svg {
    width: 18px;
    height: 18px;
}

.settings-panel-group {
    margin-bottom: 12px;
}

.settings-panel-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    display: block;
}

.settings-panel-group select {
    width: 100%;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.settings-panel-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    border-radius: 5px;
    padding: 3px;
}

.settings-panel-control button {
    width: 36px;
    height: 30px;
    border: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
    border-radius: 4px;
    cursor: pointer;
}

.settings-panel-control button:active {
    background: var(--bg-tertiary);
}

.settings-panel-control span {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Highlight Color Options */
.highlight-color-options {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.highlight-color-btn {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    padding: 0;
}

.highlight-color-btn:hover {
    transform: scale(1.1);
    border-color: var(--text-secondary);
}

.highlight-color-btn.active {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-color);
}

.highlight-color-options input[type="color"] {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    background: none;
    -webkit-appearance: none;
}

.highlight-color-options input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.highlight-color-options input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .app-header,
    .action-bar,
    .toc-panel,
    .editor-panel,
    .resizer {
        display: none !important;
    }

    .app-container {
        height: auto;
    }

    .preview-panel {
        width: 100% !important;
    }

    .preview-wrapper {
        padding: 0;
    }
}
