/* ── AI API Proxy — Premium Metallic Chrome & Sage Dark Theme ──────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Micro+5&display=swap');

:root {
    --bg-primary: #0A0A0A;
    --bg-secondary: #0A0A0A;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-card-hover: rgba(255, 255, 255, 0.05);
    --bg-input: rgba(255, 255, 255, 0.01);
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);

    /* Contrast text colors (Rule C) */
    --text-primary: #e0e0e4;
    --text-secondary: #8a8a9a;
    --text-muted: #555566;

    /* Metallic Chrome & Silver Palette */
    --accent: #e4e4e7;
    /* Silver Chrome */
    --accent-hover: #ffffff;
    --accent-glow: rgba(228, 228, 231, 0.15);
    --accent-silver: #e4e4e7;
    /* Silver Chrome */
    --accent-silver-hover: #ffffff;

    --success: #00d68f;
    --success-bg: rgba(0, 214, 143, 0.08);
    --warning: #ffaa00;
    --warning-bg: rgba(255, 170, 0, 0.08);
    --danger: #ff4757;
    --danger-bg: rgba(255, 71, 87, 0.08);
    --info: #0abde3;
    --info-bg: rgba(10, 189, 227, 0.08);

    /* Slightly rounded corners */
    --radius: 3px;
    --radius-sm: 2px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.03);
    --transition: all 0.12s ease;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
    font-size: 12px;
    /* Rule G: 12px for UI elements */
    min-height: 100vh;
}

