/* Cloud Console — dark operator UI, no external assets. */

:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e4e7ec;
    --muted: #8b93a3;
    --accent: #4f8cf7;
    --danger: #e5534b;
    --warn: #d9a441;
    --ok: #3fb950;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.muted { color: var(--muted); font-size: 0.875em; }
code { font-family: var(--mono); font-size: 0.9em; }

/* --- Login ------------------------------------------------------------- */

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
}

.login-card h1 { margin: 0 0 0.25rem; font-size: 1.35rem; }
.login-card p  { margin: 0 0 1.5rem; }

.login-card label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.login-card input {
    width: 100%;
    margin-bottom: 1.1rem;
    padding: 0.65rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
}

.login-card input:focus,
.composer textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.login-card button {
    width: 100%;
    padding: 0.7rem;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

.alert {
    margin: 1rem 0 0;
    padding: 0.7rem 0.85rem;
    border-radius: 8px;
    font-size: 0.85rem;
    line-height: 1.5;
}

.alert.error { background: rgba(229, 83, 75, 0.12); border: 1px solid rgba(229, 83, 75, 0.35); }
.alert.warn  { background: rgba(217, 164, 65, 0.10); border: 1px solid rgba(217, 164, 65, 0.30); color: #e8c98a; }

/* --- App shell ---------------------------------------------------------- */

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }

.topbar-actions { display: flex; gap: 0.5rem; }

.ghost {
    padding: 0.35rem 0.7rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    font-size: 0.8rem;
    text-decoration: none;
    cursor: pointer;
}

.ghost:hover { color: var(--text); border-color: var(--muted); }

/* --- Transcript --------------------------------------------------------- */

.transcript {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1rem;
}

.message { margin-bottom: 1rem; display: flex; }
.message.user { justify-content: flex-end; }

.bubble {
    max-width: 85%;
    padding: 0.7rem 0.9rem;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.message.user .bubble { background: var(--accent); border-color: var(--accent); color: #fff; }
.bubble p { margin: 0 0 0.6rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble p:last-child { margin-bottom: 0; }
.bubble.error { border-color: rgba(229, 83, 75, 0.5); background: rgba(229, 83, 75, 0.10); }
.message.placeholder .bubble { color: var(--muted); font-style: italic; }

/* --- Tool log ----------------------------------------------------------- */

.tool-log {
    margin: -0.5rem 0 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    font-size: 0.8rem;
}

.tool-log summary {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    color: var(--muted);
    user-select: none;
}

.tool-entry { padding: 0.6rem 0.75rem; border-top: 1px solid var(--border); }
.tool-entry.failed { background: rgba(229, 83, 75, 0.06); }
.tool-entry.pending { background: rgba(217, 164, 65, 0.06); }

.tool-name { font-family: var(--mono); color: var(--accent); margin-bottom: 0.35rem; }
.tool-entry.pending .tool-name { color: var(--warn); }

.tool-args, .tool-output {
    margin: 0 0 0.4rem;
    padding: 0.5rem;
    max-height: 260px;
    overflow: auto;
    background: var(--bg);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 0.75rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--muted);
}

.tool-output { color: var(--text); margin-bottom: 0; }

/* --- Pending approvals -------------------------------------------------- */

.pending-area { padding: 0 1rem 0.75rem; }

.pending-card {
    margin-bottom: 0.75rem;
    border: 1px solid rgba(217, 164, 65, 0.45);
    border-radius: 10px;
    background: rgba(217, 164, 65, 0.07);
    overflow: hidden;
}

.pending-head {
    padding: 0.55rem 0.85rem;
    background: rgba(217, 164, 65, 0.13);
    color: var(--warn);
    font-size: 0.85rem;
    font-weight: 600;
}

.pending-body {
    margin: 0;
    padding: 0.75rem 0.85rem;
    max-height: 320px;
    overflow: auto;
    font-family: var(--mono);
    font-size: 0.75rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.pending-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0 0.85rem 0.85rem;
}

.pending-actions button {
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.pending-actions .approve { background: var(--ok); border-color: var(--ok); color: #06210d; }
.pending-actions .deny { background: transparent; color: var(--muted); }
.pending-actions button:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Composer ----------------------------------------------------------- */

.composer {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    padding: 0.85rem 1rem 1.1rem;
    border-top: 1px solid var(--border);
}

.composer textarea {
    flex: 1;
    padding: 0.65rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font: inherit;
    resize: none;
    max-height: 200px;
}

.composer button {
    padding: 0.65rem 1.2rem;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.composer button:disabled { opacity: 0.55; cursor: not-allowed; }

@media (max-width: 600px) {
    .bubble { max-width: 95%; }
    .topbar { padding: 0.6rem 0.75rem; }
}

.alert.ok { background: rgba(63, 185, 80, 0.12); border: 1px solid rgba(63, 185, 80, 0.35); color: #7ee08f; }

.scope-select {
    padding: 0.35rem 0.6rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.8rem;
    max-width: 11rem;
    cursor: pointer;
}
.scope-select:focus { outline: none; border-color: var(--accent); }
/* Amber while scoped, so the restriction is visible at a glance. */
.scope-select.scoped { border-color: var(--warn); color: var(--warn); }

/* --- Streaming turns ----------------------------------------------------- */
/*
 * A live turn stacks a bubble, a status line and the tool rows, so assistant
 * messages lay out as a column. User messages stay on the flex row so they
 * keep hugging the right edge.
 */
.message.assistant { flex-direction: column; align-items: flex-start; }

.bubble.streaming::after {
    content: '';
    display: inline-block;
    width: 0.5rem;
    height: 1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--accent);
    animation: cb-caret 1s steps(1) infinite;
}
@keyframes cb-caret { 50% { opacity: 0; } }

.turn-status {
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.8rem;
    font-style: italic;
}
.turn-status:empty { display: none; }

.tool-live {
    align-self: stretch;
    margin-top: 0.5rem;
    font-size: 0.8rem;
}
.tool-live:empty { display: none; }

.tool-live .tool-entry {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    margin-bottom: 0.5rem;
}

.tool-entry.running .tool-name::after {
    content: '';
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    margin-left: 0.4rem;
    border: 2px solid var(--muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: cb-spin 0.7s linear infinite;
}
@keyframes cb-spin { to { transform: rotate(360deg); } }

/* A card whose action already ran but whose follow-up failed. */
.pending-card.stale { opacity: 0.5; }

/* --- Markdown ------------------------------------------------------------ */

.bubble .md-heading { margin: 0.4rem 0 0.5rem; font-size: 1rem; line-height: 1.3; }
.bubble .md-heading:first-child { margin-top: 0; }
.bubble ul, .bubble ol { margin: 0 0 0.6rem; padding-left: 1.3rem; }
.bubble li { margin-bottom: 0.25rem; overflow-wrap: anywhere; }
.bubble :not(pre) > code {
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    overflow-wrap: anywhere;
}
.message.user .bubble :not(pre) > code { background: rgba(0, 0, 0, 0.22); border-color: transparent; }

.code-block {
    margin: 0 0 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    overflow: hidden;
}
.code-block:last-child { margin-bottom: 0; }

.code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.3rem 0.6rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--muted);
}

.code-copy {
    padding: 0.15rem 0.5rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
    font-size: 0.72rem;
    cursor: pointer;
}
.code-copy:hover { color: var(--text); border-color: var(--muted); }

.code-block pre {
    margin: 0;
    padding: 0.6rem;
    max-height: 420px;
    overflow: auto;
    font-family: var(--mono);
    font-size: 0.78rem;
    line-height: 1.45;
    /* Code must not be reflowed — wrapping would misrepresent it. */
    white-space: pre;
}

/* Per-turn spend. Deliberately visible: an agentic turn can cost far more
   than the question that started it, and that is not guessable otherwise. */
.turn-cost {
    margin-top: 0.35rem;
    font-family: var(--mono);
    font-size: 0.68rem;
    color: var(--muted);
    opacity: 0.75;
}
