/* ============================================
   Facand Dashboard — Components
   ============================================ */

/* ============================================
   Buttons
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}

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

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px var(--primary-100);
}

.btn-outline {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border);
}

.btn-outline:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-dark);
    border-color: var(--danger-dark);
}

.btn-sm {
    padding: 0.3125rem 0.625rem;
    font-size: 0.8125rem;
    border-radius: var(--radius-sm);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 0.5rem;
}

/* ============================================
   Forms
   ============================================ */

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.375rem;
}

.form-input,
.form-select,
.form-textarea {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: var(--font);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
}

input.form-input,
select.form-input {
    height: 40px;
}

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

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

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

select.form-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
}

.form-help {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.form-error {
    font-size: 0.8125rem;
    color: var(--danger);
    margin-top: 0.25rem;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row > .form-group {
    flex: 1;
    min-width: 0;
}

.form-row-between {
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.form-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-soft);
    cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.form-link {
    font-size: 0.8125rem;
    color: var(--primary);
    text-decoration: none;
}

.form-link:hover {
    text-decoration: underline;
}

.form-static {
    font-size: 0.875rem;
    color: var(--text);
    padding: 0.5rem 0;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    padding-top: 0.5rem;
}

.settings-form {
    max-width: 560px;
}

/* ============================================
   Tables
   ============================================ */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table thead th {
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-soft);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.table tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

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

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

/* ============================================
   Cards
   ============================================ */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

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

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.card-body {
    padding: 1.25rem;
}

.card-body-flush {
    padding: 0;
}

.card-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============================================
   Badges
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    white-space: nowrap;
    line-height: 1.6;
}

.badge-primary {
    background: var(--primary-100);
    color: var(--primary);
}

.badge-success,
.badge-approved,
.badge-active,
.badge-paid {
    background: var(--success-light);
    color: var(--success-dark);
}

.badge-warning,
.badge-pending,
.badge-review {
    background: var(--warning-light);
    color: var(--warning-dark);
}

.badge-danger,
.badge-failed,
.badge-rejected,
.badge-overdue {
    background: var(--danger-light);
    color: var(--danger-dark);
}

.badge-info,
.badge-processing,
.badge-new {
    background: var(--info-light);
    color: var(--info-dark);
}

.badge-default,
.badge-inactive,
.badge-draft {
    background: var(--bg);
    color: var(--text-soft);
    border: 1px solid var(--border);
}

/* ============================================
   KPI Cards
   ============================================ */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: box-shadow var(--transition), transform var(--transition);
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon svg {
    width: 24px;
    height: 24px;
}

.kpi-icon-primary {
    background: var(--primary-100);
    color: var(--primary);
}

.kpi-icon-success {
    background: var(--success-light);
    color: var(--success);
}

.kpi-icon-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.kpi-icon-info {
    background: var(--info-light);
    color: var(--info);
}

.kpi-icon-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.kpi-body {
    flex: 1;
    min-width: 0;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

.kpi-label {
    font-size: 0.8125rem;
    color: var(--text-soft);
    margin-top: 0.125rem;
}

/* ============================================
   Modal
   ============================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

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

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.2s ease;
}

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

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

.modal-title {
    font-size: 1.0625rem;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.25rem;
    line-height: 1;
    transition: color var(--transition);
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============================================
   Toast
   ============================================ */

.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    pointer-events: auto;
    animation: toastIn 0.3s ease;
    max-width: 360px;
}

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

.toast-exit {
    animation: toastOut 0.25s ease forwards;
}

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

.toast-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

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

/* ============================================
   Pagination
   ============================================ */

.pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    list-style: none;
    padding: 0;
    margin: 1.5rem 0 0;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition);
}

.pagination a:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.pagination .active span {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.pagination .disabled span {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============================================
   Filters Bar
   ============================================ */

.filters {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filters .form-input,
.filters .form-select {
    width: auto;
    min-width: 160px;
}

.filters .btn {
    flex-shrink: 0;
}

/* ============================================
   Alerts
   ============================================ */

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 1rem;
}

.alert-success {
    background: var(--success-light);
    color: var(--success-dark);
    border: 1px solid var(--success);
}

.alert-warning {
    background: var(--warning-light);
    color: var(--warning-dark);
    border: 1px solid var(--warning);
}

.alert-danger {
    background: var(--danger-light);
    color: var(--danger-dark);
    border: 1px solid var(--danger);
}

.alert-info {
    background: var(--info-light);
    color: var(--info-dark);
    border: 1px solid var(--info);
}

/* ============================================
   Empty State
   ============================================ */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-state svg {
    margin: 0 auto 1rem;
}

.empty-state-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.empty-state-sub {
    font-size: 0.875rem;
    color: var(--text-soft);
}

/* ============================================
   Auth Form tweaks
   ============================================ */

.auth-form .form-group:last-of-type {
    margin-bottom: 0;
}

.auth-subtitle {
    font-size: 0.875rem;
    color: var(--text-soft);
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

/* ============================================
   Responsive overrides
   ============================================ */

@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .table {
        font-size: 0.8125rem;
    }

    .table thead th,
    .table tbody td {
        padding: 0.625rem 0.75rem;
    }
}

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

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filters .form-input,
    .filters .form-select {
        width: 100%;
        min-width: 0;
    }
}
