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

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d28;
    --bg-card: #212430;
    --bg-hover: #2a2d3a;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --accent: #6c5ce7;
    --accent-hover: #7c6ff7;
    --accent-light: rgba(108, 92, 231, 0.15);
    --green: #2ecc71;
    --red: #e74c3c;
    --orange: #f39c12;
    --border: #2a2d3a;
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

.hidden { display: none !important; }

/* Login Screen */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: radial-gradient(ellipse at top, rgba(108,92,231,0.08), transparent 60%),
                radial-gradient(ellipse at bottom, rgba(46,204,113,0.05), transparent 60%);
}

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

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header .logo {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-header h1 {
    font-size: 24px;
    margin-bottom: 4px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Dashboard */
#dashboard-screen {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
}

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

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-small {
    font-size: 24px;
}

.user-badge {
    background: var(--accent-light);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    margin-right: 12px;
}

/* Stats */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: border-color 0.2s;
}

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

.stat-icon {
    font-size: 28px;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 4px;
    border: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
    background: var(--accent);
    color: white;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h3 { font-size: 18px; }
.section-header h4 { font-size: 15px; color: var(--text-secondary); }

.badge {
    background: var(--accent-light);
    color: var(--accent);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.description {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
}

.description code {
    background: var(--bg-card);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--accent);
}

/* Search Bar */
.search-bar { margin-bottom: 16px; }

.search-bar input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.search-bar input:focus {
    border-color: var(--accent);
}

/* Provider Grid */
.provider-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.provider-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.provider-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.provider-card .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

.provider-card .status-dot.online { background: var(--green); }
.provider-card .status-dot.offline { background: var(--red); }

.provider-card h4 {
    font-size: 15px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
}

.provider-card .provider-url {
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 8px;
}

.provider-card .provider-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.provider-card .provider-meta span {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-secondary);
}

.provider-card .toggle-switch {
    position: absolute;
    top: 12px;
    right: 12px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-hover);
    border-radius: 20px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

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

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

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

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-danger {
    background: var(--red);
    color: white;
}

.btn-danger:hover { opacity: 0.9; }

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

.btn-full { width: 100%; }

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

.modal-body { padding: 20px 24px; }

.modal-body .provider-info {
    margin-bottom: 20px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
}

.modal-body .provider-info p {
    margin-bottom: 4px;
    font-size: 13px;
}

.modal-body .provider-info code {
    color: var(--accent);
    font-size: 12px;
}

.format-badge {
    background: var(--accent-light);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

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

.form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.form-row .input-key { flex: 3; padding: 8px 12px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; }
.form-row .input-label { flex: 2; padding: 8px 12px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; }
.form-row input:focus { border-color: var(--accent); outline: none; }

.error-message {
    color: var(--red);
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 20px;
}

/* Keys List */
.keys-list, .provider-keys {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.key-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s;
}

.key-item:hover { border-color: var(--accent); }

.key-item .key-info {
    flex: 1;
    min-width: 0;
}

.key-item .key-value {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.key-item .key-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.key-item .key-meta {
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

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

.key-item .key-usage {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Models Manager */
.provider-models {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.model-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.model-item .model-name {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
}

.model-item .model-priority {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 4px;
}

/* Add Key Form */
.add-key-form {
    margin-bottom: 12px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

/* Notification toast */
.notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    z-index: 2000;
    max-width: 400px;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.notification.success { border-color: var(--green); }
.notification.error { border-color: var(--red); }

/* Responsive */
@media (max-width: 768px) {
    .provider-grid { grid-template-columns: 1fr; }
    .stats-bar { grid-template-columns: 1fr; }
    .modal-content { max-height: 90vh; }
    .form-row { flex-wrap: wrap; }
    .form-row .input-key, .form-row .input-label { flex: 1 1 100%; }
}
