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

:root {
    --bg-main: #F4F7FE; /* Very soft blue/gray for that premium modern app feel */
    --bg-card: #FFFFFF;
    --text-main: #1B2559;
    --text-muted: #A3AED0;
    --primary: #4318FF; /* Vibrant modern indigo/purple */
    --primary-hover: #3311DB;
    --primary-light: rgba(67, 24, 255, 0.05);
    --secondary: #F4F7FE;
    --secondary-hover: #E9EDF7;
    --success: #05CD99;
    --success-light: rgba(5, 205, 153, 0.1);
    --danger: #EE5D50;
    --danger-light: rgba(238, 93, 80, 0.1);
    --border: #E9EDF7;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Outfit', sans-serif;
    
    --shadow-sm: 0px 2px 4px rgba(0, 0, 0, 0.02);
    --shadow-md: 0px 10px 20px rgba(0, 0, 0, 0.03);
    --shadow-hover: 0px 18px 40px rgba(112, 144, 176, 0.15);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    letter-spacing: -0.02em;
    color: var(--text-main);
}

/* Sidebar Navigation */
.sidebar {
    width: 280px;
    background-color: var(--bg-card);
    display: flex;
    flex-direction: column;
    padding: 2rem 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.02);
    z-index: 10;
}

.sidebar-header {
    padding: 0 2rem 1.5rem;
    margin-bottom: 1rem;
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    background: linear-gradient(135deg, var(--primary), #868CFF);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0 1.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-muted);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.nav-item svg {
    transition: all 0.25s ease;
}

.nav-item:hover {
    background-color: var(--secondary);
    color: var(--text-main);
    transform: translateX(4px);
}

.nav-item.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 8px 16px rgba(67, 24, 255, 0.2);
}

.nav-item.active svg {
    color: white;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: 80px;
    background: rgba(244, 247, 254, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 2.5rem;
    position: sticky;
    top: 0;
    z-index: 5;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--bg-card);
    padding: 0.5rem 1.25rem;
    border-radius: 99px;
    box-shadow: var(--shadow-sm);
    color: var(--text-main);
    transition: all 0.3s ease;
}

.status-indicator:hover {
    box-shadow: var(--shadow-md);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-muted);
    transition: all 0.3s ease;
}
.dot.active {
    background-color: var(--success);
    box-shadow: 0 0 10px var(--success);
}
.dot.error {
    background-color: var(--danger);
    box-shadow: 0 0 10px var(--danger);
}

.content-wrapper {
    padding: 1rem 2.5rem 2.5rem;
    flex: 1;
    overflow-y: auto;
}

/* Tab Views */
.tab-view {
    display: none;
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.tab-view.active {
    display: block;
}

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

/* Cards */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    box-shadow: var(--shadow-md);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(255,255,255,0.4);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.card h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}
.card h2 svg {
    color: var(--primary);
}

.card .desc {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

/* Metrics */
.metrics {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--bg-main);
    transition: all 0.2s ease;
}
.metric:hover {
    background: var(--secondary-hover);
}
.metric .label {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}
.metric .value {
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.95rem;
}

/* Buttons */
.btn {
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-family);
}
.btn.primary {
    background: linear-gradient(135deg, var(--primary), #6B4CFF);
    color: white;
    width: 100%;
    box-shadow: 0 4px 12px rgba(67, 24, 255, 0.2);
}
.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(67, 24, 255, 0.3);
}
.btn.primary:active {
    transform: translateY(0);
}
.btn.secondary {
    background-color: var(--bg-main);
    color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--border);
}
.btn.secondary:hover {
    background-color: var(--secondary-hover);
    color: var(--primary-hover);
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
}
input, textarea, select {
    width: 100%;
    padding: 0.85rem 1rem;
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--bg-card);
    box-shadow: 0 0 0 4px var(--primary-light);
}

/* Tables */
.table-container {
    overflow-x: auto;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-card);
}
.keys-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}
.keys-table th, .keys-table td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}
.keys-table th {
    background: var(--bg-main);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}
