/* components.css — Buttons, inputs, cards, badges, table, toast, modal, empty */

/* ── Button ─────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    height: 32px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.05s;
    border: 1px solid transparent;
    white-space: nowrap;
    user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-active); }

.btn-secondary {
    background: transparent;
    border-color: var(--border-default);
    color: var(--text-secondary);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--bg-elevated);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-sm { height: 28px; padding: 0 var(--space-2); font-size: var(--text-xs); }
.btn-lg { height: 40px; padding: 0 var(--space-4); font-size: var(--text-md); }
.btn-block { width: 100%; }

.btn .icon { width: 14px; height: 14px; }

/* ── Input ─────────────────────────────────────── */
.input {
    width: 100%;
    height: 32px;
    padding: 0 var(--space-3);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
    transition: border-color 0.12s, background 0.12s;
    outline: none;
}
.input:hover { border-color: var(--border-strong); }
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }
.input:disabled { opacity: 0.5; cursor: not-allowed; }

.input-lg { height: 40px; font-size: var(--text-base); }

textarea.input {
    height: auto;
    min-height: 100px;
    padding: var(--space-3);
    line-height: 1.6;
    font-family: var(--font-mono);
    resize: vertical;
}

.input-group {
    display: flex; align-items: center;
    position: relative;
}
.input-group .input { padding-left: 32px; }
.input-group-icon {
    position: absolute; left: 10px;
    color: var(--text-muted);
    pointer-events: none;
}
.input-group .input { padding-left: 32px; }

/* ── Card / Panel ───────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    min-height: 48px;
}

.card-title {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    display: flex; align-items: center; gap: var(--space-2);
}

.card-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

.card-body { padding: var(--space-4); }
.card-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-default);
    background: var(--bg-elevated);
}

/* ── Stat Card ─────────────────────────────────── */
.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 3px; height: 100%;
    background: var(--text-muted);
    transition: width 0.2s ease;
}
.stat-card:hover { border-color: var(--border-accent); transform: translateY(-1px); }
.stat-card:hover::before { width: 4px; }
.stat-card.success::before { background: var(--success); }
.stat-card.danger::before  { background: var(--danger); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.info::before    { background: var(--info); }

.stat-label {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: var(--weight-medium);
    display: flex; align-items: center; gap: var(--space-2);
}

.stat-value {
    font-size: var(--text-2xl);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    margin-top: var(--space-2);
    line-height: 1.1;
    font-family: var(--font-sans);
    font-variant-numeric: tabular-nums;
}

.stat-trend {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.stat-card.success .stat-value { color: var(--success); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.info .stat-value { color: var(--info); }

/* ── Stat Grid ─────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

/* ── Badge / Pill ──────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    height: 20px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    white-space: nowrap;
}
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.mono { font-family: var(--font-mono); font-size: 10px; }

.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Table ─────────────────────────────────────── */
.table-wrapper { overflow: auto; max-height: 100%; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.table thead {
    position: sticky; top: 0;
    background: var(--bg-surface);
    z-index: 1;
}

.table th {
    text-align: left;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border-default);
    background: var(--bg-surface);
    white-space: nowrap;
}

.table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-default);
    color: var(--text-secondary);
    vertical-align: middle;
}

.table tbody tr:hover { background: var(--bg-elevated); }
.table tbody tr:last-child td { border-bottom: none; }

.table-compact th,
.table-compact td { padding: var(--space-1) var(--space-3); }

.row-success { box-shadow: inset 2px 0 0 var(--success); }
.row-danger  { box-shadow: inset 2px 0 0 var(--danger); }
.row-warning { box-shadow: inset 2px 0 0 var(--warning); }
.row-info    { box-shadow: inset 2px 0 0 var(--info); }

.text-success { color: var(--success); font-weight: var(--weight-medium); }
.text-danger { color: var(--danger); font-weight: var(--weight-medium); }
.text-warning { color: var(--warning); font-weight: var(--weight-medium); }
.text-info { color: var(--info); font-weight: var(--weight-medium); }

/* ── Empty State ───────────────────────────────── */
.empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: var(--space-10) var(--space-5);
    text-align: center;
    color: var(--text-muted);
}
.empty-icon {
    color: var(--text-muted);
    opacity: 0.4;
    margin-bottom: var(--space-3);
}
.empty-icon svg { width: 48px; height: 48px; }
.empty-title { color: var(--text-secondary); font-size: var(--text-md); font-weight: var(--weight-medium); margin-bottom: 4px; }
.empty-desc { color: var(--text-muted); font-size: var(--text-sm); max-width: 360px; }

/* ── Toast ─────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    display: flex; flex-direction: column; gap: var(--space-2);
    z-index: 1000;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    width: 360px;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-overlay);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex; align-items: flex-start; gap: var(--space-3);
    animation: toast-in 0.2s ease;
    font-size: var(--text-sm);
}
.toast.toast-out { animation: toast-out 0.2s ease forwards; }

.toast-icon { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--success); }
.toast.danger .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--info); }

.toast-content { flex: 1; min-width: 0; }
.toast-title { font-weight: var(--weight-medium); color: var(--text-primary); }
.toast-msg { color: var(--text-secondary); margin-top: 2px; font-size: var(--text-xs); }

.toast-close {
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    margin-left: var(--space-2);
    flex-shrink: 0;
}
.toast-close:hover { background: var(--bg-elevated); color: var(--text-primary); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
    to { opacity: 0; transform: translateX(20px); }
}

/* ── Modal ─────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
    animation: fade-in 0.15s ease;
}
.modal {
    width: 100%;
    max-width: 440px;
    background: var(--bg-overlay);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    animation: modal-in 0.15s ease;
}
.modal-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-default);
}
.modal-title { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.modal-body { padding: var(--space-4); }
.modal-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-default);
    display: flex; justify-content: flex-end; gap: var(--space-2);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Spinner / Skeleton ────────────────────────── */
.spinner {
    display: inline-block; width: 14px; height: 14px;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--bg-elevated) 0%, var(--bg-overlay) 50%, var(--bg-elevated) 100%);
    background-size: 200% 100%;
    animation: skeleton 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}
@keyframes skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Refined button + focus transitions globally */
.btn { transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn-primary { box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset; }
.btn-primary:hover { box-shadow: 0 4px 12px rgba(94,106,210,0.25); }

/* ── Progress ──────────────────────────────────── */
.progress {
    height: 6px;
    background: var(--bg-elevated);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
    width: 0%;
}
.progress-text {
    position: absolute; right: 0; top: -18px;
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ── Filter Chips ──────────────────────────────── */
.chip-group {
    display: inline-flex; align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 2px;
    gap: 2px;
}

.chip {
    height: 26px;
    padding: 0 var(--space-3);
    display: inline-flex; align-items: center; gap: var(--space-1);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    transition: background 0.12s, color 0.12s;
    cursor: pointer;
    background: transparent;
    border: none;
}
.chip:hover { color: var(--text-primary); }
.chip.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.chip-count { color: var(--text-muted); font-size: 10px; }
.chip.active .chip-count { color: var(--text-secondary); }

/* ── Divider ───────────────────────────────────── */
.divider {
    height: 1px;
    background: var(--border-default);
    margin: var(--space-4) 0;
    border: none;
}

/* ── Layout helpers ────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }
