/**
 * MTune Dashboard - Main Styles
 * Core layout and base styles
 */

/* Reset & Base */
.mtune-app *,
.mtune-app *::before,
.mtune-app *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.mtune-app {
    font-family: var(--mtune-font-primary);
    font-size: 16px;
    line-height: 1.6;
    letter-spacing: -0.01em;
    color: var(--mtune-text-primary);
    background-color: var(--mtune-dark-300);
    background-image:
        radial-gradient(ellipse 100% 80% at 50% -30%, rgba(var(--mtune-primary-rgb), 0.18) 0%, transparent 55%),
        radial-gradient(ellipse 70% 50% at 100% 0%, rgba(var(--mtune-accent-rgb), 0.12) 0%, transparent 45%),
        radial-gradient(ellipse 60% 40% at 0% 100%, rgba(var(--mtune-primary-rgb), 0.08) 0%, transparent 50%);
    min-height: 100vh;
    min-height: 100dvh;
    /* Single scroll surface for the whole auth UI (no nested view scrollbars) */
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/**
 * Full-width auth column (forms only).
 */
.mtune-auth-content {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    background-color: var(--mtune-dark-300);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: max(env(safe-area-inset-left), var(--mtune-space-md));
    padding-right: max(env(safe-area-inset-right), var(--mtune-space-md));
}

.mtune-auth-content > .mtune-screen {
    display: none;
    flex: 1 1 auto;
    width: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--mtune-space-2xl) 0;
    overflow: visible;
    position: relative;
    z-index: 1;
}

.mtune-auth-content > .mtune-screen.active {
    display: flex;
}

/* Long forms: start from top instead of vertically centered */
.mtune-auth-content > .mtune-create-account-screen.active {
    justify-content: flex-start;
    padding-top: var(--mtune-space-xl);
    padding-bottom: var(--mtune-space-3xl);
}

/* Ambient mesh + subtle grain */
.mtune-app::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse 80% 60% at 20% 40%, rgba(var(--mtune-primary-rgb), 0.09) 0%, transparent 50%),
        radial-gradient(ellipse 70% 50% at 85% 75%, rgba(var(--mtune-accent-rgb), 0.06) 0%, transparent 48%),
        radial-gradient(circle at 50% 120%, rgba(var(--mtune-primary-rgb), 0.06) 0%, transparent 45%);
    pointer-events: none;
    z-index: 0;
}

.mtune-app::after {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    opacity: 0.45;
    pointer-events: none;
    z-index: 0;
    mix-blend-mode: overlay;
}

/* Typography */
.mtune-app h1,
.mtune-app h2,
.mtune-app h3,
.mtune-app h4,
.mtune-app h5,
.mtune-app h6 {
    font-family: var(--mtune-font-display);
    font-weight: 600;
    line-height: 1.3;
    color: var(--mtune-text-primary);
}

.mtune-app h1 { font-size: var(--mtune-text-4xl); }
.mtune-app h2 { font-size: var(--mtune-text-3xl); }
.mtune-app h3 { font-size: var(--mtune-text-2xl); }
.mtune-app h4 { font-size: var(--mtune-text-xl); }

.mtune-app p {
    color: var(--mtune-text-secondary);
}

.mtune-app a {
    color: var(--mtune-accent);
    text-decoration: none;
    transition: color var(--mtune-transition-fast);
}

.mtune-app a:hover {
    color: var(--mtune-accent-light);
}

/* Buttons */
.mtune-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--mtune-space-sm);
    padding: var(--mtune-space-md) var(--mtune-space-xl);
    font-family: var(--mtune-font-primary);
    font-size: var(--mtune-text-base);
    font-weight: 600;
    border: none;
    border-radius: var(--mtune-radius-md);
    cursor: pointer;
    transition: all var(--mtune-transition-normal);
    position: relative;
    overflow: hidden;
}

.mtune-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left var(--mtune-transition-slow);
}

.mtune-btn:hover::before {
    left: 100%;
}

.mtune-btn-primary {
    background: linear-gradient(135deg, var(--mtune-primary-dark) 0%, var(--mtune-primary) 45%, var(--mtune-accent-dark) 100%);
    color: white;
    box-shadow: var(--mtune-shadow-md), var(--mtune-shadow-glow);
}

.mtune-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--mtune-shadow-lg), var(--mtune-shadow-glow);
}

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

