/* ════════════════════════════════════════════════════════════
   RahnMas — Components
   ──────────────────────────────────────────────────────────── */

/* ── BUTTON ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.2;
    border-radius: var(--r-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.18s ease;
    text-decoration: none;
    white-space: nowrap;
    min-height: 42px;
}
.btn:disabled, .btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-gold);
}
.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}
.btn-accent:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-emerald);
    color: #fff;
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--gold-300);
}
.btn-outline:hover:not(:disabled) {
    background: var(--gold-50);
    border-color: var(--primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover:not(:disabled) {
    background: #B91C1C;
    color: #fff;
}

.btn-sm {
    padding: 0.4rem 0.875rem;
    font-size: 0.8125rem;
    min-height: 32px;
    border-radius: var(--r-sm);
}
.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
    min-height: 52px;
}
.btn-block {
    width: 100%;
}

/* ── CARD ──────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.card-compact { padding: 1rem; }
.card-tight   { padding: 0.75rem; }

.card-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.card-subtitle {
    color: var(--text-dim);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.card-gold {
    background: linear-gradient(135deg, var(--gold-50) 0%, #FFFFFF 100%);
    border-color: var(--gold-200);
}
.card-emerald {
    background: linear-gradient(135deg, var(--emerald-50) 0%, #FFFFFF 100%);
    border-color: var(--emerald-200);
}

/* ── FORM ──────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.25rem;
}
.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-2);
    margin-bottom: 0.4rem;
}
.form-label .required {
    color: var(--danger);
    margin-left: 2px;
}
.form-hint {
    font-size: 0.8125rem;
    color: var(--text-dim);
    margin-top: 0.35rem;
}
.form-error {
    font-size: 0.8125rem;
    color: var(--danger-text);
    margin-top: 0.35rem;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    line-height: 1.4;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--r-md);
    transition: all 0.15s;
    min-height: 44px;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(200, 146, 42, 0.12);
}
.form-control:disabled {
    background: var(--surface-3);
    color: var(--text-muted);
    cursor: not-allowed;
}
.form-control.is-invalid {
    border-color: var(--danger);
}
.form-control.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

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

select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23475569' stroke-width='1.5' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    background-size: 12px 8px;
    padding-right: 2.5rem;
}

/* Input prefix/suffix */
.input-group {
    position: relative;
    display: flex;
    align-items: center;
}
.input-prefix, .input-suffix {
    position: absolute;
    color: var(--text-dim);
    font-size: 0.875rem;
    pointer-events: none;
    user-select: none;
}
.input-prefix { left: 0.875rem; }
.input-suffix { right: 0.875rem; }
.input-group .form-control:has(~ .input-prefix),
.input-group .form-control.pl-8 { padding-left: 2.75rem; }
.input-group:has(.input-prefix) .form-control { padding-left: 2.75rem; }
.input-group:has(.input-suffix) .form-control { padding-right: 2.75rem; }

/* File input */
.file-input-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}
.file-input-wrapper input[type="file"] {
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0;
}
.file-input-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 1rem;
    background: var(--cream-50);
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--r-md);
    color: var(--text-2);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s;
    min-height: 60px;
}
.file-input-label:hover {
    border-color: var(--primary);
    background: var(--gold-50);
    color: var(--primary);
}
.file-input-label .file-name {
    color: var(--text);
    font-weight: 500;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--slate-300);
    border-radius: 24px;
    transition: 0.2s;
    cursor: pointer;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px; height: 18px;
    left: 3px; bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* ── BADGE ─────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    border-radius: var(--r-full);
    white-space: nowrap;
}
.badge-gold     { background: var(--gold-100); color: var(--gold-800); }
.badge-emerald  { background: var(--emerald-100); color: var(--emerald-800); }
.badge-success  { background: var(--success-bg); color: var(--success-text); }
.badge-warning  { background: var(--warning-bg); color: var(--warning-text); }
.badge-danger   { background: var(--danger-bg); color: var(--danger-text); }
.badge-info     { background: var(--info-bg); color: var(--info-text); }
.badge-neutral  { background: var(--slate-100); color: var(--slate-700); }
.badge-dot::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    margin-right: 0.25rem;
}

/* Status-specific badges */
.status-aktif       { background: var(--emerald-100); color: var(--emerald-800); }
.status-lunas       { background: var(--info-bg); color: var(--info-text); }
.status-jatuh_tempo { background: var(--warning-bg); color: var(--warning-text); }
.status-lelang      { background: var(--danger-bg); color: var(--danger-text); }
.status-closed      { background: var(--slate-100); color: var(--slate-700); }
.status-belum_bayar { background: var(--slate-100); color: var(--slate-700); }
.status-sebagian    { background: var(--warning-bg); color: var(--warning-text); }
.status-terlambat   { background: var(--danger-bg); color: var(--danger-text); }
.status-pending     { background: var(--warning-bg); color: var(--warning-text); }
.status-verified    { background: var(--success-bg); color: var(--success-text); }
.status-rejected    { background: var(--danger-bg); color: var(--danger-text); }
.status-expired     { background: var(--slate-100); color: var(--slate-500); }

