/**
 * Afritivity Loyalty Admin Styles
 * 
 * Dark theme dashboard for vendor loyalty management.
 * 
 * @version 2.9.0
 */

/* =========================================================================
   Base / Reset
   ========================================================================= */

.af-loyalty-wrap {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: #e0e0e0;
    line-height: 1.5;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.af-loyalty-wrap * {
    box-sizing: border-box;
}

/* =========================================================================
   Dashboard Grid (Two Columns)
   ========================================================================= */

.af-dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

@media (max-width: 900px) {
    .af-dashboard-grid {
        grid-template-columns: 1fr;
    }
}

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

.af-card {
    background: linear-gradient(145deg, rgba(26, 26, 46, 0.95), rgba(15, 15, 35, 0.95));
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* v2.32.0 — collapsible cards (Locations tab). The heading is the toggle,
   chevron matches the Payment Analytics bar: '›' pointing right when
   collapsed, rotated down when open. Body hiding is class-based
   (:not(.af-col-toggle) — Selectors L3, works everywhere). */
.af-collapsible > .af-col-toggle {
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.af-collapsible > .af-col-toggle::after {
    content: '›';
    font-size: 24px;
    line-height: 1;
    color: #8b949e;
    transform: rotate(90deg);
    transition: transform 0.15s ease;
    flex: 0 0 auto;
}
.af-collapsible.af-collapsed > .af-col-toggle::after { transform: rotate(0deg); }
.af-collapsible.af-collapsed > .af-col-toggle { margin-bottom: 0; }
.af-collapsible.af-collapsed > *:not(.af-col-toggle) { display: none !important; }
.af-collapsible > .af-col-toggle:focus-visible {
    outline: 2px solid #22c55e;
    outline-offset: 4px;
    border-radius: 6px;
}

.af-card-header {
    margin-bottom: 16px;
}

.af-card-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}

.af-card h2 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}

.af-card h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

/* =========================================================================
   Toggle Switch - FIXED: Now functional
   ========================================================================= */

.af-toggle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
}

.af-toggle {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
}

.af-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.af-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.15);
    transition: 0.3s;
    border-radius: 28px;
}

.af-toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: #fff;
    transition: 0.3s;
    border-radius: 50%;
}

.af-toggle input:checked + .af-toggle-slider {
    background-color: #22c55e;
}

.af-toggle input:checked + .af-toggle-slider:before {
    transform: translateX(24px);
}

.af-toggle input:disabled + .af-toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

.af-toggle-label {
    font-size: 0.95rem;
    color: #ccc;
}

/* =========================================================================
   Sign-up URL
   ========================================================================= */

.af-signup-url {
    margin-bottom: 16px;
    padding: 12px 16px;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 10px;
}

.af-signup-url-label {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 4px;
}

.af-signup-url a {
    color: #22c55e;
    text-decoration: none;
    font-size: 0.9rem;
    word-break: break-all;
}

.af-signup-url a:hover {
    text-decoration: underline;
}

/* =========================================================================
   Status Boxes
   ========================================================================= */

.af-status-box {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 16px;
}

.af-status-success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.25);
    color: #22c55e;
}

.af-status-warning {
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.25);
    color: #ffc107;
}

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

.af-nav-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
}

.af-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #ccc;
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.af-nav-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.2);
}

.af-nav-btn.af-nav-active {
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.4);
    color: #22c55e;
}

/* =========================================================================
   Overview Stats
   ========================================================================= */

.af-overview-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.af-overview-stat {
    text-align: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
}

.af-overview-stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: #22c55e;
}

.af-overview-stat-label {
    display: block;
    font-size: 0.8rem;
    color: #888;
    margin-top: 4px;
}

/* =========================================================================
   Summary Grid
   ========================================================================= */

.af-summary-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #888;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.af-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.af-summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
}

.af-summary-item-label {
    font-size: 0.85rem;
    color: #888;
}

.af-summary-item-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
}

.af-text-gold {
    color: #fbbf24 !important;
}

.af-text-platinum {
    color: #a78bfa !important;
}

/* =========================================================================
   Stat Grid (Analytics)
   ========================================================================= */

.af-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.af-stat-card {
    background: linear-gradient(145deg, rgba(26, 26, 46, 0.95), rgba(15, 15, 35, 0.95));
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}

.af-stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: #22c55e;
}

.af-stat-label {
    display: block;
    font-size: 0.85rem;
    color: #888;
    margin-top: 4px;
}

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

.af-table-wrap {
    overflow-x: auto;
    margin: 0 -8px;
    padding: 0 8px;
}

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

.af-table th,
.af-table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.af-table th {
    font-weight: 600;
    color: #888;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.af-table td {
    color: #ccc;
}

.af-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.af-table code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.85em;
}

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

.af-form-table {
    width: 100%;
    border-collapse: collapse;
}

.af-form-table th,
.af-form-table td {
    padding: 12px 0;
    vertical-align: top;
}

