/* ============================================
   API Keys Management - Dark Theme
   Matches DAT Workspace design language
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222636;
    --bg-input: #2a2e3f;
    --border: #2e3348;
    --text-primary: #f5f6fa;
    --text-secondary: #cdd1e0;
    --text-muted: #a0a4b8;
    --accent: #6c8cff;
    --accent-hover: #8ba4ff;
    --green: #4ade80;
    --yellow: #facc15;
    --red: #f87171;
    --orange: #fb923c;
    --radius: 8px;

    --header-height: 52px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ---------- Header ---------- */
.header {
    background: rgba(15, 17, 23, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(108, 140, 255, 0.1);
    padding: 0 20px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.header__back:hover {
    background: rgba(108, 140, 255, 0.15);
    color: var(--text-primary);
}

.header__back svg {
    width: 20px;
    height: 20px;
}

.header__title {
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent) 0%, hsla(270, 50%, 65%, 1) 50%, hsla(40, 80%, 60%, 1) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ---------- Access Denied ---------- */
.access-denied {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    height: calc(100vh - var(--header-height));
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
}

.access-denied h2 {
    color: var(--red);
    font-size: 1.3rem;
}

.access-denied p {
    font-size: 0.9rem;
}

.access-denied svg {
    color: var(--red);
    opacity: 0.6;
}

/* ---------- Main ---------- */
.main {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px 20px;
}

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.toolbar__title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ---------- Buttons ---------- */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.15s, opacity 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    text-decoration: none;
}

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

.btn--accent {
    background: var(--accent);
    color: #fff;
}

.btn--accent:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn--secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn--secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn--danger {
    background: rgba(248, 113, 113, 0.12);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.btn--danger:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.22);
}

.btn--small {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn--icon {
    padding: 6px;
    min-width: 32px;
    justify-content: center;
}

.btn svg {
    width: 16px;
    height: 16px;
}

/* ---------- Status Bar ---------- */
.status-bar {
    padding: 10px 16px;
    font-size: 0.85rem;
    border-radius: var(--radius);
    margin-bottom: 16px;
    display: none;
}

.status-bar.is-visible {
    display: block;
}

.status-bar--success {
    background: rgba(74, 222, 128, 0.1);
    color: var(--green);
    border: 1px solid rgba(74, 222, 128, 0.2);
}

.status-bar--error {
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

/* ---------- API Key Cards ---------- */
.keys-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.key-card {
    background: rgba(34, 38, 54, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
}

.key-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.key-card__name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.key-card__prefix {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 4px 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    display: inline-block;
}

.key-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.key-card__meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.key-card__scopes {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.scope-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 500;
    background: rgba(108, 140, 255, 0.1);
    color: var(--accent);
    border: 1px solid rgba(108, 140, 255, 0.2);
}

.scope-pill--all {
    background: rgba(74, 222, 128, 0.1);
    color: var(--green);
    border-color: rgba(74, 222, 128, 0.2);
}

.key-card--inactive {
    opacity: 0.5;
}

.key-card--inactive .key-card__name::after {
    content: ' (revoked)';
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.85rem;
}

/* ---------- Empty State ---------- */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 48px 24px;
    background: rgba(34, 38, 54, 0.5);
    border: 1px dashed var(--border);
    border-radius: 12px;
}

.empty-state__icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    opacity: 0.4;
}

.empty-state__title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state__desc {
    font-size: 0.85rem;
}

/* ---------- Usage Instructions ---------- */
.usage-box {
    background: rgba(34, 38, 54, 0.6);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    margin-top: 24px;
}

.usage-box__header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.usage-box__header svg {
    width: 18px;
    height: 18px;
}

.usage-box__text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.usage-box__code {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow-x: auto;
    white-space: pre;
    line-height: 1.6;
}

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.modal.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.modal__card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 24px 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.modal__close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.modal__title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal__title svg {
    width: 24px;
    height: 24px;
}

.modal__title--success {
    color: var(--green);
}

.modal__form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal__error {
    font-size: 0.85rem;
    color: var(--red);
    min-height: 18px;
}

.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

/* ---------- Form Fields ---------- */
.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-field__label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-field__hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.form-field input[type="text"] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.form-field input:focus {
    border-color: var(--accent);
}

/* ---------- Scopes Checkboxes ---------- */
.scopes-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.scope-check {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    transition: border-color 0.15s, background 0.15s;
}

.scope-check:hover {
    border-color: var(--accent);
}

.scope-check input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-secondary);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}

.scope-check input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.scope-check input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.scope-check--disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---------- Key Display (Success Modal) ---------- */
.key-display {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.key-display__value {
    flex: 1;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
    word-break: break-all;
    line-height: 1.5;
}

.key-display__copy {
    flex-shrink: 0;
}

.key-display__copy.copied {
    color: var(--green);
}

.warning-box {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: rgba(250, 204, 21, 0.08);
    border: 1px solid rgba(250, 204, 21, 0.2);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.warning-box svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: var(--yellow);
}

.warning-box__text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.warning-box__text strong {
    color: var(--yellow);
    font-weight: 600;
}

/* ---------- Confirm Modal ---------- */
.confirm-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
}

.confirm-text strong {
    color: var(--text-primary);
}

/* ---------- Loading ---------- */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
    .main {
        padding: 16px 12px;
    }

    .key-card {
        padding: 14px 16px;
    }

    .modal__card {
        margin: 12px;
        padding: 24px 18px 20px;
    }

    .toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}