.mtune-btn-secondary {
    background: var(--mtune-glass-bg);
    color: var(--mtune-text-primary);
    border: 1px solid var(--mtune-glass-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

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

.mtune-btn-ghost {
    background: transparent;
    color: var(--mtune-text-secondary);
}

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

.mtune-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.mtune-btn .btn-loader {
    display: none;
}

.mtune-btn.loading .btn-text {
    visibility: hidden;
}

.mtune-btn.loading .btn-loader {
    display: flex;
    position: absolute;
}

.mtune-btn .spinner {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

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

/* Form Elements */
.mtune-form-group {
    margin-bottom: var(--mtune-space-lg);
}

.mtune-form-group label {
    display: block;
    font-size: var(--mtune-text-sm);
    font-weight: 500;
    color: var(--mtune-text-secondary);
    margin-bottom: var(--mtune-space-sm);
}

.mtune-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.mtune-input-icon {
    position: absolute;
    left: var(--mtune-space-md);
    width: 20px;
    height: 20px;
    color: var(--mtune-text-tertiary);
    pointer-events: none;
    transition: color var(--mtune-transition-fast);
}

.mtune-input-wrapper input,
.mtune-input-wrapper textarea,
.mtune-input-wrapper select {
    width: 100%;
    padding: var(--mtune-space-md);
    padding-left: 48px;
    font-family: var(--mtune-font-primary);
    font-size: var(--mtune-text-base);
    color: var(--mtune-text-primary);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--mtune-radius-md);
    transition: all var(--mtune-transition-fast);
    
    /* iOS Safari fixes */
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
}

.mtune-input-wrapper input:focus,
.mtune-input-wrapper textarea:focus,
.mtune-input-wrapper select:focus {
    outline: none;
    border-color: var(--mtune-primary);
    box-shadow: 0 0 0 3px rgba(var(--mtune-primary-rgb), 0.2);
}

.mtune-input-wrapper input:focus + .mtune-input-icon,
.mtune-input-wrapper:focus-within .mtune-input-icon {
    color: var(--mtune-primary);
}

.mtune-input-wrapper input::placeholder {
    color: var(--mtune-text-muted);
}

/* Input without icon */
.mtune-input-wrapper.no-icon input {
    padding-left: var(--mtune-space-md);
}

/* Checkbox */
.mtune-checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--mtune-space-sm);
    cursor: pointer;
    font-size: var(--mtune-text-sm);
    color: var(--mtune-text-secondary);
}

.mtune-checkbox-label input[type="checkbox"] {
    display: none;
}

.mtune-checkbox-custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--mtune-glass-border);
    border-radius: var(--mtune-radius-xs);
    background: var(--mtune-glass-bg);
    transition: all var(--mtune-transition-fast);
    position: relative;
}

.mtune-checkbox-custom::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 12px;
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E") center/contain no-repeat;
    transition: transform var(--mtune-transition-spring);
}

.mtune-checkbox-label input:checked + .mtune-checkbox-custom {
    background: linear-gradient(135deg, var(--mtune-primary), var(--mtune-accent));
    border-color: transparent;
}

.mtune-checkbox-label input:checked + .mtune-checkbox-custom::after {
    transform: translate(-50%, -50%) scale(1);
}

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

.mtune-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.mtune-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--mtune-glass-bg);
    border: 1px solid var(--mtune-glass-border);
    border-radius: var(--mtune-radius-full);
    transition: all var(--mtune-transition-normal);
}

.mtune-toggle-slider::before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: var(--mtune-text-tertiary);
    border-radius: 50%;
    transition: all var(--mtune-transition-spring);
}

.mtune-toggle input:checked + .mtune-toggle-slider {
    background: linear-gradient(135deg, var(--mtune-primary), var(--mtune-accent));
    border-color: transparent;
}

.mtune-toggle input:checked + .mtune-toggle-slider::before {
    transform: translateX(24px);
    background: white;
}

/* Cards */
.mtune-card {
    background: var(--mtune-glass-bg);
    border: 1px solid var(--mtune-glass-border);
    border-radius: var(--mtune-radius-lg);
    padding: var(--mtune-space-xl);
    backdrop-filter: blur(20px);
    transition: all var(--mtune-transition-normal);
}

.mtune-card:hover {
    background: var(--mtune-glass-bg-hover);
    border-color: var(--mtune-glass-border-hover);
}

