/* ============================================
   COMPONENTS — Reusable UI Components
   ============================================ */

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn:active {
    transform: translateY(0) scale(0.96);
    transition-duration: 0.1s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 6px -1px rgba(20, 184, 166, 0.4), 0 2px 4px -1px rgba(20, 184, 166, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

[data-theme="light"] .btn-primary {
    /* Ensure visibility on light mode */
    box-shadow: 0 4px 12px rgba(20, 184, 166, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-400), var(--primary-500));
    color: white;
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--bg-surface-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    color: var(--text-primary);
    border-color: var(--border-color-strong);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #16a34a;
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    color: white;
    box-shadow: var(--shadow-glow-danger);
}

.btn-warning {
    background: var(--warning);
    color: #0f172a;
}

.btn-warning:hover {
    background: #d97706;
    color: #0f172a;
}

[data-theme="dark"] .btn-warning {
    color: var(--text-inverse);
}

[data-theme="dark"] .btn-warning:hover {
    color: var(--text-inverse);
}

.btn-info {
    background: var(--info);
    color: white;
}

[data-theme="light"] .btn-info {
    color: white;
}

.btn-info:hover {
    background: #2563eb;
    color: white;
    box-shadow: var(--shadow-glow-info);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.85rem 1.75rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-sm i {
    font-size: 0.75rem;
}

/* ---- Outline Buttons ---- */
.btn-outline-primary {
    background: transparent;
    color: var(--primary-500);
    border: 1px solid var(--primary-500);
}

.btn-outline-primary:hover {
    background: var(--primary-500);
    color: white;
    box-shadow: var(--shadow-glow);
}

.btn-outline-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color-strong);
}

.btn-outline-secondary:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.btn-outline-success {
    background: transparent;
    color: var(--success);
    border: 1px solid var(--success);
}

.btn-outline-success:hover {
    background: var(--success);
    color: white;
}

.btn-outline-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-outline-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-outline-warning {
    background: transparent;
    color: var(--warning);
    border: 1px solid var(--warning);
}

.btn-outline-warning:hover {
    background: var(--warning);
    color: #0f172a;
}

.btn-outline-info {
    background: transparent;
    color: var(--info);
    border: 1px solid var(--info);
}

.btn-outline-info:hover {
    background: var(--info);
    color: white;
}

/* ---- Cards ---- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.card:hover {
    border-color: var(--border-color-strong);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.card-header h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    color: var(--text-primary);
}

.card-body {
    padding: 1.25rem;
}

.card-chart {
    flex: 1.5;
}

/* ---- Stat Cards ---- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.dashboard-row {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    border-radius: 0;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-primary::before {
    background: linear-gradient(90deg, var(--primary-400), var(--primary-600));
}

.stat-success::before {
    background: linear-gradient(90deg, #22c55e, #16a34a);
}

.stat-warning::before {
    background: linear-gradient(90deg, #f59e0b, #d97706);
}

.stat-danger::before {
    background: linear-gradient(90deg, #ef4444, #dc2626);
}

.stat-info::before {
    background: linear-gradient(90deg, #3b82f6, #2563eb);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.stat-primary .stat-icon {
    background: rgba(20, 184, 166, 0.15);
    color: var(--primary-text-active, var(--primary-400));
}

.stat-success .stat-icon {
    background: var(--success-bg);
    color: var(--success);
}

.stat-warning .stat-icon {
    background: var(--warning-bg);
    color: var(--warning);
}

.stat-danger .stat-icon {
    background: var(--danger-bg);
    color: var(--danger);
}

.stat-info .stat-icon {
    background: var(--info-bg);
    color: var(--info);
}

.stat-info-text {
    display: flex;
    flex-direction: column;
}

/* rename to avoid collision with .stat-info */
.stat-card .stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ---- Tables ---- */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table thead th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table tbody td {
    padding: 0.7rem 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.table tbody tr {
    transition: var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--bg-surface-hover);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tfoot td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border-top: 2px solid var(--border-color-strong);
}

