/**
 * Sheet Music Editor Professional Styling
 * Organist-friendly design with high contrast and accessibility
 */

/* ============================================
   SMuFL Font (Bravura)
   ============================================ */
@font-face {
    font-family: 'Bravura';
    src: url('/fonts/Bravura.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ============================================
   Root Variables
   ============================================ */
:root {
    --sm-primary: #2c3e50;
    --sm-secondary: #34495e;
    --sm-accent: #3498db;
    --sm-success: #27ae60;
    --sm-warning: #f39c12;
    --sm-danger: #e74c3c;
    --sm-light: #ecf0f1;
    --sm-dark: #1a252f;
    --sm-border: #bdc3c7;
    --sm-hover: #e8f4f8;
    --sm-selected: #d4edda;
    --sm-font: 'Segoe UI', 'Roboto', system-ui, -apple-system, sans-serif;
    --sm-font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
    --sm-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12);
    --sm-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --sm-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Main Container
   ============================================ */
.sheet-music-editor {
    display: flex;
    flex-direction: column;
    height: 100vh;
    font-family: var(--sm-font);
    background: #ffffff;
    color: var(--sm-primary);
}

/* ============================================
   Toolbar
   ============================================ */
.sheet-music-toolbar {
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
    border-bottom: 2px solid var(--sm-border);
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    box-shadow: var(--sm-shadow-sm);
    z-index: 100;
}

.toolbar-group {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 4px 12px;
    border-right: 1px solid var(--sm-border);
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--sm-secondary);
    margin-right: 8px;
}

.toolbar-button {
    padding: 8px 16px;
    border: 1px solid var(--sm-border);
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--sm-primary);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.toolbar-button:hover {
    background: var(--sm-hover);
    border-color: var(--sm-accent);
    transform: translateY(-1px);
}

.toolbar-button:active {
    transform: translateY(0);
}

.toolbar-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.toolbar-button.active {
    background: var(--sm-accent);
    color: white;
    border-color: var(--sm-accent);
}

.toolbar-select {
    padding: 6px 32px 6px 12px;
    border: 1px solid var(--sm-border);
    border-radius: 4px;
    background: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toolbar-select:hover {
    border-color: var(--sm-accent);
}

.toolbar-select:focus {
    outline: 2px solid var(--sm-accent);
    outline-offset: 2px;
}

/* ============================================
   Staff Canvas
   ============================================ */
.staff-canvas-container {
    flex: 1;
    overflow: auto;
    background: white;
    padding: 24px;
    position: relative;
}

.staff-canvas {
    min-width: 100%;
    background: white;
    border: 1px solid var(--sm-border);
    border-radius: 8px;
    padding: 32px;
    box-shadow: var(--sm-shadow-md);
    cursor: crosshair;
    user-select: none;
}

.staff-canvas svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* ============================================
   Music Elements
   ============================================ */
.note-selectable {
    cursor: pointer;
    transition: opacity 0.2s ease, fill 0.2s ease;
}

.note-selectable:hover {
    opacity: 0.7;
}

.note-selected ellipse,
.note-selected circle {
    stroke: var(--sm-success) !important;
    stroke-width: 3 !important;
    filter: drop-shadow(0 0 4px var(--sm-success));
}

.chord-group {
    cursor: pointer;
}

.chord-group:hover .note-head {
    fill: var(--sm-accent);
}

.staff-line {
    stroke: var(--sm-dark);
    stroke-width: 1;
}

.ledger-line {
    stroke: var(--sm-dark);
    stroke-width: 1.5;
}

.bar-line {
    stroke: var(--sm-dark);
    stroke-width: 2;
}

.time-signature,
.key-signature {
    fill: var(--sm-dark);
    font-family: var(--sm-font);
    font-size: 20px;
    font-weight: 600;
}

.clef {
    fill: var(--sm-dark);
}

/* ============================================
   Status Bar
   ============================================ */
.sheet-music-statusbar {
    background: linear-gradient(to top, #f8f9fa, #e9ecef);
    border-top: 2px solid var(--sm-border);
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--sm-secondary);
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
    z-index: 100;
}

.statusbar-section {
    display: flex;
    gap: 16px;
    align-items: center;
}

.statusbar-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 4px;
}

.statusbar-item strong {
    font-weight: 600;
    color: var(--sm-primary);
}

.statusbar-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: var(--sm-light);
    color: var(--sm-primary);
}

.statusbar-badge.success {
    background: var(--sm-success);
    color: white;
}

.statusbar-badge.warning {
    background: var(--sm-warning);
    color: white;
}

.statusbar-badge.danger {
    background: var(--sm-danger);
    color: white;
}

/* ============================================
   Modals & Dialogs
   ============================================ */
.sheet-music-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.sheet-music-modal {
    background: white;
    border-radius: 8px;
    padding: 24px;
    max-width: 600px;
    width: 90%;
    box-shadow: var(--sm-shadow-lg);
}

.modal-header {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--sm-primary);
}

.modal-body {
    margin-bottom: 16px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ============================================
   Loading & Empty States
   ============================================ */
.loading-state,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 24px;
    color: var(--sm-secondary);
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--sm-light);
    border-top-color: var(--sm-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.empty-state-icon {
    font-size: 64px;
    color: var(--sm-border);
    margin-bottom: 16px;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .sheet-music-toolbar {
        padding: 8px 12px;
    }

    .toolbar-group {
        padding: 4px 8px;
    }

    .toolbar-button {
        padding: 6px 12px;
        font-size: 13px;
    }

    .staff-canvas-container {
        padding: 16px;
    }

    .staff-canvas {
        padding: 16px;
    }

    .sheet-music-statusbar {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .toolbar-label {
        display: none;
    }

    .statusbar-section {
        flex-wrap: wrap;
        gap: 8px;
    }
}

/* ============================================
   Accessibility & High Contrast
   ============================================ */
@media (prefers-contrast: high) {
    :root {
        --sm-border: #000000;
        --sm-primary: #000000;
        --sm-hover: #ffff00;
        --sm-selected: #00ff00;
    }

    .toolbar-button:hover,
    .note-selectable:hover {
        outline: 3px solid #000000;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Focus visible for keyboard navigation */
.toolbar-button:focus-visible,
.toolbar-select:focus-visible {
    outline: 3px solid var(--sm-accent);
    outline-offset: 2px;
}

.note-selectable:focus-visible {
    outline: 3px solid var(--sm-success);
    outline-offset: 2px;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .sheet-music-toolbar,
    .sheet-music-statusbar {
        display: none;
    }

    .staff-canvas-container {
        padding: 0;
    }

    .staff-canvas {
        border: none;
        box-shadow: none;
    }
}

/* ============================================
   Utility Classes
   ============================================ */
.text-center { text-align: center; }
.text-muted { color: var(--sm-secondary); }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.p-2 { padding: 8px; }
.p-3 { padding: 16px; }
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.align-center { align-items: center; }
