/* ============================================
   MTG Stats - Global Styles
   Mobile-first responsive design
   ============================================ */

/* CSS Custom Properties (Theme) */
:root {
    --color-primary: #4361ee;
    --color-primary-dark: #3a0ca3;
    --color-success: #22c55e;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-text: #1a1a2e;
    --color-text-muted: #666;
    --color-background: #ffffff;
    --color-surface: #f8f9fa;
    --color-border: #e0e0e0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --touch-target-min: 44px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
}

/* Base Reset & Typography */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-background);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Touch-friendly interactions */
@media (hover: none) and (pointer: coarse) {
    /* Disable hover effects on touch devices to prevent sticky hover */
    .btn:hover,
    .nav-link:hover,
    .card:hover {
        transform: none !important;
    }
}

/* Ensure minimum touch target size */
button,
a,
input[type="checkbox"],
input[type="radio"],
select {
    min-height: var(--touch-target-min);
}

/* Links */
a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-dark);
}

/* Buttons - Touch-friendly */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch-target-min);
    padding: 0.625rem 1.25rem;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition: all var(--transition-normal);
    -webkit-appearance: none;
    appearance: none;
}

.btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.25);
}

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

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    border-color: var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

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

.btn-secondary:hover:not(:disabled) {
    background-color: #e9ecef;
}

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

.btn-danger:hover:not(:disabled) {
    background-color: #dc2626;
}

.btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.btn-lg {
    min-height: 52px;
    padding: 0.75rem 1.5rem;
    font-size: 1.125rem;
}

/* Form Controls - Touch-friendly */
.form-control {
    display: block;
    width: 100%;
    min-height: var(--touch-target-min);
    padding: 0.625rem 1rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-background);
    background-clip: padding-box;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus {
    border-color: var(--color-primary);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

.form-control::placeholder {
    color: #999;
    opacity: 1;
}

.form-control:disabled {
    background-color: var(--color-surface);
    opacity: 0.7;
}

/* Textarea */
textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

/* Select */
select.form-control {
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23333' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
}

/* Form Label */
.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--color-text);
}

/* Form Group */
.form-group {
    margin-bottom: 1.25rem;
}

/* Validation States */
.form-control.is-invalid,
.was-validated .form-control:invalid {
    border-color: var(--color-danger);
}

.form-control.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.invalid-feedback {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.875rem;
    color: var(--color-danger);
}

.valid.modified:not([type=checkbox]) {
    border-color: var(--color-success);
}

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

.validation-message {
    color: var(--color-danger);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Cards */
.card {
    background-color: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-body {
    padding: var(--spacing-lg);
}

/* Alerts */
.alert {
    padding: 0.875rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
}

.alert-danger {
    color: #991b1b;
    background-color: #fee2e2;
    border-color: #fecaca;
}

.alert-success {
    color: #166534;
    background-color: #dcfce7;
    border-color: #bbf7d0;
}

.alert-warning {
    color: #92400e;
    background-color: #fef3c7;
    border-color: #fde68a;
}

.alert-info {
    color: #1e40af;
    background-color: #dbeafe;
    border-color: #bfdbfe;
}

/* Loading States */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    color: var(--color-text-muted);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

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

/* Empty States */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    color: var(--color-text-muted);
}

.empty-state p {
    margin-bottom: 1.5rem;
}

/* Error Boundary */
.blazor-error-boundary {
    background: var(--color-danger);
    color: white;
    padding: 1rem;
    border-radius: var(--radius-md);
    margin: 1rem;
}

.blazor-error-boundary::after {
    content: "An error has occurred. Please refresh the page.";
}

/* Responsive Utilities */
.hide-mobile {
    display: none;
}

@media (min-width: 768px) {
    .hide-mobile {
        display: block;
    }

    .hide-desktop {
        display: none;
    }
}

/* Safe Area Insets (for notched devices) */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface);
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Remove focus outline for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* Print styles */
@media print {
    .no-print {
        display: none !important;
    }

    body {
        background: white;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Content padding for main layout */
.content {
    padding: var(--spacing-md);
}

@media (min-width: 768px) {
    .content {
        padding: var(--spacing-lg);
    }
}

/* Page titles */
h1:focus {
    outline: none;
}

/* Bootstrap overrides */
.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.25);
}

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}
