:root {
    --bg: #0c0c0f;
    --island: #16161a;
    --island-hover: #1c1c22;
    --border: #2a2a32;
    --text: #e8e8ed;
    --muted: #8b8b9a;
    --accent: #7c6cff;
    --accent-hover: #9488ff;
    --danger: #ff5c5c;
    --radius: 16px;
    --radius-sm: 10px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.island {
    background: var(--island);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Auth */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}
.auth-island {
    width: 100%;
    max-width: 400px;
    padding: 36px 32px;
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 18px;
    margin-bottom: 28px;
    color: var(--text);
}
.logo svg { color: var(--accent); }
.auth-island h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 24px;
}
.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}
.field input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text);
    font-size: 15px;
    outline: none;
}
.field input:focus { border-color: var(--accent); }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.15s;
}
.btn.primary {
    background: var(--accent);
    color: #fff;
    width: 100%;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.icon-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 12px;
    flex-shrink: 0;
}
.error {
    background: rgba(255,92,92,0.12);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
}
.muted { margin-top: 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* App layout */
.app {
    display: flex;
    height: 100vh;
    padding: 12px;
    gap: 12px;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
}

.sidebar .logo {
    margin-bottom: 24px;
    font-size: 16px;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    color: #fff;
}

.user-card .name { font-weight: 500; font-size: 14px; }
.user-card .plan { font-size: 12px; color: var(--muted); letter-spacing: 0.5px; }

.limits {
    margin-bottom: 24px;
    padding: 0 4px;
}
.limit-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
}
.limit-row strong { color: var(--text); }
.progress {
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
}
.progress .bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
}

nav { flex: 1; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 4px;
    transition: 0.15s;
}
.nav-item:hover, .nav-item.active {
    background: var(--bg);
    color: var(--text);
}
.nav-item svg { flex-shrink: 0; }

.sidebar-footer { margin-top: auto; }

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
}
.chat-header h1 {
    font-size: 16px;
    font-weight: 600;
}
.model-badge {
    font-size: 12px;
    color: var(--muted);
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 20px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome {
    margin: auto;
    text-align: center;
    color: var(--muted);
}
.welcome svg {
    margin-bottom: 12px;
    color: var(--accent);
    opacity: 0.7;
}
.welcome p { font-size: 15px; }

.msg {
    max-width: 720px;
    padding: 14px 18px;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg.assistant {
    align-self: flex-start;
    background: var(--bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 14px 16px;
}
.composer textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 140px;
    line-height: 1.45;
    font-family: inherit;
}
.composer textarea::placeholder { color: var(--muted); }

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

@media (max-width: 768px) {
    .app { flex-direction: column; padding: 8px; }
    .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; }
    .sidebar nav, .sidebar-footer { display: none; }
    .limits { margin-bottom: 0; flex: 1; }
}