.af-form-table th {
    width: 180px;
    text-align: left;
    font-weight: 500;
    color: #aaa;
    padding-right: 16px;
}

.af-form-table small {
    display: block;
    color: #666;
    margin-top: 4px;
    font-size: 0.8rem;
}

.af-input {
    width: 100%;
    max-width: 400px;
    padding: 10px 14px;
    font-size: 0.95rem;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    outline: none;
    transition: border-color 0.2s;
}

.af-input:focus {
    border-color: #22c55e;
}

.af-input::placeholder {
    color: #555;
}

textarea.af-input {
    min-height: 100px;
    resize: vertical;
}

.af-form-actions {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

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

.af-dash-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    background: #22c55e;
    color: #000;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

.af-dash-btn:hover {
    background: #16a34a;
    color: #000;
}

.af-dash-btn:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
}

.af-btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.af-btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #ccc;
}

.af-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.af-btn-danger {
    background: rgba(220, 38, 38, 0.8);
    color: #fff;
}

.af-btn-danger:hover {
    background: rgba(220, 38, 38, 1);
}

.af-btn-warning {
    background: rgba(245, 158, 11, 0.8);
    color: #fff;
}

.af-btn-warning:hover {
    background: rgba(245, 158, 11, 1);
}

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

.af-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: #888;
}

.af-badge-green {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.af-badge-red {
    background: rgba(220, 38, 38, 0.15);
    color: #f87171;
}

.af-badge-grey {
    background: rgba(255, 255, 255, 0.05);
    color: #666;
}

/* =========================================================================
   Notices
   ========================================================================= */

.af-notice {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.af-notice-success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.25);
    color: #22c55e;
}

.af-notice-warning {
    background: rgba(255, 193, 7, 0.12);
    border: 1px solid rgba(255, 193, 7, 0.25);
    color: #ffc107;
}

.af-notice-error {
    background: rgba(220, 38, 38, 0.12);
    border: 1px solid rgba(220, 38, 38, 0.25);
    color: #f87171;
}

.af-notice-info {
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #60a5fa;
}

.af-notice a {
    color: inherit;
    text-decoration: underline;
}

/* =========================================================================
   Status Boxes
   ========================================================================= */

.af-status-box {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.9rem;
}

.af-status-success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.25);
    color: #22c55e;
}

.af-status-warning {
    background: rgba(255, 193, 7, 0.12);
    border: 1px solid rgba(255, 193, 7, 0.25);
    color: #ffc107;
}

.af-status-error {
    background: rgba(220, 38, 38, 0.12);
    border: 1px solid rgba(220, 38, 38, 0.25);
    color: #f87171;
}

.af-status-info {
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #60a5fa;
}

/* =========================================================================
   Setup Steps (Telegram Wizard)
   ========================================================================= */

.af-telegram-steps {
    margin-top: 1rem;
}

.af-setup-step {
    display: flex;
    gap: 16px;
    margin-bottom: 1.5rem;
    align-items: flex-start;
}