/* ── TABLE ─────────────────────────────────────────────── */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.table thead {
    background: var(--cream-100);
    border-bottom: 1px solid var(--border);
}
.table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-2);
    font-size: 0.8125rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.table td {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr:hover {
    background: var(--cream-50);
}
.table tbody tr:first-child td { border-top: none; }

.table-empty {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-dim);
}

/* Mobile: tabel jadi card list */
@media (max-width: 768px) {
    .table-responsive thead { display: none; }
    .table-responsive tbody tr {
        display: block;
        padding: 0.875rem 1rem;
        border-top: 1px solid var(--border);
    }
    .table-responsive tbody tr:first-child { border-top: none; }
    .table-responsive tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        padding: 0.35rem 0;
        border-top: none;
    }
    .table-responsive tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-dim);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }
    .table-responsive tbody td.td-actions {
        justify-content: flex-end;
        padding-top: 0.5rem;
    }
    .table-responsive tbody td.td-actions::before { content: ''; }
}

/* ── MODAL ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--surface);
    border-radius: var(--r-xl);
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    transform: translateY(10px) scale(0.98);
    transition: transform 0.2s;
}
.modal-overlay.show .modal {
    transform: translateY(0) scale(1);
}
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.modal-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}
.modal-close {
    width: 36px; height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-dim);
    transition: all 0.15s;
}
.modal-close:hover {
    background: var(--surface-2);
    color: var(--text);
}
.modal-body {
    padding: 1.5rem;
}
.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    background: var(--surface-3);
}

/* ── TOAST ─────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    max-width: calc(100vw - 2rem);
}
@media (max-width: 640px) {
    .toast-container {
        left: 1rem;
        right: 1rem;
        top: 1rem;
    }
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--text-dim);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    max-width: 420px;
    font-size: 0.875rem;
    color: var(--text);
    animation: toastIn 0.25s ease-out;
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-info    { border-left-color: var(--info); }

.toast-icon {
    flex-shrink: 0;
    width: 20px; height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.toast-message {
    flex: 1;
    line-height: 1.4;
}
.toast-close {
    color: var(--text-muted);
    padding: 0.125rem;
}
.toast-close:hover { color: var(--text); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── ALERT ─────────────────────────────────────────────── */
.alert {
    padding: 0.875rem 1rem;
    border-radius: var(--r-md);
    border: 1px solid;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    font-size: 0.875rem;
    line-height: 1.5;
}
.alert-success {
    background: var(--success-bg);
    border-color: var(--emerald-200);
    color: var(--success-text);
}
.alert-warning {
    background: var(--warning-bg);
    border-color: #FCD34D;
    color: var(--warning-text);
}
.alert-danger {
    background: var(--danger-bg);
    border-color: #FCA5A5;
    color: var(--danger-text);
}
.alert-info {
    background: var(--info-bg);
    border-color: #BFDBFE;
    color: var(--info-text);
}

/* ── LOADER / SPINNER ──────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 2.5px solid var(--cream-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.spinner-sm { width: 14px; height: 14px; border-width: 2px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

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

.loading-block {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem 1rem;
    color: var(--text-dim);
    font-size: 0.875rem;
}

/* ── EMPTY STATE ───────────────────────────────────────── */
.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-dim);
}
.empty-state-icon {
    width: 56px; height: 56px;
    margin: 0 auto 1rem;
    color: var(--text-muted);
}
.empty-state-title {
    color: var(--text-2);
    font-weight: 500;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}
.empty-state-desc {
    font-size: 0.875rem;
    color: var(--text-dim);
}

/* ── DIVIDER ───────────────────────────────────────────── */
.divider {
    height: 1px;
    background: var(--border);
    margin: 1.5rem 0;
    border: none;
}
.divider-thick { height: 2px; }
.divider-gold {
    background: linear-gradient(90deg, transparent, var(--gold-300), transparent);
    height: 1px;
}

/* ── STAT CARD ─────────────────────────────────────────── */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.15s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-dim);
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.stat-value {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
    word-break: break-all;
}
.stat-meta {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-dim);
}
.stat-icon {
    width: 36px; height: 36px;
    border-radius: var(--r-md);
    background: var(--gold-50);
    color: var(--gold-700);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}
.stat-icon.emerald { background: var(--emerald-50); color: var(--emerald-700); }
.stat-icon.info    { background: var(--info-bg); color: var(--info-text); }
.stat-icon.danger  { background: var(--danger-bg); color: var(--danger-text); }
.stat-icon.warning { background: var(--warning-bg); color: var(--warning-text); }

/* ── PAGINATION ────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0;
    flex-wrap: wrap;
}
.pagination-info {
    font-size: 0.875rem;
    color: var(--text-dim);
}
.pagination-controls {
    display: flex;
    gap: 0.25rem;
}
.pagination button {
    min-width: 36px;
    height: 36px;
    padding: 0 0.625rem;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--r-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-2);
    transition: all 0.15s;
}
.pagination button:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}
.pagination button.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}
.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── TABS ──────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-dim);
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
}
.tab:hover { color: var(--text-2); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ── GRID UTILITIES ────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

@media (max-width: 768px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .grid-4 { grid-template-columns: 1fr; }
}
