/**
 * SEL Education Platform - Components Library
 * 可重用 UI 元件樣式
 * 
 * 依賴: design-tokens.css
 */

/* ==================== 基礎重置與全域樣式 ==================== */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    color: var(--color-text-primary);
}

h1 {
    font-size: var(--font-size-6xl);
}

h2 {
    font-size: var(--font-size-5xl);
}

h3 {
    font-size: var(--font-size-4xl);
}

h4 {
    font-size: var(--font-size-3xl);
}

h5 {
    font-size: var(--font-size-2xl);
}

h6 {
    font-size: var(--font-size-xl);
}

/* ==================== 按鈕元件 ==================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 0.75rem 1.5rem;
    font-family: var(--font-heading);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
    user-select: none;
}

.btn:focus-visible {
    outline: 3px solid var(--color-primary-20);
    outline-offset: 2px;
}

/* Primary Button */
.btn-primary {
    background: var(--color-primary);
    color: var(--color-text-white);
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

/* Secondary Button */
.btn-secondary {
    background: transparent;
    color: var(--color-primary);
    border: 2px solid var(--color-primary);
}

.btn-secondary:hover {
    background: var(--color-primary);
    color: var(--color-text-white);
}

/* Accent Button */
.btn-accent {
    background: var(--color-accent);
    color: var(--color-text-white);
    box-shadow: var(--shadow-md);
}

.btn-accent:hover {
    background: var(--color-accent-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Ghost Button */
.btn-ghost {
    background: transparent;
    color: var(--color-text-primary);
}

.btn-ghost:hover {
    background: var(--color-bg-secondary);
}

/* Button Sizes */
.btn-sm {
    padding: 0.5rem 1rem;
    font-size: var(--font-size-sm);
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: var(--font-size-lg);
}

.btn-xl {
    padding: 1.25rem 2.5rem;
    font-size: var(--font-size-xl);
}

/* Rounded Button */
.btn-rounded {
    border-radius: var(--radius-full);
}

/* Icon Button */
.btn-icon {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border-radius: var(--radius-full);
}

/* Disabled State */
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ==================== 卡片元件 ==================== */

.card {
    background: var(--color-bg-primary);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
    transition: all var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-4px);
}

/* Card Variants */
.card-flat {
    box-shadow: none;
    border: 1px solid var(--color-border-light);
}

.card-glass {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.card-gradient-warm {
    background: linear-gradient(135deg, var(--color-bg-warm) 0%, var(--color-bg-peach) 100%);
}

.card-gradient-cool {
    background: linear-gradient(135deg, var(--color-bg-tertiary) 0%, #E3F2FD 100%);
}

/* Card Interactive */
.card-interactive {
    cursor: pointer;
}

.card-interactive:hover {
    border-color: var(--color-primary);
}

/* Card Header */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border-light);
}

.card-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
}

/* Card Body */
.card-body {
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

/* Card Footer */
.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border-light);
}

/* ==================== 表單元件 ==================== */

.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    margin-bottom: var(--space-sm);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.form-label-required::after {
    content: ' *';
    color: var(--color-error);
}

/* Input Fields */
.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    color: var(--color-text-primary);
    background: var(--color-bg-primary);
    border: 2px solid var(--color-border-light);
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-10);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--color-text-muted);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
}