.af-step-number {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.af-step-content {
    flex: 1;
    padding-top: 4px;
}

.af-step-content h4 {
    margin: 0 0 8px 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

.af-step-content p {
    margin: 0 0 8px 0;
    color: #a0a0a0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.af-step-content p:last-child {
    margin-bottom: 0;
}

.af-step-content code {
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #22c55e;
}

.af-step-content a {
    color: #60a5fa;
    text-decoration: none;
}

.af-step-content a:hover {
    text-decoration: underline;
}

.af-step-content .af-input {
    margin-top: 8px;
}

.af-btn-success {
    background: linear-gradient(135deg, #22c55e, #16a34a) !important;
}

.af-btn-success:hover {
    background: linear-gradient(135deg, #16a34a, #15803d) !important;
}

/* =========================================================================
   Accordion (Collapsible Settings)
   ========================================================================= */

.af-accordion {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.af-accordion-item {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.af-accordion-item:last-child {
    border-bottom: none;
}

.af-accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 8px;
    cursor: pointer;
    transition: background 0.2s ease;
    user-select: none;
}

.af-accordion-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.af-accordion-header span:first-child {
    font-weight: 500;
    font-size: 1rem;
    color: #e0e0e0;
}

.af-accordion-icon {
    font-size: 1.25rem;
    color: #888;
    transition: transform 0.3s ease;
    display: inline-block;
}

.af-accordion-item.active .af-accordion-icon {
    transform: rotate(90deg);
}

.af-accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 8px;
}

/* v2.33.1 — the open-state max-height here is only a NO-JS FALLBACK.
   afToggleAccordion() now measures the real content height and, once the
   opening transition finishes, lifts the cap entirely (max-height:none) so
   tall sections (e.g. Ordivity's Online Ordering form, which outgrew the old
   2000px cap in v0.37.0 and clipped its own Save button) can never be
   clipped, no matter how much siblings add in future. */
.af-accordion-item.active .af-accordion-content {
    max-height: 6000px;
    padding: 0 8px 24px 8px;
}

/* Helper Note */
.af-helper-note {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 1.5rem;
    color: #93c5fd;
    font-size: 0.9rem;
}

.af-helper-note strong {
    color: #60a5fa;
}

/* =========================================================================
   Promote Page
   ========================================================================= */

.af-promote-info {
    margin-bottom: 20px;
    padding: 16px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 10px;
}

.af-promote-info-main {
    font-size: 0.95rem;
    color: #ccc;
}

.af-promote-count {
    font-weight: 700;
    color: #60a5fa;
}

.af-promote-info-sub {
    margin-top: 8px;
    font-size: 0.85rem;
    color: #888;
}

/* =========================================================================
   Guide Page
   ========================================================================= */

.af-guide-content h3 {
    color: #22c55e;
    margin: 24px 0 12px 0;
    font-size: 1rem;
}

.af-guide-content h3:first-child {
    margin-top: 0;
}

.af-guide-content p {
    color: #aaa;
    margin-bottom: 12px;
}

.af-guide-content ol,
.af-guide-content ul {
    color: #aaa;
    padding-left: 20px;
    margin-bottom: 12px;
}

.af-guide-content li {
    margin-bottom: 6px;
}

.af-guide-content a {
    color: #22c55e;
}

/* =========================================================================
   Universal QR Block (Status Card)
   ========================================================================= */

.af-universal-qr {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    padding: 16px;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 12px;
    margin-bottom: 16px;
}

.af-qr-preview {
    flex-shrink: 0;
}

.af-qr-preview img {
    display: block;
    border-radius: 8px;
    background: #fff;
    padding: 6px;
}

.af-qr-details {
    flex: 1;
    min-width: 0;
}

.af-signup-link {
    display: block;
    color: #22c55e;
    text-decoration: none;
    font-size: 0.9rem;
    word-break: break-all;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

.af-signup-link:hover {
    text-decoration: underline;
    color: #4ade80;
}

.af-qr-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 600px) {
    .af-universal-qr {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .af-qr-details {
        width: 100%;
    }
    
    .af-qr-actions {
        justify-content: center;
    }
}

/* =========================================================================
   Searchable Select Dropdown
   ========================================================================= */

.af-searchable-select {
    position: relative;
}

.af-dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 250px;
    overflow-y: auto;
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    margin-top: 4px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.af-dropdown-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #ccc;
    transition: background 0.15s;
}

.af-dropdown-item:hover,
.af-dropdown-item.af-dropdown-highlighted {
    background: rgba(34, 197, 94, 0.15);
    color: #fff;
}

.af-dropdown-item.af-dropdown-selected {
    background: rgba(34, 197, 94, 0.25);
    color: #22c55e;
}

.af-dropdown-item.af-dropdown-hidden {
    display: none;
}

.af-dropdown-empty {
    padding: 12px 14px;
    color: #666;
    font-size: 0.85rem;
    text-align: center;
}

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

@media (max-width: 768px) {
    .af-loyalty-wrap {
        padding: 16px;
    }
    
    .af-card {
        padding: 20px;
    }
    
    .af-form-table th {
        display: block;
        width: 100%;
        padding-bottom: 4px;
    }
    
    .af-form-table td {
        display: block;
        padding-top: 0;
    }
    
    .af-input {
        max-width: 100%;
    }
    
    .af-summary-grid {
        grid-template-columns: 1fr;
    }
    
    .af-nav-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* =========================================================================
   Customer Search & Pagination
   ========================================================================= */

.af-customers-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
}

.af-customers-header h2 {
    margin: 0 !important;
}

.af-customer-search-form {
    flex: 1;
    max-width: 350px;
    min-width: 200px;
}

.af-search-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

.af-search-input {
    flex: 1;
    min-width: 150px;
}

.af-pagination-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    color: #888;
}

.af-pagination-info strong {
    color: #fff;
}

.af-search-results {
    color: #60a5fa;
}

.af-showing-info {
    font-size: 0.85rem;
    color: #666;
}

.af-pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    align-items: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.af-pagination-ellipsis {
    color: #666;
    padding: 0 4px;
    font-size: 1rem;
}

/* Active page number */
.af-pagination .af-dash-btn:not(.af-btn-secondary) {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #fff;
    cursor: default;
}

/* First/Last page buttons */
.af-pagination .af-dash-btn[title="First page"],
.af-pagination .af-dash-btn[title="Last page"] {
    font-weight: 700;
    padding-left: 10px;
    padding-right: 10px;
}

@media (max-width: 600px) {
    .af-customers-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .af-customer-search-form {
        max-width: 100%;
    }
    
    .af-pagination-info {
        flex-direction: column;
        text-align: center;
    }
    
    .af-pagination {
        gap: 4px;
    }
    
    .af-pagination .af-dash-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    /* Hide ellipsis on mobile */
    .af-pagination-ellipsis {
        display: none;
    }
}
