:root {
    --bg: #ffffff;
    --canvas: #f7f7f8;
    --ink: #111111;
    --muted: #6d6d6d;
    --line: #e7e7e7;
    --hover: #f2f2f3;
    --soft: #f4f4f5;
    --danger: #b42318;
    --shadow: 0 1px 2px rgba(16, 16, 16, 0.04), 0 12px 32px rgba(16, 16, 16, 0.06);
    --radius: 12px;
    color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font: 14px/1.5 Inter, ui-sans-serif, -apple-system, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

button, .quiet {
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
    color: var(--ink);
    font-weight: 500;
}
button:hover { background: var(--hover); }
.primary {
    background: #111;
    color: #fff;
    border-color: #111;
}
.primary:hover { background: #2b2b2b; }
.quiet, button.quiet {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}
.quiet:hover, button.quiet:hover { background: var(--hover); color: var(--ink); }
.icon-btn, .file-btn, .send, .icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    border-radius: 9px;
    background: transparent;
    border: 0;
    color: var(--muted);
}
.icon-btn:hover, .file-btn:hover, .icon:hover { background: var(--hover); color: var(--ink); }
.send {
    margin-left: auto;
    background: #111;
    color: #fff;
    border-radius: 999px;
}
.send:hover { background: #2b2b2b; }

.form-error { color: var(--danger); margin: 0; font-size: 13px; }
.form-error:not(:empty) { margin-top: 8px; }
.form-error.ok { color: #111; }
.note { color: var(--muted); margin: 0; font-size: 13px; }
.note code, .secret code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    background: var(--soft);
    padding: 1px 5px;
    border-radius: 5px;
}
.secret {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 0;
    padding: 10px 12px;
    background: var(--canvas);
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 13px;
}
.secret code { word-break: break-all; background: #fff; }

label { display: grid; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
input, textarea, select {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 9px;
    padding: 8px 10px;
    min-height: 36px;
    outline: none;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: #111; box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.08); }
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236d6d6d' stroke-width='1.75' stroke-linecap='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.mark {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #111;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.gate {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--canvas);
}
.gate-panel {
    width: min(760px, 100%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.gate-brand, .gate-card { padding: 32px 28px; }
.gate-brand {
    background: var(--canvas);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
}
.gate-brand h1 { margin: 0; font-size: 28px; letter-spacing: -0.04em; }
.lede { margin: 0; color: var(--muted); max-width: 28ch; }
.gate-card { display: grid; align-content: center; gap: 12px; }
.gate-card button { width: 100%; height: 38px; }

.shell { height: 100dvh; display: grid; grid-template-columns: 268px 1fr; }
.side {
    background: var(--canvas);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.side-top { padding: 14px 12px 8px; display: grid; gap: 12px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 4px; }
.brand strong { display: block; font-size: 14px; letter-spacing: -0.02em; }
.brand small { color: var(--muted); font-size: 12px; }
.new-chat { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; }
.new-chat svg { stroke: #fff; }
.side-label {
    margin: 8px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #8a8a8a;
}
.chats {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0 8px 8px;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: 2px;
}
.chat-row { display: flex; align-items: center; border-radius: 8px; }
.chat-row:hover, .chat-item.active { background: #fff; }
.chat-item {
    flex: 1;
    min-width: 0;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 8px;
    padding: 8px 8px 8px 10px;
    height: auto;
}
.chat-item span, .chat-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item small, .muted { color: var(--muted); font-size: 12px; font-weight: 400; }
.chat-row .icon { opacity: 0; }
.chat-row:hover .icon, .chat-row:focus-within .icon { opacity: 1; }
.side-links { margin-top: auto; border-top: 1px solid var(--line); padding: 8px; display: grid; gap: 2px; }
.side-links button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 34px;
    padding: 0 8px;
    border: 0;
    background: transparent;
    color: #3a3a3a;
    font-weight: 500;
    text-align: left;
}
.side-links button:hover, .side-links button.active { background: #fff; color: #111; }

.top {
    height: 52px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px 0 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
}
.top-title { flex: 1; min-width: 0; }
.top-title h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.02em; }
#chat-title {
    width: min(440px, 100%);
    min-height: 32px;
    border-color: transparent;
    background: transparent;
    font-weight: 600;
    padding: 4px 8px;
    box-shadow: none;
}
#chat-title:hover, #chat-title:focus { background: var(--canvas); border-color: transparent; }
.menu { display: none; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 99px; background: #c7c7c7; }
.dot.on { background: #111; }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #fff; }
#view-chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow: auto; padding: 28px 16px 12px; }
.thread { width: min(760px, 100%); margin: 0 auto; display: grid; gap: 22px; }
.msg { display: grid; gap: 6px; }
.msg.user { justify-items: end; }
.bubble { max-width: min(680px, 100%); }
.msg.assistant .bubble { width: 100%; max-width: none; }
.msg.user .bubble {
    background: var(--soft);
    border-radius: 16px;
    padding: 10px 14px;
}
.msg-tools { display: flex; gap: 8px; align-items: center; min-height: 18px; }
.msg.user .msg-tools { padding-right: 4px; }
.copy-msg, .copy-code {
    height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: #8a8a8a;
    font-size: 12px;
    font-weight: 500;
}
.copy-msg:hover, .copy-code:hover { color: #111; background: transparent; }
.msg-tools small { color: #8a8a8a; font-size: 11px; }
.pending { color: var(--muted); margin: 0; }
.fail {
    margin: 0;
    color: var(--danger);
    background: #fff5f5;
    border: 1px solid #f3d0d0;
    border-radius: 10px;
    padding: 8px 10px;
}
.attach { display: flex; gap: 8px; flex-wrap: wrap; }
.attach a {
    color: inherit;
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    background: #fff;
}
.attach img { max-width: 240px; max-height: 180px; display: block; border-radius: 12px; border: 1px solid var(--line); }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 1.2em; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15px; margin: 0 0 8px; letter-spacing: -0.02em; }
.bubble a { color: inherit; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.bubble p code, .bubble li code { background: #eeeef0; border-radius: 5px; padding: 1px 5px; }
.bubble pre {
    margin: 0 0 10px;
    overflow: auto;
    background: #f6f6f7;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0;
}
.codebar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    color: #8a8a8a;
    font-size: 11px;
    border-bottom: 1px solid var(--line);
}
.bubble pre code { display: block; padding: 10px 12px; white-space: pre; }
.empty { color: var(--muted); text-align: center; padding: 18vh 16px 0; margin: 0; }

.composer {
    width: min(760px, calc(100% - 24px));
    margin: 0 auto 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 8px 8px 8px 12px;
    box-shadow: var(--shadow);
}
.composer textarea {
    display: block;
    width: 100%;
    border: 0;
    min-height: 28px;
    max-height: 160px;
    padding: 6px 4px;
    resize: none;
    box-shadow: none;
    overflow: auto;
}
.composer textarea:focus { box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: 6px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.composer-bar select {
    width: auto;
    max-width: 210px;
    min-height: 32px;
    height: 32px;
    border-radius: 999px;
    background-color: var(--canvas);
    font-size: 12px;
    padding-top: 0;
    padding-bottom: 0;
}
.file-list { display: flex; gap: 6px; flex-wrap: wrap; }
.file-list:empty { display: none; }
.file-list span { background: var(--canvas); border-radius: 999px; padding: 2px 8px; font-size: 12px; color: var(--muted); }

.page { flex: 1; overflow: auto; background: var(--canvas); }
.page-inner { width: min(980px, calc(100% - 32px)); margin: 20px auto 32px; display: grid; gap: 14px; }
.block, .inline-form {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
}
.block { display: grid; gap: 10px; align-content: start; }
.block h3, .page-inner > h3 { margin: 0; font-size: 14px; letter-spacing: -0.02em; }
.inline-form { display: flex; gap: 10px; align-items: end; }
.grow { flex: 1; }
.inline-form textarea { min-height: 58px; }
.inline-form button { height: 36px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pair, .actions { display: flex; gap: 10px; }
.pair label { flex: 1; }
.admin-layout { grid-template-columns: 320px 1fr; align-items: start; }
.table-block { min-width: 0; overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #8a8a8a;
    padding: 0 10px 8px;
    border-bottom: 1px solid var(--line);
}
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table .quiet { height: 28px; }
.list, #key-list {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 4px 14px;
}
.list { display: grid; }
.list > .muted, #key-list > .muted { padding: 12px 0; }
.row-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 12px;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}
.row-item:last-child { border-bottom: 0; }
.row-item small { grid-column: 1; }
.row-item button { grid-column: 2; grid-row: 1 / span 2; }
.row-item p { margin: 0; }
.perm-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.perm {
    width: auto;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink);
}
label.perm { color: var(--ink); }
.perm input { width: 14px; height: 14px; min-height: 0; margin: 0; accent-color: #111; box-shadow: none; }
.perm.on { background: var(--soft); }
.perm.off { color: #8a8a8a; background: #fff; }
.perm strong { font-weight: 500; }
.backdrop { position: fixed; inset: 0; background: rgba(17, 17, 17, 0.28); z-index: 15; }

@media (max-width: 860px) {
    .gate-panel, .split, .admin-layout { grid-template-columns: 1fr; }
    .gate-brand { padding-bottom: 8px; }
    .shell { grid-template-columns: 1fr; }
    .side {
        position: fixed;
        z-index: 20;
        inset: 0 auto 0 0;
        width: min(300px, 88vw);
        transform: translateX(-105%);
        transition: transform .18s ease;
        box-shadow: var(--shadow);
    }
    body.nav-open .side { transform: none; }
    .menu { display: inline-grid; }
    .chat-row .icon { opacity: 1; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .composer-bar { flex-wrap: wrap; }
    .composer-bar select { max-width: calc(100% - 84px); }
    .page-inner { width: min(100% - 20px, 980px); margin-top: 12px; }
    .top { padding-left: 8px; }
}
