/**
 * Chess Academy — UI Components
 *
 * Buttons, forms, cards, badges, toasts, modals, pagination, etc.
 * All values come from design tokens. No hardcoded values.
 */

/* ══════════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════════ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0.625rem 1.25rem;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    line-height: 1;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}

.btn:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

.btn:disabled,
.btn--disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Primary */
.btn--primary {
    background: var(--color-primary-500);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-primary);
}
.btn--primary:hover {
    background: var(--color-primary-600);
    box-shadow: var(--shadow-primary-lg);
    transform: translateY(-1px);
}
.btn--primary:active { background: var(--color-primary-700); transform: scale(0.98); box-shadow: none; }

/* Secondary */
.btn--secondary {
    background: var(--color-surface-alt);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn--secondary:hover { background: var(--color-border-light); }

/* Outline */
.btn--outline {
    background: transparent;
    color: var(--color-primary-500);
    border-color: var(--color-primary-500);
}
.btn--outline:hover { background: var(--color-primary-50); }

/* Ghost */
.btn--ghost {
    background: transparent;
    color: var(--color-text-secondary);
}
.btn--ghost:hover { background: var(--color-surface-alt); color: var(--color-text); }

/* Danger */
.btn--danger {
    background: var(--color-danger);
    color: var(--color-text-inverse);
}
.btn--danger:hover { background: var(--color-danger-hover); }

/* Success */
.btn--success {
    background: var(--color-success);
    color: var(--color-text-inverse);
}

/* Icon-only */
.btn--icon {
    padding: 0.5rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
}

/* Brass — high-emphasis action on dark/ink backgrounds */
.btn--brass {
    background: var(--gradient-brass);
    color: hsl(30, 60%, 12%);
    box-shadow: 0 1px 2px hsla(30, 80%, 20%, 0.3), 0 4px 14px hsla(38, 92%, 45%, 0.35);
}
.btn--brass:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn--brass:active { transform: scale(0.98); box-shadow: none; }

/* Glass — secondary action on dark/ink backgrounds */
.btn--glass {
    background: hsla(0, 0%, 100%, 0.1);
    color: var(--color-text-inverse);
    border-color: hsla(0, 0%, 100%, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.btn--glass:hover { background: hsla(0, 0%, 100%, 0.18); border-color: hsla(0, 0%, 100%, 0.4); }

/* Sizes */
.btn--sm { padding: 0.375rem 0.75rem; font-size: var(--text-xs); }
.btn--lg { padding: 0.875rem 1.75rem; font-size: var(--text-base); }

/* Full width */
.btn--block { display: flex; width: 100%; }

/* Trailing/leading icon inside a button */
.btn__icon {
    width: 1.05em;
    height: 1.05em;
    flex-shrink: 0;
    transition: transform var(--duration-normal) var(--ease-out);
}
.btn:hover .btn__icon { transform: translateX(2px); }

/* Loading state */
.btn--loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn--loading::after {
    content: '';
    position: absolute;
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}


/* ══════════════════════════════════════════════════════════════
   FORMS
   ══════════════════════════════════════════════════════════════ */

.form__group {
    margin-bottom: var(--space-5);
}

.form__group--row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.form__label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text);
    margin-bottom: var(--space-1);
}

.form__label--required::after {
    content: ' *';
    color: var(--color-danger);
}

.form__input,
.form__textarea,
.form__select {
    display: block;
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: var(--text-base);
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}

.form__input:hover,
.form__textarea:hover,
.form__select:hover {
    border-color: var(--color-primary-300);
}

.form__input:focus,
.form__textarea:focus,
.form__select:focus {
    outline: none;
    border-color: var(--color-primary-500);
    box-shadow: var(--ring-primary);
}

.form__input--sm {
    padding: 0.375rem 0.625rem;
    font-size: var(--text-sm);
}

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

.form__input--error:focus {
    box-shadow: var(--ring-danger);
}

.form__error {
    display: block;
    font-size: var(--text-xs);
    color: var(--color-danger);
    margin-top: var(--space-1);
}

.form__hint {
    display: block;
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
    margin-top: var(--space-1);
}

.form__checkbox {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--color-text);
    cursor: pointer;
}

.form__checkbox input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    margin-top: 0.125rem;
    accent-color: var(--color-primary-500);
    cursor: pointer;
}

.form__textarea {
    resize: vertical;
    min-height: 6rem;
}

.form__select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8.825L.35 3.175 1.175 2.35 6 7.175 10.825 2.35l.825.825z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}


/* ══════════════════════════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════════════════════════ */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--duration-normal) var(--ease-out),
                transform var(--duration-normal) var(--ease-out);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card--interactive:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.card__header {
    margin-bottom: var(--space-4);
}

.card__title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
}

.card__body {
    color: var(--color-text-secondary);
}

.card__footer {
    margin: var(--space-5) calc(var(--space-5) * -1) calc(var(--space-5) * -1);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border-light);
    background: var(--color-surface-alt);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
}

.card--elevated {
    border: none;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
}


/* ══════════════════════════════════════════════════════════════
   CONTAINER MODIFIERS
   ══════════════════════════════════════════════════════════════ */

.container--narrow {
    max-width: 40rem;
}


/* ══════════════════════════════════════════════════════════════
   TEXT & HEADING UTILITIES
   ══════════════════════════════════════════════════════════════ */

.h1, .h2, .h3, .h4, .h5, .h6 {
    font-weight: var(--weight-bold);
    line-height: var(--leading-tight);
    color: var(--color-text);
}

.h1 { font-size: var(--text-4xl); }
.h2 { font-size: var(--text-3xl); }
.h3 { font-size: var(--text-2xl); }
.h4 { font-size: var(--text-xl); }
.h5 { font-size: var(--text-lg); }
.h6 { font-size: var(--text-base); }

@media (max-width: 768px) {
    .h1 { font-size: var(--text-3xl); }
    .h2 { font-size: var(--text-2xl); }
    .h3 { font-size: var(--text-xl); }
}

.text-bold { font-weight: var(--weight-bold); }

.link {
    color: var(--color-primary-500);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-out);
}

.link:hover {
    color: var(--color-primary-600);
    text-decoration: underline;
}

.link:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}


/* ══════════════════════════════════════════════════════════════
   BADGES & CHIPS
   ══════════════════════════════════════════════════════════════ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    border-radius: var(--radius-full);
    line-height: 1.5;
}

.badge--primary   { background: var(--color-primary-100); color: var(--color-primary-700); }
.badge--success   { background: var(--color-success-bg); color: var(--color-success); }
.badge--warning   { background: var(--color-warning-bg); color: var(--color-warning); }
.badge--danger    { background: var(--color-danger-bg); color: var(--color-danger); }
.badge--info      { background: var(--color-info-bg); color: var(--color-info); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0.25rem 0.75rem;
    font-size: var(--text-sm);
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-full);
    color: var(--color-text-secondary);
    transition: all var(--duration-fast) var(--ease-out);
}

.chip:hover {
    background: var(--color-primary-50);
    border-color: var(--color-primary-200);
    color: var(--color-primary-600);
}


/* ══════════════════════════════════════════════════════════════
   TOASTS
   ══════════════════════════════════════════════════════════════ */

.toast {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    animation: toast-in var(--duration-slow) var(--ease-out);
    max-width: 28rem;
}

.toast--success { background: var(--color-success); color: var(--color-text-inverse); }
.toast--error   { background: var(--color-danger);  color: var(--color-text-inverse); }
.toast--warning { background: var(--color-warning); color: var(--color-text-inverse); }
.toast--info    { background: var(--color-info);    color: var(--color-text-inverse); }

.toast__close {
    font-size: var(--text-lg);
    opacity: 0.8;
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
    line-height: 1;
}
.toast__close:hover { opacity: 1; }

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

.toast--dismissing {
    animation: toast-out var(--duration-slow) var(--ease-out) forwards;
}

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


/* ══════════════════════════════════════════════════════════════
   AVATAR
   ══════════════════════════════════════════════════════════════ */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-full);
    background: var(--color-primary-100);
    color: var(--color-primary-700);
    font-weight: var(--weight-semibold);
    font-size: var(--text-sm);
    overflow: hidden;
}

.avatar--sm { width: 2rem; height: 2rem; font-size: var(--text-xs); }
.avatar--lg { width: 4rem; height: 4rem; font-size: var(--text-xl); }

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}


/* ══════════════════════════════════════════════════════════════
   PAGINATION
   ══════════════════════════════════════════════════════════════ */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    margin-top: var(--space-6);
}

.pagination__link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 var(--space-2);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    transition: all var(--duration-fast) var(--ease-out);
}

.pagination__link:hover {
    background: var(--color-surface-alt);
    color: var(--color-text);
}

.pagination__link--active {
    background: var(--color-primary-500);
    color: var(--color-text-inverse);
}

.pagination__link--disabled {
    opacity: 0.4;
    pointer-events: none;
}


/* ══════════════════════════════════════════════════════════════
   ERROR PAGES
   ══════════════════════════════════════════════════════════════ */

.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
}

.error-page__code {
    font-size: 6rem;
    font-weight: var(--weight-bold);
    color: var(--color-primary-200);
    line-height: 1;
}

.error-page__title {
    margin-top: var(--space-2);
    font-size: var(--text-2xl);
}

.error-page__message {
    margin-top: var(--space-3);
    color: var(--color-text-secondary);
    max-width: 28rem;
    margin-inline: auto;
}

.error-page .btn {
    margin-top: var(--space-6);
}



/* ══════════════════════════════════════════════════════════════
   FOOTER
   ══════════════════════════════════════════════════════════════ */

.site-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border-light);
    padding-block: var(--space-10) var(--space-6);
}

.footer__grid {
    display: grid;
    grid-template-columns: 1.6fr repeat(3, 1fr);
    gap: var(--space-8) var(--space-6);
}

.footer__logo {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    color: var(--color-text);
    text-decoration: none;
}

.footer__tagline {
    margin-top: var(--space-3);
    margin-bottom: 0;
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    color: var(--color-text-secondary);
    max-width: 34ch;
}

@media (max-width: 1023px) {
    .footer__grid { grid-template-columns: repeat(3, 1fr); }
    .footer__brand { grid-column: 1 / -1; }
}

@media (max-width: 767px) {
    .footer__grid { grid-template-columns: repeat(2, 1fr); }
}

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

.footer__heading {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-3);
}

.footer__links li {
    margin-bottom: var(--space-2);
}

.footer__links a {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    transition: color var(--duration-fast) var(--ease-out);
}

.footer__links a:hover {
    color: var(--color-primary-500);
}

.footer__bottom {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-border-light);
    text-align: center;
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
}
