/* ═══════════════════════════════════════════════════════════════
   ERPA Framework - Components
   Buttons, Cards, Badges, Forms, Modals, Tables, Toasts, etc.
   ═══════════════════════════════════════════════════════════════ */

/* ── BUTTONS ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.125rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-base);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    color: #fff;
    border: none;
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-light);
}

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

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
}
.btn-danger:hover { background: #dc2626; box-shadow: 0 4px 12px var(--danger-light); }

.btn-warning {
    background: var(--warning);
    color: #000;
    border: none;
}
.btn-warning:hover { background: #d97706; }

.btn-success {
    background: var(--success);
    color: #fff;
    border: none;
}
.btn-success:hover { background: #059669; }

.btn-info {
    background: var(--info);
    color: #fff;
    border: none;
}
.btn-info:hover { background: #2563eb; }

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-tertiary); }

.btn-ghost {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-tertiary); }

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0;
    text-decoration: underline;
}

/* Button Sizes */
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.75rem; gap: 0.25rem; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-xl { padding: 1rem 2rem; font-size: 1.125rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 0.5rem; width: 36px; height: 36px; }
.btn-icon.btn-sm { width: 30px; height: 30px; padding: 0.25rem; }

/* ── CARDS ─────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body { padding: 1.5rem; }
.card-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); }

.card-hover { transition: transform var(--transition-base), box-shadow var(--transition-base); }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* Stat Card */
.stat-card { padding: 1.5rem; }
.stat-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}
.stat-card-icon.emerald { background: var(--success-light); color: var(--success); }
.stat-card-icon.blue { background: var(--info-light); color: var(--info); }
.stat-card-icon.purple { background: rgba(139,92,246,0.12); color: #8b5cf6; }
.stat-card-icon.orange { background: var(--warning-light); color: #f97316; }
.stat-card-icon.red { background: var(--danger-light); color: var(--danger); }

.stat-card-value { font-size: 1.875rem; font-weight: 700; margin-bottom: 0.25rem; }
.stat-card-label { font-size: 0.875rem; color: var(--text-muted); }

/* ── BADGES ────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-secondary { background: var(--bg-tertiary); color: var(--text-muted); }
.badge-accent { background: var(--accent-light); color: var(--accent); }

/* Tier badges */
.badge-free { background: rgba(107,114,128,0.15); color: #9ca3af; }
.badge-starter { background: var(--info-light); color: var(--info); }
.badge-business { background: rgba(99,102,241,0.15); color: #818cf8; }
.badge-enterprise { background: var(--warning-light); color: var(--warning); }

/* Status dot */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.status-dot.success, .status-dot.active { background: var(--success); }
.status-dot.warning, .status-dot.pending { background: var(--warning); }
.status-dot.danger, .status-dot.inactive { background: var(--danger); }
.status-dot.info { background: var(--info); }

/* ── FORMS ─────────────────────────────────────────────────── */
.input, .form-input, .form-select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.625rem 0.875rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.input:focus, .form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.input::placeholder, .form-input::placeholder { color: var(--text-muted); }
.input:disabled, .form-input:disabled { opacity: 0.6; cursor: not-allowed; }

.input-sm { padding: 0.375rem 0.625rem; font-size: 0.8125rem; }
.input-lg { padding: 0.75rem 1rem; font-size: 1rem; }

/* Form Layout */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.375rem; font-weight: 500; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }
.form-error { font-size: 0.75rem; color: var(--danger); margin-top: 0.25rem; }

.form-row { display: grid; gap: 1rem; }
.form-row-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 1rem;
}

.form-divider { padding-top: 1rem; margin-top: 1rem; border-top: 1px solid var(--border); }

/* Toggle */
.toggle {
    width: 44px;
    height: 24px;
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background var(--transition-base);
    flex-shrink: 0;
}
.toggle::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition-base);
}
.toggle:checked { background: var(--accent); }
.toggle:checked::before { transform: translateX(20px); }

/* Checkbox, Radio */
.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

/* ── TABLES ────────────────────────────────────────────────── */
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left;
    padding: 0.875rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: var(--table-hover); }
.table-actions { display: flex; gap: 0.375rem; justify-content: flex-end; }

/* ── MODALS ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
    padding: 1rem;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--modal-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    max-height: 90vh;
    overflow: hidden;
    width: 100%;
    animation: fadeIn 0.2s ease;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { font-size: 1.125rem; }

.modal-body { padding: 1.5rem; overflow-y: auto; max-height: calc(90vh - 140px); }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.75rem; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

/* Modal Sizes */
.modal-sm { max-width: 400px; }
.modal-md { max-width: 560px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }

/* ── TOASTS ────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 380px;
}

.toast {
    padding: 0.875rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideIn 0.3s ease;
    font-size: 0.875rem;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info { border-left: 4px solid var(--info); }

/* ── DROPDOWN ──────────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.375rem;
    z-index: 100;
    display: none;
}
.dropdown-menu.show { display: block; animation: fadeIn 0.15s ease; }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.dropdown-item:hover { background: var(--bg-tertiary); text-decoration: none; }
.dropdown-divider { height: 1px; background: var(--border); margin: 0.25rem 0; }

/* ── PAGINATION ────────────────────────────────────────────── */
.pagination { display: flex; gap: 0.25rem; justify-content: center; }
.pagination-btn {
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}
.pagination-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.pagination-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── TABS ──────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.tab {
    padding: 0.75rem 1.25rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── AVATAR ────────────────────────────────────────────────── */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 32px; height: 32px; font-size: 0.75rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.25rem; }
.avatar-xl { width: 80px; height: 80px; font-size: 1.75rem; }

.avatar-accent { background: var(--accent-light); color: var(--accent); }
.avatar-blue { background: var(--info-light); color: var(--info); }
.avatar-purple { background: rgba(139,92,246,0.12); color: #8b5cf6; }
.avatar-orange { background: var(--warning-light); color: #f97316; }

/* ── TOOLTIP ───────────────────────────────────────────────── */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.375rem 0.625rem;
    background: var(--text-primary);
    color: var(--text-inverse);
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    margin-bottom: 6px;
    z-index: 50;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── EMPTY STATE ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state-title { font-size: 1.125rem; font-weight: 600; color: var(--text-primary); margin-bottom: 0.5rem; }
.empty-state-desc { font-size: 0.875rem; max-width: 320px; margin: 0 auto; }

/* ── PROGRESS BAR ──────────────────────────────────────────── */
.progress {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--accent);
    transition: width 0.5s ease;
}
.progress-bar.danger { background: var(--danger); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.info { background: var(--info); }

/* ── FILTER BAR ────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.filter-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}
.filter-input { min-width: 160px; max-width: 240px; }
.filter-select { min-width: 140px; }

/* ── SECTION HEADER ────────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}
.section-title { font-weight: 600; font-size: 1.125rem; }
.section-subtitle { color: var(--text-muted); font-size: 0.875rem; }

/* ── SETTINGS ──────────────────────────────────────────────── */
.settings-group { display: flex; flex-direction: column; gap: 0.75rem; }
.settings-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    transition: background var(--transition-fast);
}
.settings-option:hover { background: var(--bg-tertiary); }
.settings-option-info { flex: 1; }
.settings-option-label { font-weight: 500; margin-bottom: 0.125rem; }
.settings-option-desc { font-size: 0.8125rem; color: var(--text-muted); }

/* ── AUTH/LOADING ──────────────────────────────────────────── */
.auth-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg-primary);
    position: fixed;
    inset: 0;
    z-index: 9999;
}
.auth-loading-content { text-align: center; }
