/* Document Editor Toolbar Styles */

/* Writing Mode Only Items - hide when not in writing mode */
body:not(.editor-mode-writing) .writing-mode-only {
    display: none !important;
}

.document-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 8px;
    padding: 8px 16px;
    background: var(--bg-primary, white);
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
    position: relative;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color, #e0e0e0);
    margin: 0 8px;
}

.toolbar-spacer {
    flex: 1;
}

/* Toolbar Button */
.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 10px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-primary, #333);
    transition:
        background-color 0.15s,
        color 0.15s;
    font-size: 13px;
}

.toolbar-btn:hover:not(:disabled) {
    background: var(--bg-hover, #f0f0f0);
}

.toolbar-btn:active:not(:disabled) {
    background: var(--bg-active, #e0e0e0);
}

.toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.toolbar-btn.active {
    background: var(--primary-light, #e3f2fd);
    color: var(--primary-color, #2196f3);
}

.toolbar-btn.primary {
    background: var(--primary-color, #2196f3);
    color: white;
}

.toolbar-btn.primary:hover:not(:disabled) {
    background: var(--primary-dark, #1976d2);
}

.toolbar-btn svg {
    flex-shrink: 0;
}

/* Dropdown trigger (uses universal dropdown from header.css) */
.dropdown-trigger {
    position: relative;
}

.dropdown-arrow {
    margin-left: 2px;
    opacity: 0.6;
}

/* Toolbar Select (dropdown) */
.toolbar-select {
    padding: 4px 8px;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 4px;
    background: var(--bg-primary, white);
    color: var(--text-primary, #333);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.toolbar-select:hover {
    border-color: var(--primary-color, #2196f3);
}

.toolbar-select:focus {
    border-color: var(--primary-color, #2196f3);
    box-shadow: 0 0 0 2px var(--primary-light, rgba(33, 150, 243, 0.2));
}

/* Toolbar Formatting Tools */
.toolbar-group-formatting {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-font-family {
    min-width: 100px;
    max-width: 130px;
}

.toolbar-font-size {
    min-width: 50px;
    max-width: 60px;
}

.toolbar-format-btn {
    min-width: 28px;
    width: 28px;
    height: 28px;
    padding: 4px;
    font-size: 13px;
    font-weight: 600;
}

.toolbar-format-btn b,
.toolbar-format-btn i,
.toolbar-format-btn u,
.toolbar-format-btn s {
    font-size: 13px;
}

.toolbar-color {
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

.toolbar-color::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.toolbar-color::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.toolbar-color:hover {
    border-color: var(--primary-color, #2196f3);
}

.toolbar-indent {
    min-width: 80px;
    max-width: 100px;
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.zoom-level {
    min-width: 48px;
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary, #666);
    user-select: none;
}

/* Format Bar */
.format-bar {
    position: fixed;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-primary, white);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
}

.format-select {
    padding: 4px 8px;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 4px;
    background: var(--bg-primary, white);
    font-size: 12px;
    cursor: pointer;
}

.format-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color, #e0e0e0);
    margin: 0 4px;
}

.format-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-primary, #333);
    font-size: 13px;
    transition: background-color 0.15s;
}

.format-btn:hover {
    background: var(--bg-hover, #f0f0f0);
}

.format-btn.active {
    background: var(--primary-light, #e3f2fd);
    color: var(--primary-color, #2196f3);
}

.format-color {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 4px;
    cursor: pointer;
}

.format-color::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.format-color::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

/* Tooltips handled by TooltipService (services/TooltipService.js) */
/* DO NOT add CSS ::after tooltips here - they duplicate TooltipService */

/* Dropdown Menu */
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: var(--bg-primary, white);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    display: none;
    padding: 4px 0;
}

.dropdown-menu.open {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary, #333);
    transition: background-color 0.15s;
}

.dropdown-item:hover {
    background: var(--bg-hover, #f0f0f0);
}

.dropdown-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color, #e0e0e0);
    margin: 4px 0;
}

/* Layout Menu Specific Styles */
.layout-menu {
    min-width: 220px;
}

.dropdown-section {
    padding: 4px 0;
}

.dropdown-section-title {
    padding: 4px 12px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dropdown-item .size-check,
.dropdown-item .orient-check {
    width: 16px;
    visibility: hidden;
    color: var(--primary-color, #2196f3);
    font-weight: bold;
}

.dropdown-item.active .size-check,
.dropdown-item.active .orient-check {
    visibility: visible;
}

.dropdown-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary, #333);
}

.dropdown-checkbox input[type='checkbox'] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color, #2196f3);
}

.dropdown-checkbox:hover {
    background: var(--bg-hover, #f0f0f0);
}

.dropdown-checkbox input:disabled + span {
    opacity: 0.5;
}

/* ============================================================================
   Paragraph Styles Dropdown
   ============================================================================ */
.styles-dropdown-wrapper {
    position: relative;
}

#paragraph-style-select {
    min-width: 110px;
    padding: 5px 24px 5px 8px;
    font-size: 13px;
    font-weight: 500;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}

#paragraph-style-select:focus {
    border-color: var(--primary, #2196f3);
}

/* Style preview in dropdown options */
#paragraph-style-select option[value='heading-1'] {
    font-size: 18px;
    font-weight: bold;
}

#paragraph-style-select option[value='heading-2'] {
    font-size: 16px;
    font-weight: bold;
}

#paragraph-style-select option[value='heading-3'] {
    font-size: 14px;
    font-weight: bold;
}

#paragraph-style-select option[value='quote'] {
    font-style: italic;
    color: #666;
}

#paragraph-style-select option[value='code'] {
    font-family: 'Consolas', 'Monaco', monospace;
}

/* Column Selector */
.columns-selector {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
}

.column-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 32px;
    padding: 4px;
    border: 1px solid var(--border-color, #e0e0e0);
    background: var(--bg-primary, white);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary, #666);
    transition: all 0.15s;
}

.column-btn:hover {
    background: var(--bg-hover, #f5f5f5);
    color: var(--text-primary, #333);
    border-color: var(--primary, #2196f3);
}

.column-btn.active {
    background: var(--primary-light, #e3f2fd);
    color: var(--primary, #2196f3);
    border-color: var(--primary, #2196f3);
}

.column-btn svg {
    stroke: currentColor;
}

/* Dark theme */
[data-theme='dark'] .document-toolbar {
    background: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme='dark'] .format-bar {
    background: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme='dark'] .dropdown-menu {
    background: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme='dark'] .dropdown-item:hover,
[data-theme='dark'] .dropdown-checkbox:hover {
    background: var(--bg-hover);
}

[data-theme='dark'] .column-btn {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

[data-theme='dark'] .column-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

[data-theme='dark'] .column-btn.active {
    background: var(--primary-dark, #1565c0);
    color: white;
    border-color: var(--primary);
}

/* Save Button States */
#save-btn {
    transition:
        background-color 0.15s,
        color 0.15s,
        opacity 0.15s;
    min-width: 100px;
}

#save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#save-btn .save-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-color, #ccc);
    border-top-color: var(--primary, #1976d2);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================================
   Responsive Toolbar - Mobile Optimization
   ============================================================================ */

/* More Menu Button */
.toolbar-more-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-primary, #333);
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 1px;
}

.toolbar-more-btn:hover {
    background: var(--bg-hover, #f0f0f0);
}

.toolbar-more-btn.active {
    background: var(--primary-light, #e3f2fd);
    color: var(--primary-color, #2196f3);
}

/* More Menu Dropdown */
.toolbar-more-menu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 220px;
    max-width: calc(100vw - 16px);
    max-height: 70vh;
    overflow-y: auto;
    background: var(--bg-primary, white);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1002;
    display: none;
    padding: 8px 0;
}

.toolbar-more-menu.open {
    display: block;
}

.toolbar-more-section {
    padding: 4px 0;
}

.toolbar-more-section:not(:last-child) {
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.toolbar-more-section-title {
    padding: 8px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.toolbar-more-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary, #333);
    transition: background-color 0.15s;
}

.toolbar-more-item:hover {
    background: var(--bg-hover, #f0f0f0);
}

.toolbar-more-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.toolbar-more-item span {
    flex: 1;
}

/* Group items in More menu */
.toolbar-more-group {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 16px;
}

.toolbar-more-group .toolbar-btn {
    flex: 0 0 auto;
}

/* Wrapper for More button positioning */
.toolbar-more-wrapper {
    position: relative;
    margin-left: auto;
}

/* ============================================================================
   Breakpoint: Medium screens (768px - 1200px)
   Hide: Formatting tools (font, colors, alignment, indent)
   ============================================================================ */
@media (max-width: 1200px) {
    .toolbar-more-btn {
        display: flex;
    }

    /* Hide formatting tools */
    .toolbar-group-formatting {
        display: none;
    }

    /* Hide dividers before formatting */
    #divider-before-indent,
    .toolbar-group-formatting + .toolbar-divider {
        display: none;
    }

    /* Adjust toolbar padding */
    .document-toolbar {
        padding: 6px 12px;
    }
}

/* ============================================================================
   Breakpoint: Small screens (< 768px)
   Hide: Block tools, Writing tools, Layout menu, Find, Rulers, Grid
   Show only: Save, File, Undo/Redo, Zoom +/-, View Mode, More
   ============================================================================ */
@media (max-width: 768px) {
    /* Hide secondary tools - !important to override inline styles from JS */
    .toolbar-group-blocks,
    .toolbar-group-writing,
    #divider-before-block-tools,
    #divider-writing-tools,
    #toolbar-first-line-indent,
    #divider-before-indent {
        display: none !important;
    }

    /* Hide Layout menu group and its divider on mobile */
    #toolbar-group-layout,
    #toolbar-group-layout + .toolbar-divider {
        display: none;
    }

    /* Hide Find dividers on mobile, but keep Find button visible */
    #divider-before-find,
    #toolbar-group-find + .toolbar-divider {
        display: none;
    }

    /* Hide Fit controls group */
    .toolbar-group-fit {
        display: none;
    }

    /* Hide Toggles group (Rulers, Grid) */
    .toolbar-group-toggles {
        display: none;
    }

    /* Compact toolbar */
    .document-toolbar {
        padding: 4px 8px;
        gap: 4px;
    }

    .toolbar-group {
        gap: 1px;
    }

    .toolbar-btn {
        padding: 4px 6px;
    }

    .toolbar-divider {
        margin: 0 4px;
        height: 20px;
    }

    /* Hide zoom controls on mobile - pinch-to-zoom instead */
    .zoom-controls {
        display: none;
    }

    /* Hide view mode select on mobile - auto-set to vertical */
    .toolbar-group-view {
        display: none;
    }

    /* Save button compact */
    #save-btn {
        min-width: auto;
        padding: 4px 8px;
    }

    #save-btn span:not(.save-spinner) {
        display: none;
    }
}

/* ============================================================================
   Breakpoint: Extra small screens (< 480px)
   Ultra compact mode
   ============================================================================ */
@media (max-width: 480px) {
    .document-toolbar {
        padding: 4px 6px;
        gap: 2px;
    }

    .toolbar-btn {
        padding: 4px;
    }

    .toolbar-divider {
        display: none;
    }

    /* Hide view mode text, show only icons would need JS */
    #view-mode-select {
        min-width: 70px;
        font-size: 10px;
    }

    .zoom-level {
        min-width: 36px;
        font-size: 10px;
    }

    /* File menu compact */
    #file-menu-btn span {
        display: none;
    }
}

/* ============================================================================
   Dark Theme for More Menu
   ============================================================================ */
[data-theme='dark'] .toolbar-more-btn:hover {
    background: var(--bg-hover);
}

[data-theme='dark'] .toolbar-more-btn.active {
    background: var(--primary-dark);
    color: white;
}

[data-theme='dark'] .toolbar-more-menu {
    background: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme='dark'] .toolbar-more-section:not(:last-child) {
    border-color: var(--border-color);
}

[data-theme='dark'] .toolbar-more-item:hover {
    background: var(--bg-hover);
}
