/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Light mode - vibrant blue palette with depth */
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary-color: #3b82f6;
    --accent-color: #6366f1;
    --background: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-lyrics: #1e293b;
    --text-secondary: #64748b;
    --border-color: #cbd5e1;
    --border-light: #e2e8f0;
    --success-color: #16a34a;
    --danger-color: #dc2626;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px rgba(37, 99, 235, 0.15), 0 4px 10px rgba(0, 0, 0, 0.08);
    --card-border: 1px solid var(--border-light);
    --gradient-primary: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --gradient-accent: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
}

/* Dark mode variables */
:root.dark-mode {
    --primary-color: #3b82f6;
    --primary-dark: #60a5fa;
    --primary-light: #1e293b;
    --secondary-color: #60a5fa;
    --accent-color: #818cf8;
    --background: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-lyrics: #e2e8f0;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --border-light: #475569;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.2);
    --card-border: 1px solid var(--border-color);
    --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --gradient-accent: linear-gradient(135deg, #60a5fa 0%, #818cf8 100%);
}

/* Auto dark mode (system preference) - only when no manual preference set */
@media (prefers-color-scheme: dark) {
    :root:not(.light-mode):not(.dark-mode) {
        --primary-color: #3b82f6;
        --primary-dark: #60a5fa;
        --primary-light: #1e293b;
        --secondary-color: #60a5fa;
        --accent-color: #818cf8;
        --background: #0f172a;
        --card-bg: #1e293b;
        --text-primary: #f1f5f9;
        --text-lyrics: #e2e8f0;
        --text-secondary: #94a3b8;
        --border-color: #334155;
        --border-light: #475569;
        --success-color: #22c55e;
        --danger-color: #ef4444;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
        --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.15);
        --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.2);
        --card-border: 1px solid var(--border-color);
        --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
        --gradient-accent: linear-gradient(135deg, #60a5fa 0%, #818cf8 100%);
    }
}

/* Theme toggle button */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border: var(--card-border);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.9rem;
    width: 100%;
    transition: background 0.2s;
}

.theme-toggle:hover {
    background: var(--primary-light);
}

.theme-toggle-icon {
    font-size: 1.1rem;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    background: var(--card-bg);
    border-bottom: 2px solid var(--primary-color);
    box-shadow: var(--shadow-md);
    z-index: 100;
    padding: 0.75rem 1rem;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 800px;
    margin: 0 auto;
}

.menu-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-radius: 4px;
}

.menu-btn:hover {
    background: var(--background);
}

.menu-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
}

.header-title {
    font-size: 1.125rem;
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-container {
    flex: 1;
    max-width: 400px;
}

.search-input {
    width: 100%;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
    background: var(--card-bg);
    color: var(--text-primary);
}

.search-input::placeholder {
    color: var(--text-secondary);
}

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

/* Search hint tooltip */
.search-hint {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    animation: fadeInHint 0.3s ease-out;
}

.search-hint::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: var(--primary-color);
}

@keyframes fadeInHint {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.search-hint.hiding {
    animation: fadeOutHint 0.2s ease-in forwards;
}

@keyframes fadeOutHint {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-4px);
    }
}

/* Side Menu */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 200;
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

.side-menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 201;
    display: flex;
    flex-direction: column;
}

.side-menu.active {
    transform: translateX(0);
}

.menu-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 1.125rem;
    background: var(--primary-light);
    color: var(--primary-color);
}

.menu-items {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.menu-item {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.2s, border-color 0.2s;
    border-left: 3px solid transparent;
}

.menu-item:hover {
    background: var(--primary-light);
    border-left-color: var(--secondary-color);
}

.menu-item.active {
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 500;
    border-left-color: var(--primary-color);
}

.menu-section-title {
    padding: 1rem 1rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.menu-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.admin-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
}

.admin-link:hover {
    color: var(--primary-color);
}

.admin-link svg {
    stroke: currentColor;
}

/* Main Content */
.main-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
}

/* Song Cards */
.song-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.song-card {
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}

.song-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.song-header {
    padding: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.song-title {
    font-weight: 500;
    font-size: 1rem;
}

.expand-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.3s;
    flex-shrink: 0;
    stroke: var(--text-secondary);
}

.song-card.expanded {
    border-left: 3px solid var(--primary-color);
}

.song-card.expanded .expand-icon {
    transform: rotate(180deg);
    stroke: var(--primary-color);
}