.mtune-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--mtune-space-lg);
}

.mtune-card-title {
    font-size: var(--mtune-text-xl);
    font-weight: 600;
}

.mtune-card-subtitle {
    font-size: var(--mtune-text-sm);
    color: var(--mtune-text-tertiary);
    margin-top: var(--mtune-space-xs);
}

/* Messages */
.mtune-message {
    padding: var(--mtune-space-md);
    border-radius: var(--mtune-radius-sm);
    font-size: var(--mtune-text-sm);
    margin-top: var(--mtune-space-md);
    display: none;
}

.mtune-message.show {
    display: block;
    animation: messageSlide 0.3s ease;
}

.mtune-message.success {
    background: var(--mtune-success-bg);
    color: var(--mtune-success);
    border: 1px solid rgba(0, 200, 83, 0.3);
}

.mtune-message.error {
    background: var(--mtune-error-bg);
    color: var(--mtune-error);
    border: 1px solid rgba(255, 82, 82, 0.3);
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Toast Notifications */
.mtune-toast-container {
    position: fixed;
    bottom: var(--mtune-space-xl);
    right: var(--mtune-space-xl);
    z-index: var(--mtune-z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--mtune-space-md);
}

.mtune-toast {
    display: flex;
    align-items: center;
    gap: var(--mtune-space-md);
    padding: var(--mtune-space-md) var(--mtune-space-lg);
    background: var(--mtune-dark-100);
    border: 1px solid var(--mtune-glass-border);
    border-radius: var(--mtune-radius-md);
    backdrop-filter: blur(20px);
    box-shadow: var(--mtune-shadow-lg);
    animation: toastSlide 0.3s ease;
    min-width: 300px;
    max-width: 450px;
}

.mtune-toast.success {
    border-left: 4px solid var(--mtune-success);
}

.mtune-toast.error {
    border-left: 4px solid var(--mtune-error);
}

.mtune-toast.info {
    border-left: 4px solid var(--mtune-info);
}

.mtune-toast-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.mtune-toast.success .mtune-toast-icon { color: var(--mtune-success); }
.mtune-toast.error .mtune-toast-icon { color: var(--mtune-error); }
.mtune-toast.info .mtune-toast-icon { color: var(--mtune-info); }

.mtune-toast-content {
    flex: 1;
}

.mtune-toast-title {
    font-weight: 600;
    font-size: var(--mtune-text-sm);
    margin-bottom: 2px;
}

.mtune-toast-message {
    font-size: var(--mtune-text-sm);
    color: var(--mtune-text-secondary);
}

.mtune-toast-close {
    background: none;
    border: none;
    color: var(--mtune-text-tertiary);
    cursor: pointer;
    padding: var(--mtune-space-xs);
    transition: color var(--mtune-transition-fast);
}

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

.mtune-toast.removing {
    animation: toastRemove 0.3s ease forwards;
}

@keyframes toastSlide {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastRemove {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Scrollbar */
.mtune-app ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.mtune-app ::-webkit-scrollbar-track {
    background: var(--mtune-dark-200);
}

.mtune-app ::-webkit-scrollbar-thumb {
    background: var(--mtune-glass-border);
    border-radius: var(--mtune-radius-full);
}

.mtune-app ::-webkit-scrollbar-thumb:hover {
    background: var(--mtune-glass-border-hover);
}

/* Error State */
.mtune-error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--mtune-space-lg);
    padding: var(--mtune-space-3xl);
    text-align: center;
    color: var(--mtune-text-tertiary);
}

.mtune-error-state svg {
    color: var(--mtune-error);
    opacity: 0.6;
}

.mtune-error-state p {
    font-size: var(--mtune-text-lg);
    color: var(--mtune-text-secondary);
}

/* Modal Overlay */
.mtune-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: var(--mtune-z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--mtune-transition-normal);
}

.mtune-modal-overlay.show {
    opacity: 1;
}

/* Modal */
.mtune-modal {
    background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.1) 0%,
        rgba(255, 255, 255, 0.05) 100%
    );
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border: 1px solid var(--mtune-glass-border);
    border-radius: var(--mtune-radius-xl);
    padding: var(--mtune-space-2xl);
    max-width: 420px;
    width: 90%;
    box-shadow: var(--mtune-shadow-xl);
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    transition: all var(--mtune-transition-spring);
}

