:root {
    --bg-grad-1: #EDEBFF;
    --bg-grad-2: #EAF4FF;
    --bg-grad-3: #FFF1D6;
    --primary: #5B47F1;
    --accent: #4DD0E1;
    --highlight: #FFD22E;
    --text: #0E0F12;
    --muted: #70737C;
    --border: #E5E7EB;
    --error: #E84A4A;
    --success: #16A34A;
    --card: #FFFFFF;
    --shadow-soft: 0 16px 40px rgba(24, 33, 68, 0.08);
    --shadow-card: 0 8px 22px rgba(32, 41, 78, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Poppins', 'Segoe UI', sans-serif;
    color: var(--text);
    min-height: 100vh;
    max-width: 100%;
    overflow-x: hidden;
    background:
        radial-gradient(120% 120% at 0% 0%, rgba(91, 71, 241, 0.12) 0%, rgba(91, 71, 241, 0) 60%),
        radial-gradient(120% 120% at 100% 10%, rgba(255, 200, 124, 0.18) 0%, rgba(255, 200, 124, 0) 65%),
        linear-gradient(135deg, var(--bg-grad-1), var(--bg-grad-2), var(--bg-grad-3));
    background-attachment: fixed;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200"%3E%3Cdefs%3E%3CradialGradient id="g" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(100 100) scale(100)"%3E%3Cstop offset="0" stop-color="%23b3b5c0" stop-opacity="0.18"/%3E%3Cstop offset="1" stop-color="%23b3b5c0" stop-opacity="0"/%3E%3C/radialGradient%3E%3C/defs%3E%3Crect width="200" height="200" fill="url(%23g)"/%3E%3C/svg%3E');
    opacity: 0.25;
    mix-blend-mode: soft-light;
}

main {
    display: flex;
    justify-content: center;
    padding: clamp(32px, 6vw, 72px) 16px 100px;
}

.form-shell,
.table-card {
    background: var(--card);
    border-radius: 24px;
    padding: clamp(28px, 4vw, 48px);
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(214, 223, 234, 0.9);
    max-width: 1200px;
    width: 100%;
}

@media (max-width: 768px) {
    .form-shell,
    .table-card {
        border-radius: 20px;
        padding: 28px 22px;
    }
}

.header-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: clamp(24px, 4vw, 36px);
}

.header-brand h1 {
    margin: 0;
    font-weight: 600;
    letter-spacing: 0.3px;
    font-size: clamp(26px, 4vw, 34px);
}

.header-brand span {
    display: inline-block;
    color: var(--muted);
    font-size: 13px;
    letter-spacing: 2px;
    text-transform: uppercase;
}


.form-grid,
#editFields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px 28px;
}

.form-row-full {
    grid-column: 1 / -1;
}

.field-flow {
    grid-column: 1 / -1;
}

label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
    letter-spacing: 0.25px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="url"],
input[type="date"],
select,
textarea,
.select2-container--default .select2-selection--single {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 15px;
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

input::placeholder,
textarea::placeholder {
    color: rgba(112, 115, 124, 0.7);
}

.select2-container--default .select2-selection--single {
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 16px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text);
    line-height: 1;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 100%;
}

input:focus,
select:focus,
textarea:focus,
.select2-container--default .select2-selection--single:focus {
    outline: none;
    border-color: rgba(91, 71, 241, 0.65);
    box-shadow: 0 0 0 4px rgba(91, 71, 241, 0.12);
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.radio-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.radio-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(91, 71, 241, 0.08);
    border: 1px solid rgba(91, 71, 241, 0.22);
    border-radius: 999px;
    padding: 10px 18px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
    color: var(--text);
}

.radio-chip input {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(91, 71, 241, 0.55);
    display: grid;
    place-items: center;
    background: #fff;
}

.radio-chip input::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.2s ease;
}

.radio-chip input:checked::after {
    background: var(--primary);
}

.radio-chip:hover {
    border-color: var(--primary);
}

button {
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #29b6f6);
    border-radius: 14px;
    color: #ffffff;
    font-weight: 600;
    padding: 16px 26px;
    font-size: 16px;
    letter-spacing: 0.4px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    width: 100%;
    box-shadow: 0 10px 24px rgba(91, 71, 241, 0.25);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 14px 32px rgba(91, 71, 241, 0.3);
    background: linear-gradient(135deg, #4a39e0, #1aa3e6);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: rgba(91, 71, 241, 0.08);
    border: 1px solid rgba(91, 71, 241, 0.25);
    color: var(--primary);
    border-radius: 12px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.btn-secondary:hover {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 10px 24px rgba(91, 71, 241, 0.22);
}

.error-message {
    color: var(--error);
    font-size: 12px;
    margin-top: 6px;
    display: none;
}

input.invalid,
select.invalid,
textarea.invalid,
.select2-container--default .select2-selection--single.invalid {
    border-color: rgba(232, 74, 74, 0.85);
    box-shadow: 0 0 0 2px rgba(232, 74, 74, 0.15);
}

.success-state {
    text-align: center;
    padding: 70px 40px;
}

.success-state h2 {
    font-size: clamp(26px, 4vw, 34px);
    margin-bottom: 18px;
    color: var(--primary);
}

.success-state p {
    color: var(--muted);
    margin-bottom: 24px;
}

.success-state .qr-wrapper {
    margin-top: 26px;
}

.alert-banner {
    margin-top: 12px;
    border-radius: 12px;
    padding: 12px 18px;
    background: rgba(232, 74, 74, 0.08);
    border: 1px solid rgba(232, 74, 74, 0.4);
    color: var(--error);
    font-size: 14px;
}

.info-banner {
    margin-top: 12px;
    border-radius: 12px;
    padding: 12px 18px;
    background: rgba(91, 71, 241, 0.08);
    border: 1px solid rgba(91, 71, 241, 0.3);
    color: var(--primary);
    font-size: 14px;
}

.dashboard-grid {
    display: grid;
    gap: 26px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    max-width: 100%;
}

.summary-card {
    background: var(--card);
    border-radius: 20px;
    padding: 22px;
    border: 1px solid rgba(91, 71, 241, 0.18);
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

.summary-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(91, 71, 241, 0.12), transparent 65%);
}

.summary-card h3 {
    margin: 0;
    font-size: 14px;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--muted);
}

