/**
 * Billing Library — CSS
 *
 * Generic billing UI styles: modals, billing display, API keys table,
 * admin customers table, buttons. Uses CSS custom properties so consumers
 * control colors by setting --bg-color, --text-color, --line-color, --navbar-bg.
 *
 * Includes dark/light mode support via body.light-mode.
 */

/* ── Modal Framework ─────────────────────────────────────────── */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--navbar-bg, rgba(0, 0, 32, 0.95));
    border: 1px solid var(--line-color, #404040);
    border-radius: 8px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    position: relative;
}

.modal-refresh {
    position: absolute;
    top: 12px;
    right: 45px;
    z-index: 1;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-color, #7FFF00);
    font-size: 24px;
    cursor: pointer;
    opacity: 0.7;
}

.modal-close:hover {
    opacity: 1;
}

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

.modal-header h2 {
    margin: 0;
    flex: 1;
    text-align: center;
}

.modal-content h2 {
    margin-bottom: 16px;
    font-size: 1.3em;
}

.btn-icon {
    background: transparent;
    border: 1px solid rgba(114, 220, 56, 0.3);
    color: var(--green-accent, #72dc38);
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(114, 220, 56, 0.1);
    border-color: var(--green-accent, #72dc38);
}

.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.modal-switch-btn {
    background: transparent;
    border: 1px solid rgba(114, 220, 56, 0.3);
    color: var(--text-color, #7FFF00);
    border-radius: 4px;
    padding: 4px 12px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85em;
    transition: all 0.2s;
}

.modal-switch-btn:hover {
    background: rgba(114, 220, 56, 0.1);
    border-color: var(--text-color, #7FFF00);
}

/* ── Buttons ─────────────────────────────────────────────────── */

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9em;
    transition: opacity 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--text-color, #7FFF00);
    color: var(--bg-color, #000040);
}

.btn-primary:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--text-color, #7FFF00);
    color: var(--text-color, #7FFF00);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(127, 255, 0, 0.1);
}

.btn-small {
    padding: 4px 10px;
    border-radius: 4px;
    background: transparent;
    border: 1px solid var(--line-color, #404040);
    color: var(--text-color, #7FFF00);
    font-family: inherit;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-small:hover {
    border-color: var(--text-color, #7FFF00);
}

.btn-danger {
    border-color: #ff6666;
    color: #ff6666;
}

.btn-danger:hover {
    background: rgba(255, 102, 102, 0.1);
}

/* ── Billing Modal ───────────────────────────────────────────── */

.billing-modal {
    max-width: 450px;
}

.billing-info {
    margin-bottom: 16px;
    line-height: 1.5;
}

.billing-status {
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    margin-bottom: 16px;
}

.billing-status p {
    margin-bottom: 8px;
}

.billing-status p:last-child {
    margin-bottom: 0;
}

.billing-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Credits Balance Display */
.credits-balance {
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    margin-bottom: 16px;
}

.balance-amount,
.balance-words {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.balance-amount {
    border-bottom: 1px solid rgba(127, 255, 0, 0.2);
}

.balance-label {
    color: rgba(127, 255, 0, 0.7);
}

.balance-value {
    font-size: 1.2em;
    font-weight: bold;
}

/* Auto-reload Section */
.auto-reload-section {
    margin-bottom: 16px;
}

.auto-reload-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
}

.auto-reload-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.auto-reload-status {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.85em;
}

.auto-reload-status.error {
    background: rgba(220, 53, 69, 0.2);
    color: #dc3545;
    border: 1px solid rgba(220, 53, 69, 0.3);
}

.auto-reload-status.warning {
    background: rgba(255, 193, 7, 0.2);
    color: #ffc107;
    border: 1px solid rgba(255, 193, 7, 0.3);
}

.auto-reload-status.pending {
    background: rgba(23, 162, 184, 0.2);
    color: #17a2b8;
    border: 1px solid rgba(23, 162, 184, 0.3);
}

/* ── API Keys Modal ──────────────────────────────────────────── */

.api-keys-modal {
    max-width: 1000px;
}

.api-keys-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

.api-keys-table thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--line-color, #404040);
    font-weight: bold;
    font-size: 0.85em;
    color: rgba(127, 255, 0, 0.7);
}

.api-keys-table tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(127, 255, 0, 0.1);
    vertical-align: middle;
}

.api-keys-table tbody tr:hover {
    background: rgba(127, 255, 0, 0.05);
}

.key-name-cell { font-weight: bold; white-space: nowrap; }

.key-value-cell code {
    font-size: 0.85em;
    color: rgba(127, 255, 0, 0.8);
    background: rgba(0, 0, 0, 0.3);
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    word-break: break-all;
}

.key-usage-cell {
    text-align: right;
    white-space: nowrap;
    color: rgba(127, 255, 0, 0.8);
}

.key-copy-cell, .key-curl-cell, .key-action-cell, .key-rotate-cell {
    width: 40px;
    text-align: center;
}

.key-curl-cell { width: 50px; }

.api-key-copy, .rotated-key-copy {
    background: transparent;
    border: 1px solid var(--line-color, #404040);
    color: var(--text-color, #7FFF00);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.7;
}

.api-key-copy:hover, .rotated-key-copy:hover { opacity: 1; border-color: var(--text-color, #7FFF00); }
.api-key-copy.copied { border-color: #4CAF50; color: #4CAF50; opacity: 1; }

.api-key-curl {
    background: transparent;
    border: 1px solid var(--line-color, #404040);
    color: var(--text-color, #7FFF00);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.75em;
    transition: all 0.2s;
    opacity: 0.7;
}

.api-key-curl:hover { opacity: 1; border-color: var(--text-color, #7FFF00); }
.api-key-curl.copied { border-color: #4CAF50; color: #4CAF50; opacity: 1; }

.api-key-rotate {
    background: transparent;
    border: 1px solid #FFA500;
    color: #FFA500;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    transition: all 0.2s;
}

.api-key-rotate:hover { background: #FFA500; color: var(--bg-color, #000040); }

.api-key-delete {
    background: transparent;
    border: 1px solid #ff6666;
    color: #ff6666;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    transition: all 0.2s;
}

.api-key-delete:hover { background: #ff6666; color: var(--bg-color, #000040); }

/* Rotated key banner */
.rotated-key-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: rgba(76, 175, 80, 0.15);
    border: 1px solid rgba(76, 175, 80, 0.4);
    border-radius: 4px;
}

.rotated-key-label { font-weight: bold; white-space: nowrap; color: #4CAF50; }

.rotated-key-value {
    font-size: 0.85em;
    word-break: break-all;
    color: var(--text-color, #7FFF00);
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 3px;
}

.rotated-key-copy { border-color: rgba(76, 175, 80, 0.4); color: #4CAF50; flex-shrink: 0; }
.rotated-key-copy:hover { border-color: #4CAF50; background: rgba(76, 175, 80, 0.1); }

.api-keys-create {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.api-keys-create input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--line-color, #404040);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-color, #7FFF00);
    font-family: inherit;
    font-size: 0.9em;
}

.api-keys-create input::placeholder { color: rgba(127, 255, 0, 0.5); }
.api-keys-create input:focus { outline: none; border-color: var(--text-color, #7FFF00); }

.api-keys-count {
    font-size: 0.85em;
    color: rgba(127, 255, 0, 0.6);
    text-align: right;
}

.no-keys {
    text-align: center;
    color: rgba(127, 255, 0, 0.6);
    padding: 2rem 0;
}

#api-keys-no-billing { text-align: center; padding: 2rem 0; }
#api-keys-no-billing a { color: var(--text-color, #7FFF00); text-decoration: underline; }
#api-keys-no-billing a:hover { opacity: 0.8; }

/* ── Customers Modal (Admin) ─────────────────────────────────── */

.customers-modal {
    max-width: 1100px;
}

.customers-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.customers-table thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--line-color, #404040);
    font-weight: bold;
    font-size: 0.85em;
    color: rgba(127, 255, 0, 0.7);
}

.customers-table tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(127, 255, 0, 0.1);
    vertical-align: middle;
    font-size: 0.9em;
}

.customers-table tbody tr:hover {
    background: rgba(127, 255, 0, 0.05);
}

.customers-count {
    font-size: 0.85em;
    color: rgba(127, 255, 0, 0.6);
    text-align: right;
}

.account-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.85em;
    font-weight: bold;
    text-transform: uppercase;
}

.status-active { color: #4CAF50; border: 1px solid rgba(76, 175, 80, 0.4); }
.status-paused { color: #ff6666; border: 1px solid rgba(255, 102, 102, 0.4); }

/* ── Light Mode Overrides ────────────────────────────────────── */

body.light-mode .modal-content { background: rgba(255, 255, 255, 0.95); }
body.light-mode .billing-status { background: rgba(0, 0, 0, 0.05); }
body.light-mode .credits-balance { background: rgba(0, 0, 0, 0.05); }
body.light-mode .balance-amount { border-bottom-color: rgba(45, 80, 22, 0.2); }
body.light-mode .balance-label { color: rgba(45, 80, 22, 0.7); }
body.light-mode .btn-primary { background: #2D5016; color: #FFFFFF; }
body.light-mode .btn-secondary { border-color: #2D5016; color: #2D5016; }
body.light-mode .btn-secondary:hover:not(:disabled) { background: rgba(45, 80, 22, 0.1); }

body.light-mode .auto-reload-status.error { color: #721c24; }
body.light-mode .auto-reload-status.warning { color: #856404; }
body.light-mode .auto-reload-status.pending { color: #0c5460; }

body.light-mode .api-keys-table thead th { color: rgba(45, 80, 22, 0.7); }
body.light-mode .api-keys-table tbody td { border-bottom-color: rgba(45, 80, 22, 0.1); }
body.light-mode .api-keys-table tbody tr:hover { background: rgba(45, 80, 22, 0.05); }
body.light-mode .key-value-cell code { color: #2D5016; background: rgba(0, 0, 0, 0.05); }
body.light-mode .key-usage-cell { color: rgba(45, 80, 22, 0.8); }
body.light-mode .api-keys-create input { background: rgba(0, 0, 0, 0.05); color: #2D5016; }
body.light-mode .api-keys-create input::placeholder { color: rgba(45, 80, 22, 0.5); }
body.light-mode .api-keys-count { color: rgba(45, 80, 22, 0.6); }
body.light-mode .no-keys { color: rgba(45, 80, 22, 0.6); }
body.light-mode #api-keys-no-billing a { color: #2D5016; }