.song-lyrics {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.song-card.expanded .song-lyrics {
    max-height: 5000px; /* Increased to accommodate longer songs and action buttons */
}

.lyrics-content {
    padding: 0.5rem 1rem 0.5rem;
    white-space: pre-wrap;
    font-size: 0.9375rem;
    line-height: 1.75;
    color: var(--text-lyrics);
    border-top: 1px solid var(--border-light);
    background: var(--primary-light);
    margin: 0 -1px -1px -1px;
    border-radius: 0 0 10px 10px;
    position: relative;
}

/* Font size controls */
.lyrics-controls {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.25rem;
    z-index: 10;
}

.font-size-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.1s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.font-size-btn:hover {
    background: rgba(255, 255, 255, 1);
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.font-size-btn:active {
    transform: scale(0.95);
}

.font-size-btn svg {
    width: 14px;
    height: 14px;
    stroke: #333;
    fill: none;
    stroke-width: 2.5;
}

[data-theme="dark"] .font-size-btn {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .font-size-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: var(--primary-color);
}

[data-theme="dark"] .font-size-btn svg {
    stroke: #fff;
}

/* Lyrics actions wrapper - contains tune link and action buttons */
.lyrics-actions-wrapper {
    margin-top: 0;
    padding-top: 0;
    border-top: 1px solid var(--border-color);
}

/* Tune link section */
.tune-link-section {
    padding-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.tune-link-section a {
    color: var(--primary-color);
    text-decoration: none;
    word-break: break-all;
}

.tune-link-section a:hover {
    text-decoration: underline;
}

.tune-artist {
    display: block;
    margin-top: 0.25rem;
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

/* Lyrics action buttons */
.lyrics-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.lyrics-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.8125rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.lyrics-action-btn:hover {
    background: var(--background);
    border-color: var(--primary-color);
}

.lyrics-action-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
}

.lyrics-action-btn.success {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

/* Hide button text on mobile */
@media (max-width: 639px) {
    .lyrics-action-btn .btn-text {
        display: none;
    }
    .lyrics-action-btn {
        padding: 0.5rem;
    }
}

/* Print styles */
@media print {
    body * {
        visibility: hidden;
    }
    .print-content, .print-content * {
        visibility: visible;
    }
    .print-content {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        padding: 2rem;
    }
    .print-content h1 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }
    .print-content pre {
        white-space: pre-wrap;
        font-family: inherit;
        font-size: 1rem;
        line-height: 1.8;
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

/* Admin Page Styles */
.admin-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

.login-container {
    max-width: 400px;
    margin: 3rem auto;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: 12px;
    border: var(--card-border);
    box-shadow: var(--shadow-lg);
}

.login-container h2 {
    margin-bottom: 1.5rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: var(--card-bg);
    color: var(--text-primary);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-secondary);
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary-color);
}

.form-group textarea {
    min-height: 150px;
    resize: vertical;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.4);
}

.btn-secondary {
    background: var(--background);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    opacity: 0.9;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-block {
    width: 100%;
}

/* Admin Sections */
.admin-section {
    background: var(--card-bg);
    border-radius: 12px;
    border: var(--card-border);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.admin-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

/* Song Admin List */
.admin-song-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.admin-song-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--background);
    border-radius: 6px;
}

.admin-song-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

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

.admin-song-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-song-actions {
    display: flex;
    gap: 0.5rem;
}

/* List Management */
.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    background: var(--background);
    border-radius: 6px;
    margin-bottom: 0.75rem;
}

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

.list-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.list-meta {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.list-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* QR Code Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 300;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card-bg);
    border-radius: 12px;
    border: var(--card-border);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.modal h3 {
    margin-bottom: 1rem;
}

.qr-code-container {
    margin: 1rem 0;
}

.qr-code-container img {
    max-width: 100%;
    height: auto;
}

.qr-url {
    font-size: 0.75rem;
    color: var(--text-secondary);
    word-break: break-all;
    margin-bottom: 1rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.tab {
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9375rem;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.2s, border-color 0.2s;
}

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

.tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--text-primary);
    color: var(--background);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 0.875rem;
    animation: slideUp 0.3s ease;
}

.toast.success {
    background: var(--success-color);
    color: white;
}

.toast.error {
    background: var(--danger-color);
    color: white;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive adjustments */
@media (min-width: 640px) {
    .header {
        padding: 1rem 1.5rem;
    }

    .main-content {
        padding: 1.5rem;
    }

    .song-header {
        padding: 1.25rem;
    }

    .lyrics-content {
        padding: 0 1.25rem 1.25rem;
        padding-top: 1.25rem;
    }

    .admin-section {
        padding: 2rem;
    }
}

/* Print styles for song lists */
@media print {
    .header,
    .side-menu,
    .menu-overlay {
        display: none !important;
    }

    .main-content {
        padding: 0;
    }

    .song-card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .song-card .song-lyrics {
        max-height: none !important;
    }
}
