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

:root {
    --bg-dark: #0a0a0f;
    --bg-card: #12121a;
    --bg-card-hover: #1a1a28;
    --bg-input: #16161f;
    --accent: #00e59b;
    --accent-dim: rgba(0, 229, 155, 0.15);
    --accent-glow: rgba(0, 229, 155, 0.3);
    --red: #ff4d6a;
    --red-dim: rgba(255, 77, 106, 0.15);
    --yellow: #fbbf24;
    --yellow-dim: rgba(251, 191, 36, 0.15);
    --text-primary: #f0f0f5;
    --text-secondary: #8a8a9a;
    --text-muted: #5a5a6a;
    --border: #1e1e2e;
    --sidebar-width: 280px;
}

body {
    font-family: 'DM Sans', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

h1, h2, h3, h4 { font-family: 'Space Grotesk', sans-serif; }

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

/* ── Auth Pages ───────────────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    position: relative;
    z-index: 1;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.auth-card .logo {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.auth-card .logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: var(--bg-dark);
    font-weight: 700;
}

.auth-card .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 32px;
}

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

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

.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

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

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-dark);
    width: 100%;
}

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

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

.btn-secondary:hover { border-color: var(--accent); }

.btn-danger {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(255, 77, 106, 0.2);
}

.btn-danger:hover { background: rgba(255, 77, 106, 0.25); }

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

.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.auth-link a {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

.auth-link a:hover { text-decoration: underline; }

.error-msg {
    background: var(--red-dim);
    color: var(--red);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 16px;
    border: 1px solid rgba(255, 77, 106, 0.2);
}

/* ── App Layout ───────────────────────────────────────────── */
.app-layout {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header .logo {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.sidebar-header .logo-icon {
    width: 28px;
    height: 28px;
    background: var(--accent);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--bg-dark);
    font-weight: 700;
}

.new-chat-btn {
    width: 100%;
    padding: 8px 12px;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(0, 229, 155, 0.2);
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.new-chat-btn:hover {
    background: rgba(0, 229, 155, 0.25);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-track { background: transparent; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.conv-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.conv-item:hover { background: var(--bg-card-hover); }
.conv-item.active { background: var(--accent-dim); }

.conv-item .title {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conv-item .delete-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 0.75rem;
    border-radius: 4px;
}

.conv-item:hover .delete-btn { display: block; }
.conv-item .delete-btn:hover { color: var(--red); background: var(--red-dim); }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.quota-bar {
    margin-bottom: 10px;
}

.quota-bar .label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.quota-bar .bar {
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    overflow: hidden;
}

.quota-bar .bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
}

.quota-bar .bar-fill.warning { background: var(--yellow); }
.quota-bar .bar-fill.danger { background: var(--red); }

.sidebar-nav {
    display: flex;
    gap: 4px;
}

.sidebar-nav button {
    flex: 1;
    padding: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.sidebar-nav button:hover { border-color: var(--accent); color: var(--text-primary); }
.sidebar-nav button.active { background: var(--accent-dim); color: var(--accent); border-color: rgba(0, 229, 155, 0.3); }

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ── Chat View ────────────────────────────────────────────── */
.chat-header {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header .model-select {
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.chat-header .model-select:focus { border-color: var(--accent); }

.chat-header .cost-badge {
    font-size: 0.8rem;
    color: var(--accent);
    background: var(--accent-dim);
    padding: 4px 12px;
    border-radius: 100px;
    font-weight: 500;
    font-family: 'Space Grotesk', sans-serif;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message {
    max-width: 800px;
    margin: 0 auto 24px;
    display: flex;
    gap: 16px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: 'Space Grotesk', sans-serif;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--accent-dim);
    color: var(--accent);
}

.message.assistant .message-avatar {
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-content .role-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.message-body {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-body p { margin-bottom: 12px; }
.message-body p:last-child { margin-bottom: 0; }
.message-body ul, .message-body ol { padding-left: 24px; margin-bottom: 12px; }
.message-body li { margin-bottom: 4px; }

.message-body pre {
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin-bottom: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
}

.message-body code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

.message-body :not(pre) > code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.message-body blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.message-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
}

.message-body th, .message-body td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
    font-size: 0.85rem;
}

.message-body th {
    background: var(--bg-card);
    font-weight: 600;
}

.message-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 6px;
    font-family: 'JetBrains Mono', monospace;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.9rem;
    max-width: 400px;
}

/* ── Chat Input ───────────────────────────────────────────── */
.chat-input-area {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

.chat-input {
    width: 100%;
    padding: 14px 60px 14px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    outline: none;
    resize: none;
    min-height: 52px;
    max-height: 200px;
    transition: border-color 0.2s;
    line-height: 1.5;
}

.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

.send-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 36px;
    height: 36px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: var(--bg-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: opacity 0.2s;
}

.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.chat-input-hint {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ── Streaming indicator ──────────────────────────────────── */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: blink 1.4s infinite both;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* ── Admin Dashboard ──────────────────────────────────────── */
.admin-page {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
}

.admin-page::-webkit-scrollbar { width: 6px; }
.admin-page::-webkit-scrollbar-track { background: transparent; }
.admin-page::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.admin-container {
    max-width: 900px;
    margin: 0 auto;
}

.admin-header {
    margin-bottom: 32px;
}

.admin-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.admin-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.admin-section {
    margin-bottom: 32px;
}

.admin-section h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.admin-section h2 .badge {
    font-size: 0.7rem;
    background: var(--accent-dim);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 100px;
    font-weight: 500;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}

.card + .card { margin-top: 12px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}

.stat-card .value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-card .label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ── Members Table ────────────────────────────────────────── */
.member-row {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.member-row:last-child { border-bottom: none; }

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

.member-info .name {
    font-weight: 600;
    font-size: 0.9rem;
}

.member-info .email {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.member-role {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 100px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.member-role.admin { background: var(--accent-dim); color: var(--accent); }
.member-role.member { background: var(--bg-input); color: var(--text-secondary); }

.member-usage {
    text-align: right;
    min-width: 140px;
}

.member-usage .spent {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
}

.member-usage .limit {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.member-usage .usage-bar {
    height: 3px;
    background: var(--bg-input);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.member-usage .usage-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
}

.member-usage .usage-bar-fill.warning { background: var(--yellow); }
.member-usage .usage-bar-fill.danger { background: var(--red); }

.member-actions {
    display: flex;
    gap: 6px;
}

/* ── API Key Cards ────────────────────────────────────────── */
.api-key-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.api-key-item:last-child { border-bottom: none; }

.api-key-info .provider {
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: capitalize;
}

.api-key-info .hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

/* ── Invite Row ───────────────────────────────────────────── */
.invite-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.invite-row:last-child { border-bottom: none; }

.invite-info .email { font-weight: 500; font-size: 0.9rem; }
.invite-info .status {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.invite-link-box {
    display: flex;
    align-items: center;
    gap: 8px;
}

.invite-link-box input {
    padding: 4px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    width: 200px;
}

/* ── Inline form rows ─────────────────────────────────────── */
.inline-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.inline-form .form-group { flex: 1; margin-bottom: 0; }

.inline-form .btn { margin-top: 0; align-self: flex-end; white-space: nowrap; height: 40px; }

/* ── Limit Editor ─────────────────────────────────────────── */
.limit-input {
    width: 80px;
    padding: 4px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    text-align: right;
    outline: none;
}

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

/* ── Toast ────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 0.85rem;
    z-index: 1000;
    animation: slideIn 0.2s ease;
}

.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error { border-color: var(--red); color: var(--red); }

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

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 90%;
    max-width: 480px;
}

.modal h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { width: 100%; position: fixed; z-index: 50; transform: translateX(-100%); transition: transform 0.2s; }
    .sidebar.open { transform: translateX(0); }
    .stats-grid { grid-template-columns: 1fr; }
    .member-row { flex-wrap: wrap; }
    .inline-form { flex-wrap: wrap; }
}