.keys-table tr {
    transition: background-color 0.2s ease;
}
.keys-table tr:hover {
    background-color: var(--bg-main);
}
.keys-table tr:last-child td {
    border-bottom: none;
}
.keys-table code {
    background: var(--secondary);
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    font-family: monospace;
    color: var(--primary);
    font-size: 0.85rem;
    border: 1px solid var(--border);
}

.generate-key-form {
    display: flex;
    gap: 1rem;
    align-items: center;
}
.generate-key-form input {
    flex-grow: 1;
}

/* Toggle Switch CSS */
.free-model-toggle {
    margin-top: 20px;
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}
.free-model-toggle:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md);
}
.switch { position: relative; display: inline-block; width: 48px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { 
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; 
    background-color: #E2E8F0; transition: .4s; 
    border-radius: 34px;
}
.slider:before { 
    position: absolute; content: ""; height: 20px; width: 20px; 
    left: 3px; bottom: 3px; background-color: white; 
    transition: .4s; border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
input:checked + .slider { background-color: var(--primary); }
input:focus + .slider { box-shadow: 0 0 0 3px var(--primary-light); }
input:checked + .slider:before { transform: translateX(22px); }

/* Dev Docs Styles */
.doc-section {
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    background: var(--bg-main);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}
.doc-section p {
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.doc-section code {
    background: var(--bg-card);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--primary);
    font-family: monospace;
    font-size: 0.85rem;
    border: 1px solid var(--border);
}

.doc-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.doc-tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.75rem 0;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.doc-tab:hover { color: var(--text-main); }
.doc-tab.active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

.doc-content {
    display: none;
    background: #0B1120; /* Very dark blue for sleek code block */
    border-radius: var(--radius-md);
    padding: 1.5rem;
    overflow-x: auto;
    border: 1px solid #1E293B;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}
.doc-content.active {
    display: block;
    animation: slideUpFade 0.3s ease forwards;
}
.doc-content pre {
    margin: 0;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: #E2E8F0;
    line-height: 1.5;
}

.test-response {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Toasts */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border-left: 4px solid var(--primary);
    z-index: 1000;
    font-weight: 500;
    font-size: 0.9rem;
}
.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-muted);
}
.icon-btn:hover {
    background: var(--secondary-hover);
    color: var(--text-main);
    border-color: #CBD5E1;
}

/* Auth Overlay with Glassmorphism */
.auth-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(244, 247, 254, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    background: rgba(255, 255, 255, 0.9);
    padding: 3rem 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 420px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    animation: slideUpFade 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-title {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 2.5rem;
}

.auth-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.auth-error {
    color: var(--danger);
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 1rem;
    text-align: center;
    min-height: 1.5rem;
}

/* Profile Section */
.profile-section {
    display: flex;
    align-items: center;
    padding: 1.5rem 2rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.profile-avatar {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary), #868CFF);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
    margin-right: 1rem;
    box-shadow: 0 4px 10px rgba(67, 24, 255, 0.2);
}

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

.profile-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
}

.profile-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
    margin-top: 2px;
}

/* Badges inside tables */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.75rem;
}
.badge.primary { background: var(--primary-light); color: var(--primary); }
.badge.success { background: var(--success-light); color: var(--success); }
.badge.danger { background: var(--danger-light); color: var(--danger); }

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 1.5rem 1rem;
        box-shadow: none;
    }
    .nav-menu {
        flex-direction: row;
        overflow-x: auto;
        padding: 0;
        margin-top: 1rem;
    }
    .nav-item {
        white-space: nowrap;
    }
    .topbar {
        padding: 0 1.5rem;
    }
    .content-wrapper {
        padding: 1.5rem;
    }
    .generate-key-form {
        flex-direction: column;
    }
    .generate-key-form button {
        width: 100%;
    }
    .table-container {
        display: block;
        width: 100%;
    }
    .keys-table th, .keys-table td {
        padding: 1rem;
    }
}
