:root {
    --bg: #f5f6f7;
    --surface: #ffffff;
    --text: #1d2d3e;
    --muted: #556b82;
    --border: #d9d9d9;
    --primary: #0070f2;
    --primary-hover: #0064d9;
    --user-bubble: #e8f2ff;
    --ok: #188918;
    --error: #aa0808;
    --warning-bg: #fff8d6;
    --warning-border: #e9730c;
    font-family: "72", "72full", Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: var(--text);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; background: var(--bg); }

.app { display: flex; flex-direction: column; height: 100%; max-width: 960px; margin: 0 auto; }

.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}

.status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="online"]::before { background: var(--ok); }
.status[data-state="offline"]::before { background: var(--error); }

.btn {
    font: inherit; border-radius: 8px; padding: 8px 16px; cursor: pointer;
    border: 1px solid transparent; transition: background .15s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.ghost { background: transparent; color: var(--primary); border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--bg); }
.btn.danger { background: transparent; color: var(--error); border-color: var(--error); }

.login { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card {
    background: var(--surface); border-radius: 12px; padding: 32px; max-width: 420px;
    box-shadow: 0 2px 8px rgba(34, 54, 73, .12); text-align: center;
}
.card h1 { margin: 0 0 8px; font-size: 20px; }
.card p { color: var(--muted); line-height: 1.5; }
.hint { font-size: 12px; }
.hint a { color: var(--primary); }

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

.empty { margin: auto; text-align: center; color: var(--muted); }
.empty h1 { color: var(--text); font-size: 22px; margin-bottom: 4px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chip {
    font: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    padding: 8px 14px; cursor: pointer; color: var(--text);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }

.msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user-bubble); white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.msg .error { color: var(--error); }

.typing::after { content: "…"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.activity { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.activity:empty { display: none; }
.tool { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tool::before {
    content: ""; width: 10px; height: 10px; border-radius: 50%;
    border: 2px solid var(--primary); border-right-color: transparent; animation: spin .8s linear infinite;
}
.tool.ok::before { animation: none; border: none; background: var(--ok); }
.tool.fail::before { animation: none; border: none; background: var(--error); }
@keyframes spin { to { transform: rotate(360deg); } }

.confirm {
    margin: 8px 0; padding: 12px; border-radius: 8px; background: var(--warning-bg);
    border-left: 4px solid var(--warning-border); white-space: pre-wrap; font-size: 13px;
}
.confirm .actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; white-space: normal; }
.confirm .timer { font-size: 12px; color: var(--muted); margin-left: auto; }
.confirm.closed .actions button { display: none; }

.body table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; }
.body th, .body td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; white-space: nowrap; }
.body th { background: var(--bg); }
.body code { background: var(--bg); padding: 1px 4px; border-radius: 4px; font-size: 12px; }
.body pre { background: var(--bg); padding: 8px; border-radius: 6px; overflow-x: auto; }
.body pre code { background: none; padding: 0; }
.body h2, .body h3, .body h4 { font-size: 15px; margin: 12px 0 4px; }
.body ul, .body ol { padding-left: 20px; }

.composer {
    display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface);
}
.composer textarea {
    flex: 1; font: inherit; resize: none; max-height: 160px; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.composer textarea:focus { border-color: var(--primary); }

.oauth-done main { max-width: 420px; margin: 15vh auto; text-align: center; padding: 16px; }
.oauth-done p { color: var(--muted); }
