/* ═══════════════════════════════════════════════════════════
   MTX MusicGen - Global Styles
   Dark theme with modern UI
   ═══════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #242834;
    --bg-card: #1e2230;
    --bg-hover: #2a2f3d;
    --border-color: #2e3344;
    --text-primary: #e4e7ef;
    --text-secondary: #9ca3b8;
    --text-muted: #6b7280;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd1;
    --accent-light: rgba(108, 92, 231, 0.15);
    --success: #00b894;
    --success-hover: #00a383;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --warning: #fdcb6e;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.app-container {
    min-height: 100vh;
}

/* ── Login Pages ──────────────────────────────────────── */

.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #0f1117 0%, #1a1d27 50%, #242834 100%);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo-icon {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
}

.login-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: color var(--transition);
}

.login-footer a:hover {
    color: var(--accent);
}

/* ── Forms ────────────────────────────────────────────── */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group label .required {
    color: #ef4444;
}

.form-group label .optional {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 12px;
}

.form-group input,
.form-group textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

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

/* ── Buttons ──────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
}

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

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

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

.btn-outline:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

/* ── Alerts ───────────────────────────────────────────── */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 4px;
}

.alert-error {
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid rgba(231, 76, 60, 0.3);
    color: #e74c3c;
}

.alert-success {
    background: rgba(0, 184, 148, 0.15);
    border: 1px solid rgba(0, 184, 148, 0.3);
    color: var(--success);
}

/* ── Top Bar ──────────────────────────────────────────── */

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.top-bar-left .logo-icon {
    font-size: 28px;
    margin-bottom: 0;
}

