/* ============================================
   MARKET TITAN - UI Components
   Fintech Premium Aesthetic
   Clean, Sophisticated, Professional
   ============================================ */

/* ===== BUTTONS ===== */

/* Base button styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: var(--font-body);
    font-weight: var(--font-semibold);
    border: none;
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.98);
}

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

/* Button sizes */
.btn-sm {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
}

.btn-md {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-base);
    border-radius: var(--radius-md);
}

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: var(--text-lg);
    border-radius: var(--radius-lg);
}

/* Primary button (solid emerald green) */
.btn-primary {
    background: var(--accent-primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--accent-primary-dim);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

/* Secondary button (transparent with border) */
.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-default);
}

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

/* Danger button (solid red for sell) */
.btn-danger {
    background: var(--accent-negative);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
    background: var(--accent-negative-dim);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Ghost button (text only) */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
}

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

/* Icon button */
.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.btn-icon:hover {
    background: var(--bg-elevated);
    color: var(--accent-primary);
    border-color: var(--border-default);
}

/* ===== CARDS ===== */

/* Base card - solid background, clean border */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

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

/* Elevated card */
.card-elevated {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

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

/* Period card (for trading periods) */
.period-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    position: relative;
    transition: all var(--transition-base);
}

.period-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-primary);
    opacity: 0;
    transition: opacity var(--transition-base);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.period-card.active::before {
    opacity: 1;
}

.period-card:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-md);
}

/* Stat card */
.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
}

.stat-card-positive {
    border-left: 3px solid var(--accent-primary);
}

.stat-card-negative {
    border-left: 3px solid var(--accent-negative);
}

.stat-card-neutral {
    border-left: 3px solid var(--accent-blue);
}

/* ===== FORMS ===== */

/* Input fields */
.input,
.textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-base);
    transition: all var(--transition-base);
}

.input:focus,
.textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-secondary);
}

.input:disabled,
.textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-secondary);
}

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

.textarea {
    min-height: 120px;
    resize: vertical;
}

/* Input with icon */
.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group .input {
    padding-left: var(--space-10);
}

.input-icon {
    position: absolute;
    left: var(--space-4);
    color: var(--text-muted);
    pointer-events: none;
}

/* Select dropdown */
.select {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-base);
    cursor: pointer;
    transition: all var(--transition-base);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23a1a1aa' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-4) center;
    padding-right: var(--space-10);
}

.select:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-secondary);
}

.select:hover {
    border-color: var(--border-default);
}

/* Toggle switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

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

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

.toggle-slider::before {
    position: absolute;
    content: '';
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--text-muted);
    transition: var(--transition-base);
    border-radius: 50%;
}

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

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

.toggle input:focus + .toggle-slider {
    border-color: var(--accent-primary);
}

/* Checkbox */
.checkbox {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    gap: var(--space-2);
}

.checkbox input {
    width: 20px;
    height: 20px;
    appearance: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    cursor: pointer;
    position: relative;
    transition: all var(--transition-base);
}

.checkbox input:checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.checkbox input:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: var(--text-sm);
    font-weight: bold;
}

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

/* Radio button */
.radio {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    gap: var(--space-2);
}

.radio input {
    width: 20px;
    height: 20px;
    appearance: none;
    border: 1px solid var(--border-default);
    border-radius: 50%;
    background: var(--bg-tertiary);
    cursor: pointer;
    position: relative;
    transition: all var(--transition-base);
}

.radio input:checked {
    border-color: var(--accent-primary);
}

.radio input:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-primary);
}

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

/* ===== BADGES ===== */

/* Base badge - small, pill-shaped */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    font-family: var(--font-body);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

/* Difficulty badges */
.badge-difficulty-easy {
    background: var(--accent-primary-bg);
    color: var(--accent-primary);
}

.badge-difficulty-medium {
    background: var(--accent-amber-bg);
    color: var(--accent-amber);
}

.badge-difficulty-hard {
    background: var(--accent-negative-bg);
    color: var(--accent-negative);
}

/* Status badges */
.badge-status-live {
    background: var(--accent-negative-bg);
    color: var(--accent-negative);
}

.badge-status-live::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-negative);
}

.badge-status-active {
    background: var(--accent-primary-bg);
    color: var(--accent-primary);
}

.badge-status-active::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-primary);
}

.badge-status-completed {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.badge-status-upcoming {
    background: var(--accent-blue-bg);
    color: var(--accent-blue);
}

/* ===== AVATARS ===== */

.avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-weight: var(--font-semibold);
    flex-shrink: 0;
    border: 1px solid var(--border-subtle);
}

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

/* Avatar sizes */
.avatar-xs {
    width: 24px;
    height: 24px;
    font-size: var(--text-xs);
}

.avatar-sm {
    width: 32px;
    height: 32px;
    font-size: var(--text-sm);
}

