:root {
    --sidebar: #f7f7f8;
    --sidebar-hover: #ececed;
    --surface: #ffffff;
    --surface-soft: #f7f7f8;
    --surface-strong: #202123;
    --text: #202123;
    --muted: #6b6b72;
    --subtle: #8e8e93;
    --border: #e5e5e7;
    --border-strong: #d6d6d9;
    --accent: #10a37f;
    --accent-hover: #0d8f70;
    --danger: #c53f4a;
    --focus: rgba(16, 163, 127, .23);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, .12);
    --sidebar-width: 268px;
    --topbar-height: 58px;
    --content-width: 860px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; margin: 0; min-height: 100%; }
body {
    color: var(--text);
    background: var(--surface);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { color: inherit; font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Authentication and account pages */
.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px 18px;
    background: #f7f7f8;
}
.auth-card {
    width: min(440px, 100%);
    padding: 36px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: 0 18px 45px rgba(0, 0, 0, .07);
}
.brand-mark, .brand-icon {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    color: #fff;
    background: var(--surface-strong);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: -.02em;
}
.auth-card h1 { margin: 22px 0 8px; font-size: 26px; letter-spacing: -.03em; }
.auth-card > p { line-height: 1.55; }
.auth-form { display: grid; gap: 10px; margin-top: 24px; }
.auth-form label { margin-top: 4px; font-size: 13px; font-weight: 650; }
.auth-form input, .auth-form select, .auth-form textarea {
    width: 100%;
    min-height: 46px;
    padding: 11px 13px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    outline: 0;
    background: #fff;
}
.auth-form input:focus, .auth-form select:focus, .auth-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.auth-form button, .primary-btn {
    min-height: 44px;
    padding: 11px 17px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: var(--surface-strong);
    font-weight: 700;
    cursor: pointer;
}
.auth-form button:hover, .primary-btn:hover { background: #343538; }
.auth-note { margin: 22px 0 0; text-align: center; }
.auth-note a { color: var(--accent-hover); font-weight: 650; }
.alert { margin: 16px 0; padding: 12px 14px; border: 1px solid transparent; border-radius: 10px; line-height: 1.45; }
.alert.error { color: #9f2530; background: #fff4f4; border-color: #f1c9cd; }
.alert.success { color: #08765d; background: #effaf7; border-color: #bce7dc; }

/* Unified application shell */
.app-body {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
.app-shell {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: var(--surface);
    overflow: hidden;
    transition: grid-template-columns .22s ease;
}
.app-shell.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.sidebar {
    position: relative;
    z-index: 30;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    min-height: 0;
    padding: 10px;
    border-right: 1px solid var(--border);
    background: var(--sidebar);
    overflow: hidden;
    transform: translateX(0);
    visibility: visible;
    transition: transform .22s ease, visibility .22s ease;
}
.sidebar-collapsed .sidebar { transform: translateX(-100%); visibility: hidden; }
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    padding: 4px 4px 8px;
}
.sidebar-brand { display: flex; min-width: 0; align-items: center; gap: 10px; padding: 4px; border-radius: 10px; }
.sidebar-brand:hover { background: var(--sidebar-hover); }
.brand-copy { min-width: 0; }
.brand-copy strong, .brand-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-copy strong { font-size: 14px; }
.brand-copy small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.icon-button {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    cursor: pointer;
}
.icon-button:hover { background: var(--sidebar-hover); }
.sidebar-close { display: none; font-size: 25px; font-weight: 300; }
.new-chat-button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    padding: 8px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    font-size: 14px;
    font-weight: 650;
    cursor: pointer;
}
.new-chat-button:hover { background: #fdfdfd; border-color: #c4c4c8; }
.new-chat-icon { font-size: 19px; font-weight: 300; line-height: 1; }
.chat-search {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    margin-top: 10px;
    padding: 0 10px;
    border-radius: 9px;
    color: var(--muted);
}
.chat-search:focus-within { background: var(--sidebar-hover); box-shadow: 0 0 0 2px var(--focus); }
.chat-search input {
    width: 100%;
    min-width: 0;
    padding: 8px 0;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 13px;
}
.archive-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 36px;
    margin-top: 2px;
    padding: 7px 10px;
    border: 0;
    border-radius: 9px;
    color: var(--muted);
    background: transparent;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}
.archive-toggle:hover, .archive-toggle.active { color: var(--text); background: var(--sidebar-hover); }
.history-section { display: flex; flex: 1; min-height: 0; flex-direction: column; margin-top: 12px; }
.section-title { padding: 7px 10px; color: var(--subtle); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.chat-list { display: grid; align-content: start; gap: 2px; min-height: 0; padding-right: 2px; overflow-y: auto; scrollbar-width: thin; }
.chat-list-empty { padding: 10px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.chat-group-title { padding: 13px 10px 5px; color: var(--subtle); font-size: 11px; font-weight: 650; }
.chat-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 30px; align-items: center; border-radius: 9px; }
.chat-row:hover { background: var(--sidebar-hover); }
.chat-row:has(.chat-item.active) { background: #e7e7e8; }
.chat-item {
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 38px;
    padding: 8px 7px 8px 10px;
    border: 0;
    background: transparent;
    overflow: hidden;
    color: #39393d;
    font-size: 13px;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}
.chat-item span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.active { color: #171719; font-weight: 600; }
.chat-more {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    font-size: 18px;
    opacity: 0;
    cursor: pointer;
}
.chat-row:hover .chat-more, .chat-more:focus-visible { opacity: 1; }
.chat-more:hover { color: var(--text); background: #fff; }
.sidebar-footer { position: relative; padding-top: 8px; border-top: 1px solid var(--border); }
.user-menu-trigger {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 24px;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 50px;
    padding: 7px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.user-menu-trigger:hover, .user-menu-trigger[aria-expanded="true"] { background: var(--sidebar-hover); }
.avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    color: #fff;
    background: var(--accent);
    font-size: 13px;
    font-weight: 800;
}
.user-summary { min-width: 0; }
.user-summary strong, .user-summary small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-summary strong { font-size: 13px; }
.user-summary small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.user-chevron { color: var(--muted); text-align: center; }
.user-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    left: 0;
    z-index: 40;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-md);
}
.user-menu a, .user-menu form button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}
.user-menu a:hover, .user-menu form button:hover { background: var(--surface-soft); }
.user-menu form { margin: 0; }
.sidebar-scrim { display: none; }

/* Top bar and chat */
.main-panel {
    display: grid;
    grid-template-rows: var(--topbar-height) minmax(0, 1fr);
    width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 0;
    background: var(--surface);
    overflow: hidden;
}
.topbar {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, .96);
}
.topbar-start, .topbar-controls { display: flex; min-width: 0; align-items: center; gap: 9px; }
.topbar-brand { font-size: 14px; font-weight: 700; letter-spacing: -.01em; }
.topbar-workspace-link { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 6px 9px; border-radius: 8px; color: var(--muted); font-size: 12px; font-weight: 650; }
.topbar-workspace-link:hover { color: var(--text); background: var(--surface-soft); }
.topbar-select {
    height: 36px;
    padding: 0 30px 0 11px;
    border: 1px solid transparent;
    border-radius: 9px;
    outline: 0;
    background-color: transparent;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.topbar-select:hover, .topbar-select:focus { border-color: var(--border); background-color: var(--surface-soft); }
.mode-select { max-width: 170px; }
.model-select { max-width: 115px; color: var(--muted); }
.thinking-toggle { display: flex; align-items: center; gap: 7px; padding: 6px 7px; border-radius: 9px; color: var(--muted); font-size: 12px; cursor: pointer; }
.thinking-toggle:hover { background: var(--surface-soft); }
.thinking-toggle.is-disabled { opacity: .48; cursor: not-allowed; }
.thinking-toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle-track { position: relative; display: block; width: 30px; height: 18px; border-radius: 999px; background: #c8c8cc; transition: background .18s ease; }
.toggle-track span { position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .18s ease; }
.thinking-toggle input:checked + .toggle-track { background: var(--accent); }
.thinking-toggle input:checked + .toggle-track span { transform: translateX(12px); }
.thinking-toggle input:focus-visible + .toggle-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.chat-panel {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    background: var(--surface);
    overflow: hidden;
}
.conversation-scroll { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.hero {
    display: grid;
    align-content: center;
    width: min(var(--content-width), calc(100% - 40px));
    min-height: 100%;
    margin: 0 auto;
    padding: 54px 0 36px;
    text-align: center;
}
.hero-mark {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin: 0 auto 20px;
    border-radius: 16px;
    color: #fff;
    background: var(--surface-strong);
    box-shadow: 0 8px 25px rgba(0,0,0,.14);
    font-size: 17px;
    font-weight: 800;
}
.hero h1 { margin: 0; font-size: clamp(26px, 3vw, 34px); font-weight: 650; letter-spacing: -.045em; }
.hero > p { max-width: 620px; margin: 12px auto 28px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: min(640px, 100%); margin: 0 auto; }
.quick-actions button {
    display: grid;
    grid-template-columns: 28px 1fr;
    grid-template-rows: auto auto;
    column-gap: 10px;
    min-height: 74px;
    padding: 13px 15px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    text-align: left;
    cursor: pointer;
    transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
.quick-actions button:hover { border-color: #c8c8cc; box-shadow: 0 5px 15px rgba(0,0,0,.06); transform: translateY(-1px); }
.quick-actions button > span { grid-row: 1 / 3; align-self: center; color: var(--accent-hover); font-size: 22px; text-align: center; }
.quick-actions strong { align-self: end; font-size: 13px; }
.quick-actions small { align-self: start; margin-top: 3px; color: var(--muted); font-size: 11px; }
.messages { width: min(var(--content-width), calc(100% - 40px)); margin: 0 auto; padding: 22px 0 50px; }
.message { display: flex; align-items: flex-start; gap: 12px; margin: 0 0 28px; }
.message.user { flex-direction: row-reverse; }
.mini-avatar {
    display: grid;
    place-items: center;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--surface-strong);
    color: #fff;
    font-size: 14px;
}
.message.user .mini-avatar { border-radius: 50%; background: #e7e7e8; color: #48484d; }
.message-body { min-width: 0; max-width: min(740px, calc(100% - 42px)); }
.message.user .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { max-width: 100%; line-height: 1.65; overflow-wrap: anywhere; }
.message.user .bubble { padding: 10px 14px; border-radius: 18px 18px 5px 18px; background: #f1f1f2; }
.message.assistant .bubble { padding-top: 3px; }
.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code { padding: 2px 5px; border-radius: 5px; background: #f1f1f2; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 13px; }
.bubble pre { position: relative; margin: 15px 0; padding: 42px 15px 15px; border-radius: 12px; background: #171719; color: #ececf1; overflow: auto; }
.bubble pre::before { content: attr(data-language); position: absolute; top: 10px; left: 14px; color: #a5a5ab; font-size: 11px; text-transform: uppercase; }
.bubble pre code { padding: 0; background: transparent; color: inherit; white-space: pre; }
.copy-code { position: absolute; top: 7px; right: 8px; padding: 5px 9px; border: 0; border-radius: 7px; color: #d8d8dc; background: #303034; font-size: 11px; cursor: pointer; }
.copy-code:hover { background: #414146; }
.message-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    min-height: 29px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity .14s ease;
}
.message:hover .message-actions, .message:focus-within .message-actions { opacity: 1; }
.message-actions button {
    min-height: 27px;
    padding: 4px 7px;
    border: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    font-size: 11px;
    cursor: pointer;
}
.message-actions button:hover, .message-actions button.active { color: var(--text); background: var(--surface-soft); }
.message-actions button.active { color: var(--accent-hover); font-weight: 700; }
.message-status { display: flex; justify-content: flex-start; gap: 7px; margin-top: 4px; color: var(--subtle); font-size: 10.5px; }
.message.user .message-status { justify-content: flex-end; }
.message.is-cancelled .bubble { color: #55555b; }
.loading-dots::after { content: ""; display: inline-block; width: 1.4em; animation: loading-dots 1.2s steps(4, end) infinite; }
@keyframes loading-dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75%,100% { content: "..."; } }
.composer-area { width: 100%; padding: 12px 22px 8px; background: linear-gradient(to top, #fff 76%, rgba(255,255,255,0)); }
.composer {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: min(var(--content-width), 100%);
    margin: 0 auto;
    padding: 9px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: 0 3px 14px rgba(0,0,0,.08);
}
.composer:focus-within { border-color: #b7b7bb; box-shadow: 0 0 0 3px rgba(0,0,0,.04), 0 5px 18px rgba(0,0,0,.09); }
.composer textarea { width: 100%; max-height: 180px; padding: 8px 4px 4px; border: 0; outline: 0; resize: none; background: transparent; line-height: 1.5; overflow-y: auto; }
.composer textarea::placeholder { color: #96969b; }
.composer-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.composer-tools { display: flex; min-width: 0; align-items: center; gap: 5px; }
.composer .composer-send, .composer .composer-attach {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: var(--surface-strong);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
}
.composer .composer-attach { border: 1px solid var(--border); border-radius: 50%; color: var(--text); background: #fff; font-size: 23px; font-weight: 400; }
.composer .composer-send:hover { background: #343538; }
.composer .composer-attach:hover { background: var(--surface-soft); }
.composer .composer-send:disabled, .composer .composer-attach:disabled { color: #aaaab0; background: #e4e4e6; cursor: not-allowed; }
.composer .composer-send.stop-generation { color: #fff; background: #d54b55; font-size: 13px; }
.composer .composer-send.stop-generation:hover { background: #bd3944; }
.composer-model-select, .composer-model-pill { min-width: 0; max-width: 190px; height: 34px; padding: 0 28px 0 10px; border: 0; border-radius: 18px; color: var(--muted); background: transparent; font: inherit; font-size: 12px; font-weight: 650; cursor: pointer; }
.composer-model-select:hover, .composer-model-pill { background: var(--surface-soft); }
.composer-model-pill { display: inline-flex; align-items: center; padding-right: 10px; cursor: default; }
.attachment-tray { display: flex; gap: 8px; padding: 2px 2px 5px; overflow-x: auto; }
.attachment-card { position: relative; display: grid; grid-template-columns: 42px minmax(0, 1fr); align-items: center; gap: 8px; flex: 0 0 190px; min-width: 0; padding: 7px 28px 7px 7px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); color: var(--text); text-decoration: none; }
.attachment-card:hover { border-color: var(--border-strong); }
.attachment-thumb { display: grid; place-items: center; width: 42px; height: 42px; overflow: hidden; border-radius: 9px; background: #e7e7ea; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.attachment-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachment-copy { min-width: 0; }
.attachment-copy strong, .attachment-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-copy strong { font-size: 11.5px; }
.attachment-copy small { margin-top: 3px; color: var(--subtle); font-size: 9.5px; }
.attachment-remove { position: absolute; top: 5px; right: 5px; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: #fff; font-size: 14px; cursor: pointer; }
.attachment-remove:hover { color: #fff; background: #b4232f; }
.message-attachments { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 8px; margin-bottom: 8px; }
.message.user .message-attachments { justify-content: flex-end; }
.message-attachments .attachment-card { flex-basis: 210px; }
.message-attachments .attachment-card.is-image { display: block; flex-basis: min(280px, 100%); padding: 0; overflow: hidden; background: #f2f2f4; }
.message-attachments .attachment-card.is-image .attachment-thumb { width: 100%; height: 190px; border-radius: 0; }
.message-attachments .attachment-card.is-image .attachment-copy { padding: 8px 10px; }
.new-chat-button:disabled { opacity: .55; cursor: not-allowed; }
.fineprint { width: min(var(--content-width), 100%); margin: 7px auto 0; color: var(--subtle); font-size: 10.5px; line-height: 1.35; text-align: center; }

/* Chat langsung tanpa login */
.guest-plan-card { display: grid; gap: 7px; margin: 12px 2px; padding: 14px; border: 1px solid var(--border); border-radius: 13px; background: #fff; }
.guest-plan-card small { color: var(--subtle); font-size: 10px; font-weight: 750; letter-spacing: .05em; }
.guest-plan-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.guest-plan-card span { color: var(--muted); font-size: 12px; }
.guest-login-button { display: grid; place-items: center; width: 100%; margin-top: 7px; }
.guest-feature-note { display: grid; gap: 4px; margin-top: auto; padding: 13px 8px; border-top: 1px solid var(--border); }
.guest-feature-note span, .guest-feature-note small { color: var(--muted); font-size: 11px; line-height: 1.45; }
.guest-model-pill { padding: 7px 10px; border-radius: 9px; background: var(--surface-soft); font-size: 12px; font-weight: 700; }
.guest-top-login { min-height: 34px; padding: 7px 11px; }

@media (max-width: 900px) {
    .guest-app-shell { grid-template-columns: minmax(0, 1fr); }
    .guest-sidebar { display: none; }
}

/* Dialog percakapan */
.app-dialog {
    width: min(480px, calc(100vw - 28px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-md);
}
.app-dialog::backdrop { background: rgba(0, 0, 0, .36); backdrop-filter: blur(1px); }
.app-dialog > form, .chat-actions-dialog { padding: 18px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.dialog-heading small { display: block; margin-bottom: 4px; color: var(--subtle); font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.dialog-heading h2 { max-width: 380px; margin: 0; overflow: hidden; font-size: 18px; letter-spacing: -.02em; text-overflow: ellipsis; white-space: nowrap; }
.dialog-close { flex: 0 0 32px; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 22px; cursor: pointer; }
.dialog-close:hover { background: var(--surface-soft); color: var(--text); }
.dialog-actions-list { display: grid; gap: 3px; margin-top: 16px; }
.dialog-actions-list button { display: flex; align-items: center; gap: 10px; min-height: 41px; padding: 8px 10px; border: 0; border-radius: 9px; background: transparent; text-align: left; cursor: pointer; }
.dialog-actions-list button:hover { background: var(--surface-soft); }
.dialog-actions-list button span { display: inline-grid; place-items: center; width: 20px; color: var(--muted); }
.dialog-actions-list .danger-action { color: var(--danger); }
.dialog-field { display: grid; gap: 7px; margin-top: 20px; font-size: 12px; font-weight: 650; }
.dialog-field input, .dialog-field textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--border-strong); border-radius: 10px; outline: 0; background: #fff; font-weight: 400; line-height: 1.5; resize: vertical; }
.dialog-field input:focus, .dialog-field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.dialog-note { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-footer .primary-btn, .dialog-footer .secondary-btn { min-height: 39px; padding: 8px 13px; font-size: 12px; cursor: pointer; }

/* Admin pages use the same design system */
.admin-page { min-height: 100vh; padding: 26px; background: #f7f7f8; }
.admin-header { display: flex; align-items: center; justify-content: space-between; max-width: 1280px; margin: 0 auto 20px; }
.admin-header h1 { margin: 0; font-size: 26px; letter-spacing: -.03em; }
.admin-header p { margin: 6px 0 0; }
.admin-header-actions { display: flex; align-items: center; gap: 9px; }
.secondary-btn { min-height: 44px; padding: 11px 16px; border: 1px solid var(--border-strong); border-radius: 10px; background: #fff; font-weight: 650; }
.secondary-btn:hover { background: var(--surface-soft); }
.admin-card { max-width: 1280px; margin: 0 auto; padding: 20px; border: 1px solid var(--border); border-radius: 15px; background: #fff; box-shadow: var(--shadow-sm); }
.admin-card + .admin-card { margin-top: 18px; }
.admin-card h2 { margin: 0 0 15px; font-size: 18px; }
.admin-plan-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.admin-plan-card { padding: 16px; border: 1px solid var(--border); border-radius: 13px; background: #fcfcfd; }
.admin-plan-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.admin-plan-heading h3 { margin: 0 0 3px; font-size: 17px; }
.admin-plan-heading span { color: var(--muted); font-size: 11px; }
.admin-switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; }
.admin-limit-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.admin-limit-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.admin-limit-grid input { width: 100%; min-height: 36px; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; color: var(--text); font-size: 12px; }
.admin-limit-grid textarea { width: 100%; padding: 8px 9px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; color: var(--text); font: inherit; font-size: 12px; resize: vertical; text-transform: none; }
.admin-limit-grid input:disabled { background: #f1f1f3; color: var(--subtle); }
.admin-limit-grid .admin-wide { grid-column: span 3; }
.admin-payment-form { display: grid; gap: 13px; }
.payment-enabled { justify-self: start; }
.upgrade-grid { display: grid; grid-template-columns: minmax(300px, .75fr) minmax(0, 1.25fr); gap: 18px; max-width: 1280px; margin: 0 auto; }
.upgrade-grid .admin-card { width: 100%; margin: 0; }
.payment-account { display: grid; gap: 5px; margin: 12px 0; padding: 17px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); }
.payment-account small { color: var(--subtle); font-weight: 750; letter-spacing: .06em; }
.payment-account strong { font-size: 15px; }
.payment-account b { font-size: 23px; letter-spacing: .03em; }
.payment-account span { color: var(--muted); }
.pre-line { white-space: pre-line; }
.upgrade-form { margin-top: 16px; }
.upgrade-review-form { display: grid; min-width: 230px; gap: 7px; }
.upgrade-review-form > input { width: 100%; min-height: 34px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px; }
.upgrade-review-form > div { display: flex; gap: 6px; }
.upgrade-review-form button { min-height: 32px; padding: 6px 10px; font-size: 11px; }
.status-badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: #ececf0; color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.status-approved { background: #dff6e7; color: #176838; }
.status-rejected, .status-cancelled { background: #fde7e8; color: #9b2530; }
.status-pending { background: #fff2cc; color: #795800; }
.admin-feature-grid { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 14px 0 10px; }
.admin-feature-grid label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.admin-plan-card > .primary-btn { min-height: 38px; padding: 8px 12px; }
.admin-user-form { min-width: 600px; }
.table-scroll { width: 100%; overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; text-align: left; vertical-align: middle; }
.admin-table th { color: var(--muted); background: #fafafa; font-size: 11px; letter-spacing: .03em; text-transform: uppercase; }
.admin-table tbody tr:hover { background: #fcfcfc; }
.inline-form { display: flex; min-width: 500px; align-items: center; gap: 7px; }
.inline-form input, .inline-form select { min-height: 36px; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; }
.inline-form input { width: 86px; }
.inline-form button { min-height: 36px; padding: 7px 11px; border: 0; border-radius: 8px; color: #fff; background: var(--surface-strong); cursor: pointer; }

@media (max-width: 900px) {
    .app-shell, .app-shell.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
    .main-panel { grid-column: 1; width: 100vw; }
    .sidebar, .sidebar-collapsed .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(var(--sidebar-width), calc(100vw - 52px));
        min-width: min(var(--sidebar-width), calc(100vw - 52px));
        box-shadow: var(--shadow-md);
        transform: translateX(-105%);
        visibility: hidden;
    }
    .sidebar-open .sidebar { transform: translateX(0); visibility: visible; }
    .sidebar-close { display: grid; }
    .sidebar-scrim {
        position: fixed;
        inset: 0;
        z-index: 25;
        display: block;
        border: 0;
        background: rgba(0,0,0,.38);
        opacity: 0;
        visibility: hidden;
        transition: opacity .2s ease, visibility .2s ease;
    }
    .sidebar-open .sidebar-scrim { opacity: 1; visibility: visible; }
    .topbar { padding: 0 12px; }
    .topbar-brand { display: none; }
    .hero { width: min(var(--content-width), calc(100% - 28px)); }
    .messages { width: min(var(--content-width), calc(100% - 28px)); }
    .composer-area { padding-right: 14px; padding-left: 14px; }
    .admin-plan-grid { grid-template-columns: minmax(0, 1fr); }
    .upgrade-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    :root { --topbar-height: 54px; }
    .topbar { gap: 6px; }
    .topbar-start { gap: 2px; }
    .topbar-prompt-library { display: none; }
    .topbar-controls { gap: 2px; }
    .topbar-select { height: 34px; max-width: 118px; padding-right: 22px; padding-left: 8px; font-size: 12px; }
    .model-select { max-width: 83px; }
    .thinking-label { display: none; }
    .thinking-toggle { padding: 5px 4px; }
    .quick-actions { grid-template-columns: minmax(0, 1fr); }
    .quick-actions button:nth-child(n+3) { display: none; }
    .hero { align-content: start; min-height: auto; padding-top: 13vh; }
    .hero h1 { font-size: 25px; }
    .hero > p { margin-bottom: 22px; }
    .message { gap: 9px; }
    .mini-avatar { flex-basis: 28px; width: 28px; height: 28px; }
    .message-body { max-width: calc(100% - 37px); }
    .message-actions { opacity: 1; }
    .messages { padding-bottom: 32px; }
    .composer-area { padding: 8px 10px 6px; }
    .composer { border-radius: 16px; }
    .fineprint { font-size: 9.5px; }
    .auth-card { padding: 26px 22px; }
    .admin-page { padding: 14px; }
    .admin-header { align-items: flex-start; flex-direction: column; gap: 14px; }
    .admin-header-actions { flex-wrap: wrap; }
    .admin-limit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-limit-grid .admin-wide { grid-column: span 2; }
}

@media (hover: none) {
    .chat-more, .message-actions { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