.mtune-modal-overlay.show .mtune-modal {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Logout Modal Specific */
.mtune-logout-modal {
    text-align: center;
}

.mtune-modal-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--mtune-space-lg) auto;
    background: linear-gradient(135deg, var(--mtune-primary), var(--mtune-accent));
    border-radius: var(--mtune-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalIconPulse 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIconPulse {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.mtune-modal-icon svg {
    width: 32px;
    height: 32px;
    color: white;
}

.mtune-modal-title {
    font-size: var(--mtune-text-2xl);
    font-weight: 700;
    color: var(--mtune-text-primary);
    margin-bottom: var(--mtune-space-sm);
}

.mtune-modal-message {
    font-size: var(--mtune-text-base);
    color: var(--mtune-text-secondary);
    margin-bottom: var(--mtune-space-xl);
    line-height: 1.6;
}

.mtune-modal-actions {
    display: flex;
    gap: var(--mtune-space-md);
    justify-content: center;
}

.mtune-modal-actions .mtune-btn {
    flex: 1;
    max-width: 160px;
}

/* Modal Animations */
.mtune-modal-overlay.hiding {
    opacity: 0;
}

.mtune-modal-overlay.hiding .mtune-modal {
    transform: scale(0.9) translateY(20px);
    opacity: 0;
}

/* Utility Classes */
.mtune-text-center { text-align: center; }
.mtune-text-left { text-align: left; }
.mtune-text-right { text-align: right; }

.mtune-flex { display: flex; }
.mtune-flex-col { flex-direction: column; }
.mtune-items-center { align-items: center; }
.mtune-justify-center { justify-content: center; }
.mtune-justify-between { justify-content: space-between; }
.mtune-gap-sm { gap: var(--mtune-space-sm); }
.mtune-gap-md { gap: var(--mtune-space-md); }
.mtune-gap-lg { gap: var(--mtune-space-lg); }

.mtune-mt-sm { margin-top: var(--mtune-space-sm); }
.mtune-mt-md { margin-top: var(--mtune-space-md); }
.mtune-mt-lg { margin-top: var(--mtune-space-lg); }
.mtune-mb-sm { margin-bottom: var(--mtune-space-sm); }
.mtune-mb-md { margin-bottom: var(--mtune-space-md); }
.mtune-mb-lg { margin-bottom: var(--mtune-space-lg); }

/* Small phones: slightly tighter horizontal padding on the form column */
@media (max-width: 639px) {
    .mtune-app {
        min-height: 100dvh;
        min-height: -webkit-fill-available;
    }

    .mtune-auth-content > .mtune-screen {
        padding-left: 0;
        padding-right: 0;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .mtune-app {
        font-size: 14px;
    }
    
    .mtune-toast-container {
        left: var(--mtune-space-md);
        right: var(--mtune-space-md);
        bottom: var(--mtune-space-md);
    }
    
    .mtune-toast {
        min-width: auto;
        max-width: none;
    }
}

/* iOS Safari Specific Improvements */
@supports (-webkit-overflow-scrolling: touch) {
    /* Enhanced glass effect for iOS */
    .mtune-glass-bg,
    .mtune-card,
    .mtune-modal {
        background: rgba(26, 26, 26, 0.85) !important;
        backdrop-filter: saturate(180%) blur(20px) !important;
        -webkit-backdrop-filter: saturate(180%) blur(20px) !important;
    }
    
    /* Smooth scrolling for all scrollable containers */
    .mtune-main-content,
    .mtune-page-content,
    .mtune-content-area {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Fix for iOS input zoom */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on focus */
    }
    
    /* Better tap targets for iOS */
    button,
    a,
    .mtune-btn,
    .mtune-nav-link {
        -webkit-tap-highlight-color: rgba(0, 79, 255, 0.1);
        touch-action: manipulation;
    }
}

/* Safe area padding for iOS devices with notch */
@supports (padding-top: env(safe-area-inset-top)) {
    .mtune-header {
        padding-top: max(var(--mtune-space-md), env(safe-area-inset-top));
    }
    
    .mtune-sidebar {
        padding-top: env(safe-area-inset-top);
    }
    
    /* Adjust bottom padding for home indicator */
    .mtune-sidebar-nav {
        padding-bottom: max(var(--mtune-space-md), env(safe-area-inset-bottom));
    }
}