.form-select {
    cursor: pointer;
    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 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

/* Input States */
.form-input.error,
.form-textarea.error,
.form-select.error {
    border-color: var(--color-error);
}

.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled {
    background: var(--color-bg-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Helper Text */
.form-helper {
    display: block;
    margin-top: var(--space-xs);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.form-error {
    display: block;
    margin-top: var(--space-xs);
    font-size: var(--font-size-sm);
    color: var(--color-error);
}

/* Checkbox & Radio */
.form-check {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.form-check-label {
    cursor: pointer;
    user-select: none;
}

/* ==================== Modal 元件 ==================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-backdrop);
    padding: var(--space-lg);
}

.modal {
    position: relative;
    background: var(--color-bg-primary);
    border-radius: var(--radius-2xl);
    padding: var(--space-2xl);
    box-shadow: var(--shadow-2xl);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    z-index: var(--z-modal);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.modal-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
}

.modal-close {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text-tertiary);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
}

.modal-body {
    margin-bottom: var(--space-lg);
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

.modal-footer {
    display: flex;
    gap: var(--space-md);
    justify-content: flex-end;
}

/* ==================== Badge 元件 ==================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.badge-primary {
    background: var(--color-primary-10);
    color: var(--color-primary);
}

.badge-secondary {
    background: var(--color-secondary-10);
    color: var(--color-secondary);
}

.badge-success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--color-success);
}

.badge-warning {
    background: rgba(255, 217, 61, 0.2);
    color: #D97706;
}

.badge-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-error);
}

/* ==================== Avatar 元件 ==================== */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    overflow: hidden;
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font-weight: var(--font-weight-semibold);
}

.avatar-sm {
    width: 2rem;
    height: 2rem;
    font-size: var(--font-size-sm);
}

.avatar-md {
    width: 2.5rem;
    height: 2.5rem;
    font-size: var(--font-size-base);
}

.avatar-lg {
    width: 3rem;
    height: 3rem;
    font-size: var(--font-size-lg);
}

.avatar-xl {
    width: 4rem;
    height: 4rem;
    font-size: var(--font-size-xl);
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ==================== Alert 元件 ==================== */

.alert {
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    border-left: 4px solid;
    display: flex;
    gap: var(--space-md);
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border-color: var(--color-success);
    color: #166534;
}

.alert-warning {
    background: rgba(255, 217, 61, 0.2);
    border-color: var(--color-warning);
    color: #92400E;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--color-error);
    color: #991B1B;
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--color-info);
    color: #1E40AF;
}

/* ==================== Utility Classes ==================== */

/* Cursor */
.cursor-pointer {
    cursor: pointer;
}

.cursor-not-allowed {
    cursor: not-allowed;
}

/* Display */
.hidden {
    display: none;
}

.block {
    display: block;
}

.inline-block {
    display: inline-block;
}

.flex {
    display: flex;
}

.inline-flex {
    display: inline-flex;
}

.grid {
    display: grid;
}

/* Flex Utilities */
.flex-row {
    flex-direction: row;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.items-start {
    align-items: flex-start;
}

.items-end {
    align-items: flex-end;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-end {
    justify-content: flex-end;
}

.gap-sm {
    gap: var(--space-sm);
}

.gap-md {
    gap: var(--space-md);
}

.gap-lg {
    gap: var(--space-lg);
}

/* Text Alignment */
.text-left {
    text-align: left;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

/* Font Weight */
.font-light {
    font-weight: var(--font-weight-light);
}

.font-normal {
    font-weight: var(--font-weight-normal);
}

.font-medium {
    font-weight: var(--font-weight-medium);
}

.font-semibold {
    font-weight: var(--font-weight-semibold);
}

.font-bold {
    font-weight: var(--font-weight-bold);
}

/* Text Colors */
.text-primary {
    color: var(--color-text-primary);
}

.text-secondary {
    color: var(--color-text-secondary);
}

.text-muted {
    color: var(--color-text-muted);
}

.text-white {
    color: var(--color-text-white);
}

/* Background Colors */
.bg-primary {
    background: var(--color-primary);
}

.bg-secondary {
    background: var(--color-secondary);
}

.bg-accent {
    background: var(--color-accent);
}

.bg-white {
    background: var(--color-bg-primary);
}

/* Spacing */
.m-0 {
    margin: 0;
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

/* Shadows */
.shadow-sm {
    box-shadow: var(--shadow-sm);
}

.shadow-md {
    box-shadow: var(--shadow-md);
}

.shadow-lg {
    box-shadow: var(--shadow-lg);
}

.shadow-xl {
    box-shadow: var(--shadow-xl);
}

/* Rounded Corners */
.rounded-sm {
    border-radius: var(--radius-sm);
}

.rounded-md {
    border-radius: var(--radius-md);
}

.rounded-lg {
    border-radius: var(--radius-lg);
}

.rounded-xl {
    border-radius: var(--radius-xl);
}

.rounded-full {
    border-radius: var(--radius-full);
}

/* Transitions */
.transition {
    transition: all var(--transition-base);
}

.transition-fast {
    transition: all var(--transition-fast);
}

.transition-slow {
    transition: all var(--transition-slow);
}