.top-bar-left h2 {
    font-size: 20px;
    font-weight: 700;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge {
    font-size: 14px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 6px 14px;
    border-radius: 20px;
}

/* ── Cards ────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header .card-title {
    margin-bottom: 0;
}

/* ── Student Layout ───────────────────────────────────── */

.student-layout {
    min-height: 100vh;
}

.student-main {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.student-main.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.generation-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.duration-info {
    display: flex;
    gap: 8px;
}

.info-chip {
    background: var(--accent-light);
    color: var(--accent);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.hidden {
    display: none !important;
}

.generate-status {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    text-align: center;
}

.generate-status.info {
    background: var(--accent-light);
    color: var(--accent);
}

.generate-status.success {
    background: rgba(0, 184, 148, 0.15);
    color: var(--success);
}

.generate-status.error {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger);
}

/* ── Audio Player ─────────────────────────────────────── */

.player-section {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.player-section h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.audio-player {
    width: 100%;
    height: 40px;
    border-radius: var(--radius-sm);
}

/* ── History ──────────────────────────────────────────── */

.history-card {
    display: flex;
    flex-direction: column;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    min-height: 100px;
}

.history-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: border-color var(--transition);
}

.history-item:hover {
    border-color: var(--accent);
}

.history-item.submitted {
    border-color: var(--success);
    background: rgba(0, 184, 148, 0.08);
}

.history-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.history-prompt {
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-tag {
    display: inline-block;
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255,255,255,0.06);
    padding: 1px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.history-time {
    font-size: 12px;
    color: var(--text-muted);
}

.history-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-submitted {
    background: var(--success);
    color: #fff;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
    font-size: 14px;
}

.empty-state-sm {
    text-align: center;
    color: var(--text-muted);
    padding: 12px;
    font-size: 13px;
}

.submission-section {
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

.submission-section h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.current-submission {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(0, 184, 148, 0.1);
    border: 1px solid var(--success);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
}

.submission-prompt {
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Portal Closed Banner ─────────────────────────────── */

.portal-closed-banner {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: var(--radius);
    padding: 24px;
    margin: 24px auto;
    max-width: 1200px;
}

.portal-closed-banner .banner-icon {
    font-size: 32px;
}

.portal-closed-banner h3 {
    font-size: 18px;
    margin-bottom: 6px;
    color: var(--danger);
}

.portal-closed-banner p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ── Admin Layout ─────────────────────────────────────── */

.admin-layout {
    min-height: 100vh;
}

.admin-main {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.tab-nav {
    display: flex;
    gap: 4px;
    padding: 0 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    max-width: 1200px;
    margin: 0 auto;
}

.tab-btn {
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

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

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

.tab-content {
    display: none;
}

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

/* ── Data Table ───────────────────────────────────────── */

.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

.data-table th {
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.actions-cell {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

.prompt-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Submission Actions ───────────────────────────────── */

.submission-actions {
    display: flex;
    gap: 8px;
}

/* ── Settings ─────────────────────────────────────────── */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 24px;
}

.setting-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setting-desc {
    font-size: 14px;
    color: var(--text-secondary);
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-status {
    font-size: 15px;
    font-weight: 600;
    color: var(--success);
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    transition: 0.3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: var(--text-muted);
    transition: 0.3s;
    border-radius: 50%;
}

.switch input:checked + .slider {
    background: var(--accent);
    border-color: var(--accent);
}

.switch input:checked + .slider:before {
    transform: translateX(22px);
    background: #fff;
}

.duration-setting {
    display: flex;
    align-items: center;
    gap: 8px;
}

.duration-input {
    width: 80px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
}

.duration-input:focus {
    border-color: var(--accent);
}

.duration-unit {
    color: var(--text-secondary);
    font-size: 14px;
}

.password-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.password-form .form-group input {
    padding: 10px 14px;
    font-size: 14px;
}

/* ── Modal ────────────────────────────────────────────── */

.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow);
    z-index: 1;
}

.modal-sm {
    max-width: 420px;
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

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

.modal-body {
    padding: 24px;
}

.modal-student-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 14px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

/* ── Toast ────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    z-index: 2000;
    box-shadow: var(--shadow);
    transition: opacity 0.3s, transform 0.3s;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

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

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

/* ── Responsive ───────────────────────────────────────── */

@media (max-width: 768px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .top-bar {
        padding: 12px 16px;
    }

    .student-main,
    .admin-main {
        padding: 16px;
    }

    .tab-nav {
        padding: 0 16px;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .submission-actions {
        flex-wrap: wrap;
    }

    .player-card-full {
        margin-top: 0;
    }
}

/* ── Full-width Player Card ───────────────────────────── */

.player-card-full {
    margin-top: 24px;
}

.player-section h4 {
    display: flex;
    align-items: center;
    gap: 6px;
}

.now-playing-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 600px;
}

/* ── Notice Banner (3-song limit) ─────────────────────── */

.notice-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(253, 203, 110, 0.12);
    border: 1px solid rgba(253, 203, 110, 0.35);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--warning);
}

.notice-banner .notice-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.notice-banner .notice-dismiss {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    transition: color var(--transition);
}

.notice-banner .notice-dismiss:hover {
    color: var(--text-primary);
}

/* ── Animations ───────────────────────────────────────── */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(108, 92, 231, 0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.4s ease-out both;
}

.fade-in {
    animation: fadeIn 0.3s ease-out both;
}

.slide-up {
    animation: slideUp 0.35s ease-out both;
}

.pulse {
    animation: pulseGlow 1.5s ease-in-out infinite;
}

/* ── Enhanced Card & Button Transitions ───────────────── */

.card {
    transition: border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
    border-color: rgba(108, 92, 231, 0.3);
    box-shadow: 0 4px 24px rgba(108, 92, 231, 0.08);
}

.btn {
    transition: all var(--transition);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

.history-item {
    transition: all var(--transition);
}

.history-item:hover {
    border-color: var(--accent);
    transform: translateX(2px);
}

/* ── Audio Player Styling ─────────────────────────────── */

.audio-player {
    transition: opacity var(--transition);
}

.audio-player::-webkit-media-controls-panel {
    background-color: var(--bg-tertiary);
}

/* White audio player controls for better contrast */
.audio-player::-webkit-media-controls-play-button,
.audio-player::-webkit-media-controls-mute-button,
.audio-player::-webkit-media-controls-fullscreen-button,
.audio-player::-webkit-media-controls-rewind-button,
.audio-player::-webkit-media-controls-return-to-realtime-button,
.audio-player::-webkit-media-controls-toggle-closed-captions-button {
    filter: invert(1) brightness(2);
}

.audio-player::-webkit-media-controls-current-time-display,
.audio-player::-webkit-media-controls-time-remaining-display {
    color: #fff;
    text-shadow: none;
    filter: none;
}

.audio-player::-webkit-media-controls-timeline,
.audio-player::-webkit-media-controls-volume-slider {
    filter: invert(1) brightness(1.4);
}

.audio-player::-webkit-media-controls-slider {
    filter: invert(1) brightness(1.4);
}

/* Firefox fallback — invert the whole control bar */
@supports (-moz-appearance: none) {
    .audio-player {
        filter: invert(1) hue-rotate(180deg);
    }
}
