/* ============================================
   KOPERASI KOMIU - Components CSS
   Modal, Loading, Toast, Confirm
   ============================================ */

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}
.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}
.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-spring);
}
.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}
.modal-content.lg { max-width: 720px; }
.modal-content.xl { max-width: 960px; }
.modal-content.sm { max-width: 400px; }

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 {
    font-size: 1.0625rem;
    font-weight: 600;
}
.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.modal-close:hover {
    background: var(--gray-100);
    color: var(--text);
}
.modal-close svg { width: 20px; height: 20px; }

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Mobile modal - slide up */
@media (max-width: 640px) {
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    .modal-content {
        max-width: 100%;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 85vh;
        transform: translateY(100%);
    }
    .modal-overlay.active .modal-content {
        transform: translateY(0);
    }
}

/* ============================================
   Loading Overlay
   ============================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(6px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}
.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    position: relative;
}
.loading-spinner::before,
.loading-spinner::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid transparent;
}
.loading-spinner::before {
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
}
.loading-spinner::after {
    border-right-color: var(--secondary);
    animation: spin 1.2s linear infinite reverse;
    inset: 4px;
}

.loading-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Inline loading */
.loading-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}
.loading-inline .spinner-sm {
    width: 18px;
    height: 18px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--primary);
    min-width: 300px;
    max-width: 420px;
    pointer-events: auto;
    animation: slideDown 0.4s var(--transition-spring);
    position: relative;
    overflow: hidden;
}
.toast.removing {
    animation: fadeOut 0.3s ease forwards;
}
@keyframes fadeOut {
    to { opacity: 0; transform: translateX(100%); }
}

.toast-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    margin-top: 1px;
}
.toast-body {
    flex: 1;
    min-width: 0;
}
.toast-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.125rem;
}
.toast-message {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.toast-close {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 4px;
    transition: all var(--transition-fast);
}
.toast-close:hover {
    background: var(--gray-100);
    color: var(--text);
}
.toast-close svg { width: 16px; height: 16px; }

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    border-radius: 0 0 0 var(--radius);
    animation: shrink linear forwards;
}
@keyframes shrink {
    from { width: 100%; }
    to { width: 0%; }
}

/* Toast types */
.toast.success { border-left-color: var(--success); }
.toast.success .toast-icon { color: var(--success); }
.toast.success .toast-progress { background: var(--success); }

.toast.error { border-left-color: var(--danger); }
.toast.error .toast-icon { color: var(--danger); }
.toast.error .toast-progress { background: var(--danger); }

.toast.warning { border-left-color: var(--warning); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.warning .toast-progress { background: var(--warning); }

.toast.info { border-left-color: var(--info); }
.toast.info .toast-icon { color: var(--info); }
.toast.info .toast-progress { background: var(--info); }

/* Mobile toast */
@media (max-width: 640px) {
    .toast-container {
        left: 0.5rem;
        right: 0.5rem;
        top: 0.5rem;
    }
    .toast {
        min-width: auto;
        max-width: 100%;
    }
}

/* ============================================
   Confirm Dialog
   ============================================ */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}
.confirm-overlay.active {
    opacity: 1;
    visibility: visible;
}
.confirm-dialog {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow-lg);
    transform: scale(0.85);
    transition: transform var(--transition-spring);
}
.confirm-overlay.active .confirm-dialog {
    transform: scale(1);
}
.confirm-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}
.confirm-icon svg {
    width: 28px;
    height: 28px;
}
.confirm-icon.warning {
    background: #fef3c7;
    color: var(--warning);
}
.confirm-icon.danger {
    background: #fee2e2;
    color: var(--danger);
}
.confirm-icon.info {
    background: #dbeafe;
    color: var(--info);
}
.confirm-title {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text);
}
.confirm-message {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}
.confirm-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}
.confirm-actions .btn {
    flex: 1;
    max-width: 160px;
}

/* ============================================
   Dropdown
   ============================================ */
.dropdown {
    position: relative;
}
.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-100);
    min-width: 180px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
}
.dropdown-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.dropdown-item:hover {
    background: var(--primary-50);
    color: var(--primary);
}
.dropdown-item svg { width: 18px; height: 18px; }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: #fef2f2; }
.dropdown-divider {
    height: 1px;
    background: var(--gray-100);
    margin: 0.25rem 0;
}

/* ============================================
   Search Bar
   ============================================ */
.search-bar {
    position: relative;
}
.search-bar svg {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}
.search-bar input {
    padding-left: 2.5rem;
}

/* ============================================
   Filter Bar
   ============================================ */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--white);
    border-bottom: 1px solid var(--gray-100);
}
.filter-bar .form-control {
    max-width: 200px;
}
@media (max-width: 640px) {
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .form-control { max-width: 100%; }
}

/* ============================================
   Counter (Tabungan Harian)
   ============================================ */
.counter {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.counter-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--gray-50);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 1.125rem;
    font-weight: 600;
}
.counter-btn:hover {
    background: var(--primary-100);
    color: var(--primary);
}
.counter-btn:active {
    background: var(--primary-200);
}
.counter-btn.minus:hover {
    background: #fee2e2;
    color: var(--danger);
}
.counter-value {
    width: 48px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    background: var(--white);
    border-left: 1px solid var(--gray-200);
    border-right: 1px solid var(--gray-200);
}

/* ============================================
   File Upload
   ============================================ */
.file-upload {
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: var(--gray-50);
}
.file-upload:hover, .file-upload.dragover {
    border-color: var(--primary);
    background: var(--primary-50);
}
.file-upload svg {
    width: 40px;
    height: 40px;
    color: var(--text-muted);
    margin: 0 auto 0.5rem;
}
.file-upload p {
    font-size: 0.875rem;
    color: var(--text-muted);
}
.file-upload .browse-text {
    color: var(--primary);
    font-weight: 600;
}
.file-upload input[type="file"] {
    display: none;
}

/* ============================================
   Date Range Picker wrapper
   ============================================ */
.date-range {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.date-range span {
    font-size: 0.875rem;
    color: var(--text-muted);
}