.avatar-md {
    width: 40px;
    height: 40px;
    font-size: var(--text-base);
}

.avatar-lg {
    width: 56px;
    height: 56px;
    font-size: var(--text-lg);
}

.avatar-xl {
    width: 72px;
    height: 72px;
    font-size: var(--text-xl);
}

/* Online indicator - small, refined dot */
.avatar-online::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: 2px solid var(--bg-primary);
}

/* ===== DATA TABLES ===== */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.table thead {
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-default);
}

.table th {
    padding: var(--space-4);
    text-align: left;
    font-family: var(--font-body);
    font-weight: var(--font-semibold);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.table td {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

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

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

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Table cell variants */
.table-cell-positive {
    color: var(--accent-primary);
    font-weight: var(--font-semibold);
}

.table-cell-negative {
    color: var(--accent-negative);
    font-weight: var(--font-semibold);
}

.table-cell-mono {
    font-family: var(--font-mono);
}

/* Striped table */
.table-striped tbody tr:nth-child(even) {
    background: var(--bg-secondary);
}

/* Bordered table */
.table-bordered {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table-bordered th,
.table-bordered td {
    border-right: 1px solid var(--border-subtle);
}

.table-bordered th:last-child,
.table-bordered td:last-child {
    border-right: none;
}

/* ===== CHAT (Slack-style) ===== */

.chat-message {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    transition: background var(--transition-base);
}

.chat-message:hover {
    background: var(--bg-hover);
}

.chat-message + .chat-message {
    border-top: 1px solid var(--border-subtle);
}

.chat-avatar {
    flex-shrink: 0;
}

.chat-content {
    flex: 1;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
}

.chat-name {
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.chat-timestamp {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.chat-body {
    color: var(--text-primary);
    line-height: var(--leading-normal);
}

/* ===== LEADERBOARD ROWS ===== */

.leaderboard-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    transition: all var(--transition-base);
    margin-bottom: var(--space-2);
}

.leaderboard-row:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-default);
    box-shadow: var(--shadow-sm);
}

.leaderboard-rank {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}

/* Top 3 highlighting */
.leaderboard-row:nth-child(1) .leaderboard-rank {
    background: var(--accent-amber-bg);
    color: var(--accent-amber);
    border-color: var(--accent-amber);
    font-weight: var(--font-bold);
}

.leaderboard-row:nth-child(2) .leaderboard-rank {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.leaderboard-row:nth-child(3) .leaderboard-rank {
    background: rgba(205, 127, 50, 0.1);
    color: #cd7f32;
    border-color: rgba(205, 127, 50, 0.3);
}

.leaderboard-info {
    flex: 1;
    min-width: 0;
}

.leaderboard-name {
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.leaderboard-stats {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.leaderboard-score {
    font-family: var(--font-mono);
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--accent-primary);
}

/* ===== PROGRESS BARS ===== */

.progress {
    width: 100%;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent-primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-slow);
}

/* Progress variants */
.progress-bar-green {
    background: var(--accent-primary);
}

.progress-bar-red {
    background: var(--accent-negative);
}

.progress-bar-blue {
    background: var(--accent-blue);
}

.progress-bar-purple {
    background: var(--accent-purple);
}

.progress-bar-amber {
    background: var(--accent-amber);
}

/* Larger progress bar */
.progress-lg {
    height: 6px;
}

.progress-xl {
    height: 8px;
}

/* ===== TABS ===== */

/* Underline style tabs */
.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border-subtle);
}

.tab {
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-body);
    font-weight: var(--font-medium);
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-base);
}

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

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

/* ===== TOOLTIPS ===== */

.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip-content {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    z-index: var(--z-tooltip);
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-base);
    pointer-events: none;
}

.tooltip-content::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px;
    border-style: solid;
    border-color: var(--bg-primary) transparent transparent transparent;
}

.tooltip:hover .tooltip-content {
    visibility: visible;
    opacity: 1;
    bottom: 135%;
}

/* ===== MODALS ===== */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    animation: fadeIn 0.2s ease;
}

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
    z-index: 1000;
}

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

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

.modal-title {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--accent-negative);
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: var(--space-6);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

/* ===== DIVIDERS ===== */

.divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-4) 0;
}

.divider-vertical {
    width: 1px;
    background: var(--border-subtle);
    margin: 0 var(--space-4);
}

/* ===== LOADING & SKELETON ===== */

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

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

.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-elevated) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== TEXT UTILITIES ===== */

.text-positive {
    color: var(--accent-primary);
}

.text-negative {
    color: var(--accent-negative);
}

.text-neutral {
    color: var(--accent-blue);
}

.text-warning {
    color: var(--accent-amber);
}

.text-mono {
    font-family: var(--font-mono);
}

.text-display {
    font-family: var(--font-display);
}