.summary-card strong {
    font-size: 32px;
    font-weight: 700;
    display: block;
    margin-top: 14px;
    color: var(--primary);
}

.summary-card span {
    font-size: 13px;
    color: rgba(15, 30, 50, 0.68);
    position: relative;
    z-index: 1;
}

.table-responsive {
    overflow-x: auto;
    border-radius: 16px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text);
    font-size: 14px;
}

thead {
    background: rgba(91, 71, 241, 0.05);
}

thead th {
    padding: 14px 16px;
    text-align: left;
    letter-spacing: 0.3px;
    color: var(--muted);
    font-weight: 500;
}

tbody td {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 0.3px;
}

.badge.success {
    background: rgba(58, 210, 159, 0.2);
    color: rgba(22, 163, 74, 0.9);
}

.badge.pending {
    background: rgba(255, 210, 46, 0.2);
    color: #8a6b00;
}

.badge.invoice {
    background: rgba(91, 71, 241, 0.12);
    color: var(--primary);
}

.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background: rgba(14, 15, 18, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.modal-backdrop-custom.show {
    display: flex;
}

.modal-card {
    background: var(--card);
    border-radius: 20px;
    width: min(820px, 92vw);
    max-height: 90vh;
    overflow-y: auto;
    padding: 32px 28px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.16);
    border: 1px solid var(--border);
}

/* Force two-column fields inside modals on wider screens */
.modal-card .form-grid,
.modal-card #editFields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 640px) {
    .modal-card .form-grid,
    .modal-card #editFields {
        grid-template-columns: 1fr;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.modal-header h4 {
    margin: 0;
}

.modal-close {
    background: none;
    color: var(--muted);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

input[type="file"] {
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.table-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--primary);
    background: rgba(91, 71, 241, 0.08);
    border: 1px solid rgba(91, 71, 241, 0.24);
}

.table-action-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    background-color: transparent !important;
    box-shadow: none;
    color: inherit;
    border-radius: 8px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.table-action-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.table-action-icon .material-icons-outlined {
    font-size: 16px;
    line-height: 1;
    color: currentColor;
}

.table-action-icon:hover,
.table-action-icon:focus-visible {
    color: #1565c0;
}

.table-action-blue,
.table-action-blue .material-icons-outlined {
    color: #1e88e5 !important;
}

.table-action-green,
.table-action-green .material-icons-outlined {
    color: #2e7d32 !important;
}

.table-action-red,
.table-action-red .material-icons-outlined {
    color: #e53935 !important;
}

.table-action.danger {
    color: var(--error);
    background: rgba(232, 74, 74, 0.08);
    border-color: rgba(232, 74, 74, 0.24);
}

input[type="date"] {
    color-scheme: light;
}

small.hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
}

#tableSearch,
#statusFilter {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 16px;
    color: var(--text);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

#statusFilter {
    min-width: 180px;
}

.select2-dropdown {
    border: 1px solid var(--border) !important;
    box-shadow: var(--shadow-soft) !important;
    border-radius: 12px !important;
}

.select2-results__option {
    padding: 10px 14px !important;
    font-size: 14px;
}

.select2-results__option--highlighted.select2-results__option--selectable {
    background: rgba(91, 71, 241, 0.12) !important;
    color: var(--primary) !important;
}

.info-banner#promoFeedback {
    display: none;
}

@media (max-width: 600px) {
    main {
        padding: 48px 24px 120px;
    }

    .header-brand {
        flex-direction: column;
        align-items: flex-start;
    }

    .logo-mark {
        width: 48px;
        height: 48px;
        padding: 4px;
    }

    .btn-primary {
        font-size: 15px;
    }

    .table-card,
    .form-shell {
        padding: 32px 28px;
    }

    .dashboard-grid {
        gap: 32px;
    }

    body {
        padding: 20px;
    }
}

/* Avoid any horizontal overflow in dashboard sections */
.form-shell,
.dashboard-grid,
.summary-cards {
    overflow-x: visible;
    overflow-y: visible;
}