::selection {
    background: rgba(228, 228, 231, 0.25);
    /* Subtle metallic chrome highlight */
    color: #ffffff;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */

.app-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 10px;
    /* Rule G: dense padding */
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-family: 'Micro 5', sans-serif;
    font-size: 24px;
    font-weight: 400;
    color: var(--accent-silver);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.header-logo-svg {
    transform: scaleX(-1) translateY(-2px);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 22px;
    padding: 0 8px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 10px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    position: relative;
    cursor: pointer;
}

.user-badge:hover {
    border-color: var(--border-hover);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: -2px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: max-content;
    display: none;
    flex-direction: column;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* Invisible bridge so mouse doesn't fall in the gap */
.user-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 0;
    right: 0;
    height: 6px;
}

.user-badge.has-dropdown:hover .user-dropdown {
    display: flex;
}

.dropdown-arrow {
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 0.6;
}

.user-badge.has-dropdown:hover .dropdown-arrow {
    transform: rotate(180deg);
}

.user-dropdown-item {
    padding: 8px 12px;
    font-size: 11px;
    color: #e0e0e4;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.user-dropdown-item:last-child {
    border-bottom: none;
}

.user-dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.header-actions .btn {
    height: 22px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    /* Rule G: padding 6px 10px for panels */
    transition: var(--transition);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.card:hover {
    border-color: var(--border-hover);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    min-height: 22px;
}

.card-header h2 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Accent Card (Silver Translucent featured card) ────────────────────────── */

.accent-card {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    color: var(--text-primary) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.accent-card .stat-label {
    color: var(--text-secondary) !important;
}

.accent-card .stat-value {
    color: var(--text-primary) !important;
}

.accent-card .stat-sub {
    color: var(--text-muted) !important;
}

/* ── Stats Grid ───────────────────────────────────────────────────────────── */

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

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.stat-card:hover {
    border-color: var(--border-hover);
}

.stat-label {
    font-size: 10px;
    /* Rule G: 10px for labels/metadata */
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-value.accent {
    color: var(--accent);
}

.stat-value.success {
    color: var(--success);
}

.stat-value.warning {
    color: var(--warning);
}

.stat-value.info {
    color: var(--info);
}

.stat-value.silver {
    color: var(--accent-silver);
}

.stat-sub {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Tables ────────────────────────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
}

.table-scroll {
    flex: 1;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: -5px;
}

.table-scroll::-webkit-scrollbar {
    width: 5px;
}

.table-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.table-scroll::-webkit-scrollbar-thumb {
    background: rgba(228, 228, 231, 0.2);
    border-radius: 0px !important;
}

.table-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.table-scroll table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 5px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 5px 8px;
    font-size: 11px;
    border-bottom: 1px solid rgba(39, 39, 42, 0.6);
    color: var(--text-secondary);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background: var(--bg-card-hover);
}

/* ── Badges ────────────────────────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 18px;
    box-sizing: border-box;
    padding: 1px 6px 0 6px;
    border-radius: var(--radius-sm);
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    line-height: 1;
    white-space: nowrap;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(0, 214, 143, 0.2);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid rgba(255, 170, 0, 0.2);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(255, 71, 87, 0.2);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid rgba(10, 189, 227, 0.2);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    /* Rule G: padding 4px 8px for buttons */
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.btn:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
    color: var(--accent-silver-hover);
}

.btn svg {
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn:hover svg {
    transform: scale(1.08);
}

.btn-primary {
    background: var(--accent-silver);
    border-color: var(--accent-silver);
    color: #09090b;
}

.btn-primary:hover {
    background: #ffffff;
    border-color: #ffffff;
    color: #000000;
}

.btn-danger {
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-bg);
}

.btn-sm {
    padding: 3px 6px;
    font-size: 10px;
}

.btn-xs {
    height: 18px;
    box-sizing: border-box;
    padding: 0 8px;
    font-size: 10px;
}

/* ── Inputs ────────────────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 8px;
}

.form-group label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.form-input {
    width: 100%;
    padding: 5px 8px;
    font-family: inherit;
    font-size: 11px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--border-hover);
}

.form-input::placeholder {
    color: var(--text-muted);
}

/* Hide native number spinners */
input[type="number"]::-webkit-inner-spin-button, 
input[type="number"]::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}
input[type="number"] {
    -moz-appearance: textfield;
}

/* ── Section Layout ───────────────────────────────────────────────────────── */

.section {
    margin-bottom: 8px;
}

.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.grid-2>.card {
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── Login Page ───────────────────────────────────────────────────────────── */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 10px;
}

.login-card {
    width: 100%;
    max-width: 300px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    text-align: center;
    margin-bottom: 4px;
    font-size: 14px;
    color: var(--accent-silver);
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-size: 11px;
}

.login-card .btn-primary {
    width: 100%;
    justify-content: center;
    padding: 5px 8px;
    margin-top: 6px;
}

.login-error {
    background: var(--danger-bg);
    border: 1px solid rgba(255, 71, 87, 0.1);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    color: var(--danger);
    font-size: 10px;
    margin-bottom: 8px;
    display: none;
}

/* ── API Key display ──────────────────────────────────────────────────────── */

.key-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-secondary);
    word-break: break-all;
    scrollbar-width: none;
    /* Firefox */
}

.key-display::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.copy-btn {
    flex-shrink: 0;
    padding: 2px 4px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 9px;
    transition: var(--transition);
}

.copy-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

/* ── Provider status ──────────────────────────────────────────────────────── */

.provider-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px;
    border-bottom: 1px solid rgba(39, 39, 42, 0.6);
    transition: var(--transition);
}

.provider-row:hover {
    background: var(--bg-card-hover);
}

