/* static/css/admin_panel.css */
body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    background-color: #f0f2f5;
    direction: rtl;
    text-align: right;
}

.admin-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.admin-header {
    background-color: #333;
    color: white;
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.admin-header h1 {
    margin: 0;
    font-size: 1.8em;
}
.admin-user-info {
    font-size: 0.9em;
}
.admin-user-info a {
    color: #a0cfff;
    text-decoration: none;
}
.admin-user-info a:hover {
    text-decoration: underline;
}
#admin-logout-button:hover {
    background-color: #c82333 !important;
}

.admin-nav {
    background-color: #444;
    padding: 15px 0;
}

.admin-nav ul {
    list-style: none;
    padding: 0 25px;
    margin: 0;
}

.admin-nav li {
     margin-bottom: 5px;
}

.admin-nav a {
    color: #e0e0e0;
    text-decoration: none;
    padding: 10px 15px;
    display: block;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.admin-nav a:hover, .admin-nav a.active {
    background-color: #555;
    color: white;
    font-weight: bold;
}

.admin-content {
    flex-grow: 1;
    padding: 25px;
    background-color: #ffffff;
}
.admin-content h2 {
    margin-top: 0;
    color: #333;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.admin-footer {
    text-align: center;
    padding: 15px;
    background-color: #e9ecef;
    color: #555;
    font-size: 0.9em;
    border-top: 1px solid #dee2e6;
}

/* Table specific styles */
.users-table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: 0.95em; table-layout: fixed; }
.users-table th, .users-table td { border: 1px solid #ddd; padding: 10px 12px; text-align: right; vertical-align: middle; word-wrap: break-word; }
.users-table th { background-color: #e9ecef; font-weight: 600; color: #333;}
.users-table tr:nth-child(even) { background-color: #f8f9fa; }
.users-table tr:hover { background-color: #f1f1f1; }

.users-table .actions button {
    padding: 5px 10px;
    font-size: 0.9em;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 4px;
    transition: all 0.2s ease;
    background-color: #f8f9fa;
    color: #333;
    display: block;
    width: 100%;
    margin-bottom: 4px;
}
.users-table .actions button:hover {
    filter: brightness(0.95);
    border-color: #999;
}
.users-table .actions button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Action-specific button colors */
.users-table .actions .manage-credits-btn { background-color: #17a2b8; color: white; border-color: #138496; }
.users-table .actions .manage-credits-btn:hover { background-color: #138496; }
.users-table .actions .manage-api-btn { background-color: #fd7e14; color: white; border-color: #d3640d; }
.users-table .actions .manage-api-btn:hover { background-color: #d3640d; }
.users-table .actions .delete-btn { background-color: #dc3545; color: white; border-color: #c82333; }
.users-table .actions .delete-btn:hover { background-color: #c82333; }

/* Status Indicators */
.status-verified { color: #28a745; font-weight: bold; }
.status-not-verified { color: #fd7e14; }
.status-disabled { color: #dc3545; text-decoration: line-through; }
#loading-users { text-align: center; padding: 20px; font-style: italic; color: #555; font-size: 1.1em; }
.users-table td.credits-cell { font-weight: bold; text-align: center; }

/* Modal Styles */
.modal { display: none; position: fixed; z-index: 1050; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.6); }
.modal-content { background-color: #fefefe; margin: 8% auto; padding: 20px; border: 1px solid #888; width: 90%; max-width: 700px; border-radius: 5px; animation-name: animatetop; animation-duration: 0.4s; position: relative; }
@keyframes animatetop { from {top: -300px; opacity: 0} to {top: 0; opacity: 1} }
.modal-close { color: #aaa; position: absolute; left: 15px; top: 10px; font-size: 28px; font-weight: bold; cursor: pointer; }

#api-clients-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; }
#api-clients-table th, #api-clients-table td { border: 1px solid #ddd; padding: 8px; text-align: right; vertical-align: middle;}
#api-clients-table th { background-color: #f2f2f2; }
.api-key-value { user-select: all; font-weight: bold; color: #0056b3; word-break: break-all; cursor: pointer; }
.api-key-value:hover { text-decoration: underline; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 600; }
.form-group input, .form-group textarea { width: 100%; padding: 8px; box-sizing: border-box; border: 1px solid #ccc; border-radius: 3px;}
.form-group textarea { min-height: 100px; font-family: monospace; resize: vertical; }

#editApiClientSettingsModal .modal-content { max-width: 800px; }
.settings-group { margin-bottom: 20px; }
.settings-group h5 { margin-top: 0; border-bottom: 1px solid #eee; padding-bottom: 5px; margin-bottom: 10px;}
.settings-group code { background-color: #e9ecef; padding: 2px 4px; border-radius: 3px; font-family: monospace;}
#embedCodePreview { background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; border-radius: 4px; white-space: pre-wrap; word-break: break-all; user-select: all; font-size: 0.9em; max-height: 200px; overflow-y: auto;}

/* --- START OF FIX --- */

/* Use main app's dark theme for admin panel consistency */
body {
    background-color: var(--dark-bg, #111827);
    color: var(--light-text, #f3f4f6);
}
.admin-content {
    background-color: transparent;
    padding: 2.5rem 1.5rem;
}
.admin-content h2 {
    color: var(--light-text, #f3f4f6);
    border-bottom-color: var(--card-border, #374151);
}
.admin-footer {
    background-color: var(--dark-bg-secondary, #1f2937);
    color: var(--medium-text, #9ca3af);
    border-top-color: var(--card-border, #374151);
}

/* Inherit header styles from main app */
.user-header, .tab-navigation {
    background-color: var(--dark-bg-secondary, #1f2937);
    border-bottom: 1px solid var(--card-border, #374151);
}

/* Admin panel header layout - balanced center alignment */
.user-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 12px 25px;
}

#admin-logout-button {
    grid-column: 1;
    justify-self: start;
    background: var(--dark-bg);
    color: var(--medium-text);
    padding: 8px 16px;
    border: 1px solid var(--card-border);
    gap: 8px;
    border-radius: 50px;
}
#admin-logout-button:hover {
    background-color: var(--card-border);
    color: white;
}

.user-header h1 {
    grid-column: 2;
    justify-self: center;
    color: white;
    font-size: 1.8em;
    font-weight: 900;
    margin: 0;
    text-align: center;
    border-bottom: none;
}

.user-header .user-details-group {
    grid-column: 3;
    justify-self: end;
}

.user-header .user-details-group p {
    color: white;
    margin: 0;
    font-size: 0.9em;
    font-weight: 600;
}
.tab-navigation.admin-nav {
    justify-content: center;
    padding: 0 20px;
    margin-top: -8px;
}
.tab-navigation.admin-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
}
.tab-navigation.admin-nav a {
    display: block;
    padding: 0.5rem 1.5rem;
    text-decoration: none;
    color: var(--medium-text);
    font-weight: 600;
    font-size: 1rem;
    transition: color 0.2s ease, border-color 0.2s ease;
    border: none;
    border-bottom: 3px solid transparent;
}
.tab-navigation.admin-nav a:hover { color: white; }
.tab-navigation.admin-nav a.active {
    color: white;
    font-weight: 700;
    border-bottom: 3px solid var(--primary-accent);
}

/* Table Redesign */
.users-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    color: #111827; /* Dark text for readability on light background */
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
}
.users-table th {
    background-color: #f9fafb;
    padding: 12px 15px;
    font-weight: 700;
    text-align: right;
    border-bottom: 2px solid #e5e7eb;
    color: #374151;
}
.users-table td {
    padding: 15px;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
}
.users-table tr:last-child td {
    border-bottom: none;
}
.users-table tr:hover {
    background-color: #f3f4f6;
}

/* This rule ensures the numeric and text columns are visible */
.users-table td {
    color: #111827;
}

.users-table td.credits-cell {
    font-weight: 700;
    color: var(--primary-accent, #a855f7);
    text-align: center;
}

/* Action Buttons Redesign */
.users-table .actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.users-table .actions button {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 700;
    border-radius: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.users-table .actions button:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.users-table .actions .delete-btn {
    background: #fee2e2;
    color: #b91c1c;
}
.users-table .actions .delete-btn:hover {
    background: #ef4444;
    color: white;
}
.users-table .actions .manage-api-btn {
    background: linear-gradient(90deg, #6366f1, #8b5cf6); /* Indigo/Violet */
}

/* Fix modal styles to appear correctly on dark background */
.modal-content {
    background-color: var(--dark-bg-secondary);
    color: var(--light-text);
    border: 1px solid var(--card-border);
}
.modal-content h3, .modal-content h4, .modal-content h5 {
    color: var(--light-text);
}
#api-clients-table {
    color: #111827;
}
/* --- END OF FIX --- */

/* ===== MOBILE RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    /* Header adjustments - Two rows layout */
    .user-header {
        padding: 10px 15px;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px;
    }

    /* First row: Logout button and user email */
    .user-header > *:not(h1) {
        order: 1;
    }

    #admin-logout-button {
        position: absolute;
        top: 10px;
        left: 15px;
        padding: 5px 10px;
        font-size: 0.7rem;
        display: inline-flex !important;
        z-index: 10;
    }

    .user-header .user-details-group {
        position: absolute;
        top: 10px;
        right: 15px;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 3px;
        z-index: 10;
    }

    .user-header .user-details-group p {
        margin: 0;
        font-size: 0.7rem;
    }

    /* Second row: Title centered below */
    .user-header h1 {
        order: 2;
        font-size: 1.5rem;
        text-align: center;
        margin: 35px 0 5px 0;
        white-space: nowrap;
    }

    /* Navigation - Two rows grid layout */
    .tab-navigation.admin-nav {
        padding: 10px;
        overflow-x: visible;
    }

    .tab-navigation.admin-nav ul {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 0;
        margin: 0;
    }

    .tab-navigation.admin-nav li {
        margin: 0;
        width: 100%;
    }

    .tab-navigation.admin-nav a {
        display: block;
        white-space: normal;
        word-wrap: break-word;
        padding: 0.6rem 0.5rem;
        font-size: 0.75rem;
        text-align: center;
        border: 1px solid var(--card-border);
        border-radius: 8px;
        background-color: rgba(255, 255, 255, 0.05);
    }

    .tab-navigation.admin-nav a:hover,
    .tab-navigation.admin-nav a.active {
        background-color: rgba(168, 85, 247, 0.1);
        border-color: var(--primary-accent);
    }

    /* Content padding */
    .admin-content {
        padding: 1.5rem 1rem;
    }

    .admin-content h2 {
        font-size: 1.3em;
    }

    /* Hide table, show cards instead */
    .users-table {
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .users-table thead {
        display: none;
    }

    .users-table tbody {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .users-table tr {
        display: block;
        background-color: #ffffff;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        padding: 1rem;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .users-table tr:hover {
        background-color: #ffffff;
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }

    .users-table td {
        display: block;
        border: none;
        padding: 0.5rem 0;
        text-align: right;
    }

    .users-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: #6b7280;
        display: block;
        margin-bottom: 0.25rem;
        font-size: 0.85rem;
    }

    .users-table td:first-child {
        font-size: 1.05em;
        font-weight: 700;
        color: var(--primary-accent, #a855f7);
        border-bottom: 1px solid #e5e7eb;
        padding-bottom: 0.75rem;
        margin-bottom: 0.5rem;
    }

    .users-table td:first-child::before {
        content: '';
        display: none;
    }

    .users-table td:last-child {
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid #e5e7eb;
    }

    .users-table .actions {
        gap: 8px;
    }

    .users-table .actions button {
        font-size: 0.9rem;
        padding: 10px 14px;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        margin: 5% auto;
        padding: 15px;
        max-height: 85vh;
        overflow-y: auto;
    }

    .modal-content h3 {
        font-size: 1.1em;
    }

    .form-grid-3col {
        grid-template-columns: 1fr;
    }

    .rule-item {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .remove-rule-btn {
        width: 100%;
        height: auto;
        padding: 8px;
        border-radius: 8px;
    }

    /* API clients table in modal */
    #api-clients-table {
        font-size: 0.85em;
    }

    #api-clients-table th,
    #api-clients-table td {
        padding: 6px;
        font-size: 0.9em;
    }

    .api-key-value {
        font-size: 0.75em;
        word-break: break-all;
    }

    /* Embed code preview */
    #embedCodePreview,
    #embedCodePreviewWP,
    #embedCodePreviewShopify {
        font-size: 0.75em;
        padding: 8px;
        max-height: 150px;
    }

    .embed-tabs {
        overflow-x: auto;
    }

    .tab-link {
        font-size: 0.9em;
        padding: 8px 15px;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .admin-header h1 {
        font-size: 1.1em;
    }

    .tab-navigation.admin-nav a {
        font-size: 0.85rem;
        padding: 0.4rem 0.8rem;
    }

    .admin-content {
        padding: 1rem 0.75rem;
    }

    .users-table tr {
        padding: 0.75rem;
    }

    .users-table .actions button {
        font-size: 0.85rem;
        padding: 8px 12px;
    }

    .modal-content {
        width: 98%;
        padding: 12px;
    }
}

/* ===== PENDING USERS PAGE MOBILE STYLES ===== */
.pending-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.pending-user-card {
    background-color: #fff;
    color: #111827;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.pending-user-card p {
    margin: 0.5rem 0;
    font-size: 0.95em;
    line-height: 1.5;
}

.pending-user-card p strong {
    color: #374151;
    font-weight: 700;
}

.pending-user-card button {
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 700;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pending-user-card .approve-btn {
    background: linear-gradient(90deg, #10b981, #059669);
    color: white;
}

.pending-user-card .approve-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.pending-user-card .reject-btn {
    background: #fee2e2;
    color: #b91c1c;
}

.pending-user-card .reject-btn:hover {
    background: #ef4444;
    color: white;
}

.pending-user-card .copy-link-btn {
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    color: white;
}

@media (max-width: 768px) {
    .pending-user-card {
        padding: 0.75rem;
    }

    .pending-user-card p {
        font-size: 0.9em;
    }

    .pending-user-card button {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}