.actions {
    white-space: nowrap;
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.row-highlight {
    background: rgba(245, 158, 11, 0.05);
}

.text-right {
    text-align: right;
}

.nowrap {
    white-space: nowrap;
}

/* ---- Mobile Card View for Tables ---- */
@media (max-width: 768px) {

    .table-responsive .table thead {
        display: none;
        /* Hide headers */
    }

    .table-responsive .table tbody tr,
    .table-responsive .table tfoot tr {
        display: block;
        background: var(--bg-surface);
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        margin-bottom: 1rem;
        padding: 1rem;
        box-shadow: var(--shadow-sm);
    }

    .table-responsive .table td {
        display: flex;
        justify-content: flex-start;
        /* Changed from space-between */
        gap: 0.5rem;
        /* Add gap between label and value */
        align-items: center;
        border: none;
        padding: 0.5rem 0;
        text-align: left;
        /* Changed from right */
        border-bottom: 1px dashed var(--border-color);
        flex-wrap: wrap;
        /* Allow wrapping if needed */
    }

    .table-responsive .table td:last-child {
        border-bottom: none;
    }

    /* Label from data-label */
    .table-responsive .table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.85rem;
        color: var(--text-muted);
        text-align: left;
        margin-right: 0.5rem;
        min-width: 100px;
        /* Ensure labels have consistent width for alignment */
        flex-shrink: 0;
    }

    /* Specific adjustments */
    .table tbody td[data-label="Nama"] {
        font-weight: 700;
        color: var(--primary-500);
        font-size: 1rem;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.75rem;
        margin-bottom: 0.5rem;
    }

    .table tbody td[data-label="Nama"]::before {
        display: none;
        /* Hide "Nama" label as it's the title */
    }

    /* Actions Column - Side-by-Side Buttons (anti salah tekan) */
    .table-responsive .table tbody td.actions {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 0.75rem;
        align-items: stretch;
        margin-top: 0.5rem;
        border-top: 1px dashed var(--border-color);
        padding-top: 1rem;
    }

    .table-responsive .table tbody td.actions::before {
        display: none !important;
    }

    .table-responsive .table tbody td.actions .btn,
    .table-responsive .table tbody td.actions form {
        flex: 1 1 0% !important;
        min-width: 0 !important;
        width: auto !important;
        display: block !important;
    }

    .table-responsive .table tbody td.actions form .btn {
        width: 100%;
        display: inline-flex !important;
        justify-content: center;
    }

    .table-responsive .table tbody td.actions a.btn {
        width: 100%;
        display: inline-flex !important;
        justify-content: center;
    }

    /* Mobile Filter Bar - Stacked & Full Width */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .filter-bar input,
    .filter-bar select,
    .filter-bar button {
        width: 100% !important;
        flex-basis: auto !important;
        min-width: 0;
    }

    /* Card Header - Side-by-Side Buttons */
    .card-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .card-header h3 {
        flex: 1;
        min-width: 0;
    }

    .header-actions {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.5rem;
        align-items: center;
        flex-shrink: 0;
    }

    .header-actions .dropdown {
        margin-left: 0 !important;
    }

    /* Modal Footer - Side-by-Side Buttons */
    .modal-footer {
        flex-direction: row !important;
        flex-wrap: nowrap;
    }

    .modal-footer .btn {
        flex: 1;
    }

    /* Form Actions - Side-by-Side Buttons */
    .form-actions {
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 0.75rem;
    }

    .form-actions .btn {
        flex: 1;
        justify-content: center;
        width: 100%;
    }

    /* Card Header Actions - Stack vertically on mobile */
    .card-header-actions {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
        margin-top: 0.5rem;
    }

    .card-header-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .btn-mobile-block {
        width: 100% !important;
        justify-content: center !important;
    }

    /* Dashboard Grid Responsive */
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 480px) {
    .dashboard-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ---- Forms ---- */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.form-row-responsive {
    grid-column: span 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 640px) {

    .form-row-responsive,
    div.form-row-responsive,
    .form-grid>.form-row-responsive {
        grid-template-columns: 1fr !important;
        grid-column: span 1 !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }
}

.grand-total-input {
    font-size: 1.5rem;
    height: 3.5rem;
    font-weight: 700;
    color: var(--primary-500);
    border: 2px solid var(--primary-500);
    background: var(--bg-surface);
}

[data-theme="dark"] .grand-total-input {
    background: var(--bg-surface-2);
}

@media (max-width: 640px) {
    .grand-total-input {
        font-size: 1.25rem;
        height: 3.25rem;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
    padding: 0.65rem 0.9rem;
    background: var(--bg-surface-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    transition: var(--transition);
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15);
}

.form-control {
    width: 100%;
}

/* ---- Input Group ---- */
.input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.search-bar .input-group {
    max-width: 400px;
    /* Shorten the search field as requested */
}

.input-group .form-control,
.input-group input[type="text"],
.input-group input[type="number"],
.input-group select {
    flex: 1;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group .btn {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    margin-left: -1px;
}

.input-sm {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    width: 120px;
}

textarea {
    resize: vertical;
}

.checkbox-label {
    flex-direction: row !important;
    gap: 0.5rem !important;
    cursor: pointer;
    padding: 0.5rem 0;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary-500);
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 0.5rem;
}

/* ---- Filters ---- */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.filter-bar input,
.filter-bar select {
    width: auto;
    min-width: 160px;
}

.filter-bar button {
    flex-basis: 48px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-secondary);
}

[data-theme="dark"] .badge {
    background: rgba(255, 255, 255, 0.08);
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
}

.badge-secondary {
    background: rgba(148, 163, 184, 0.15);
    color: var(--gray-400);
}

/* ---- Alerts ---- */
.alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    margin: 0 1.5rem 1rem;
    font-size: 0.875rem;
    animation: slideDown 0.3s ease;
    position: relative;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.alert-info {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.alert-close {
    margin-left: auto;
    background: none;
    border: none;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    font-size: 1rem;
}

.alert-close:hover {
    opacity: 1;
}

@keyframes slideDown {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ---- Activity List ---- */
.activity-list {
    max-height: 400px;
    overflow-y: auto;
}

.activity-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border-color);
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-icon {
    color: var(--primary-400);
    font-size: 0.5rem;
    padding-top: 0.4rem;
}

.activity-content {
    display: flex;
    flex-direction: column;
}

.activity-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.activity-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ---- Info Grid ---- */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.info-item {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

@media (max-width: 640px) {
    .info-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
}

.info-item strong {
    color: var(--text-primary);
}

/* ---- Modal ---- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    z-index: 1;
    animation: modalIn 0.3s ease;
}

.modal-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

@keyframes modalIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ---- Utility Classes ---- */
.text-muted {
    color: var(--text-muted);
}

.text-center {
    text-align: center;
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.text-warning {
    color: var(--warning);
}

.font-bold {
    font-weight: 700;
}

@media (max-width: 640px) {

    .form-grid,
    form.form-grid,
    body .form-grid {
        grid-template-columns: 1fr !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100% !important;
    }

    .form-group,
    .form-grid>.form-group {
        width: 100% !important;
        grid-column: span 1 !important;
    }

    .stat-value {
        font-size: 1.1rem;
    }
}