.provider-name {
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.provider-name .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-dot.online {
    background: var(--accent);
    box-shadow: 0 0 4px var(--accent);
}

.status-dot.offline {
    background: var(--danger);
    box-shadow: 0 0 4px var(--danger);
}

.provider-meta {
    display: flex;
    gap: 10px;
    font-size: 10px;
    color: var(--text-muted);
}

/* ── Progress Bar ─────────────────────────────────────────────────────────── */

.progress-bar-wrap {
    background: var(--bg-input);
    border: 1px solid var(--border);
    height: 6px;
    position: relative;
    margin-top: 4px;
    margin-bottom: 8px;
}

.progress-bar {
    background: var(--accent);
    height: 100%;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-bar.warning {
    background: var(--warning);
}

.progress-bar.danger {
    background: var(--danger);
}

/* ── Charts ───────────────────────────────────────────────────────────────── */

.chart-wrap {
    position: relative;
    width: 100%;
    height: 200px;
    padding: 4px 0;
}

.chart-wrap canvas {
    max-width: 100%;
}

/* ── Console Logging ──────────────────────────────────────────────────────── */

.console {
    background: #060608;
    border: 1px solid var(--border);
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: #a1a1aa;
    padding: 6px 10px;
    height: 130px;
    overflow-y: auto;
    line-height: 1.4;
}

.console::-webkit-scrollbar {
    width: 4px;
}

.console::-webkit-scrollbar-track {
    background: transparent;
}

.console::-webkit-scrollbar-thumb {
    background: rgba(228, 228, 231, 0.2);
    border-radius: 0px !important;
}

.console::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

@supports (-moz-appearance: none) {

    .table-scroll,
    .console {
        scrollbar-width: thin;
        scrollbar-color: rgba(228, 228, 231, 0.2) transparent;
    }
}

.console-line {
    margin-bottom: 2px;
}

.console-line .time {
    color: var(--text-muted);
    margin-right: 6px;
}

.console-line .info {
    color: var(--info);
}

.console-line .warn {
    color: var(--warning);
}

.console-line .err {
    color: var(--danger);
}

.console-line .ok {
    color: var(--accent);
}

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

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(1px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

@keyframes modalOverlayIn {
    from { opacity: 0; backdrop-filter: blur(0px); }
    to { opacity: 1; backdrop-filter: blur(1px); }
}

@keyframes modalContentIn {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-overlay.active {
    display: flex;
    animation: modalOverlayIn 0.15s ease-out forwards;
}

.modal-overlay.active .modal {
    animation: modalContentIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal {
    background: #0a0a0a;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    width: 100%;
    max-width: 320px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
}

.modal h2 {
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--accent-silver);
}

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

/* ── Loading spinner ──────────────────────────────────────────────────────── */

.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent-silver);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ── Animations ───────────────────────────────────────────────────────────── */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(2px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.15s ease forwards;
}

/* ── Custom Select ───────────────────────────────────────────────────────── */

.custom-select-wrapper {
    position: relative;
    width: 100%;
    user-select: none;
}

.custom-select {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.custom-select.open .dropdown-arrow {
    transform: rotate(180deg);
}

.custom-options {
    position: absolute;
    top: calc(100% + 4px);
    left: auto;
    right: 0;
    min-width: 100%;
    width: max-content;
    background: var(--bg-primary); /* neutral black background */
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    z-index: 10;
    display: none;
    max-height: 150px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.custom-options.show {
    display: block;
}

.custom-option {
    padding: 6px 8px;
    font-size: 11px;
    color: #e0e0e4;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    white-space: nowrap;
}

.custom-option:last-child {
    border-bottom: none;
}

.custom-option:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.reasoning-block {
    margin: 8px 0;
    padding: 4px 12px 2px 12px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    font-size: 0.85em;
    color: rgba(255, 255, 255, 0.7);
    width: fit-content;
    transition: all 0.2s ease;
}

.reasoning-block[open] {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: none;
    border-left: 3px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.reasoning-block summary {
    cursor: pointer;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 0;
    user-select: none;
    list-style: none; /* remove default arrow */
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.reasoning-block[open] summary {
    margin-bottom: 12px;
}

.reasoning-block summary::-webkit-details-marker {
    display: none;
}

.reasoning-block .thought-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
}

@keyframes textShimmer {
    to { background-position: 200% center; }
}

.reasoning-block .thought-text {
    color: rgba(255, 255, 255, 0.85);
}

.reasoning-block[data-thinking="true"] .thought-text {
    background: linear-gradient(120deg, #ccc 0%, #ccc 40%, #fff 50%, #ccc 60%, #ccc 100%);
    background-size: 200% auto;
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
    animation: textShimmer 3s linear infinite;
}

.reasoning-block summary:hover .thought-text {
    color: #ffffff;
}

.reasoning-block[data-thinking="true"] summary:hover .thought-text {
    background: linear-gradient(120deg, #fff 0%, #fff 40%, #fff 50%, #fff 60%, #fff 100%);
    -webkit-background-clip: text;
    background-clip: text;
}