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

/* The Keepwork shell uses component CSS. Supply its browser defaults locally
   so the SDK and first paint do not wait for a runtime CSS compiler. */
:where(html.keepwork-workbench) { line-height: 1.5; -webkit-text-size-adjust: 100%; tab-size: 4; }
:where(.keepwork-workbench) *, :where(.keepwork-workbench) ::before, :where(.keepwork-workbench) ::after {
    border-width: 0; border-style: solid; border-color: #e5e7eb;
}
:where(.keepwork-workbench) :is(button, input, select, optgroup, textarea) {
    font: inherit; letter-spacing: inherit; color: inherit;
}
:where(.keepwork-workbench) button, :where(.keepwork-workbench) input:where([type="button"], [type="submit"], [type="reset"]) {
    background-color: transparent; cursor: pointer;
}
:where(.keepwork-workbench) :disabled { cursor: default; }
:where(.keepwork-workbench) :is(h1, h2, h3, h4, h5, h6) { font-size: inherit; font-weight: inherit; }
:where(.keepwork-workbench) a { color: inherit; text-decoration: inherit; }
:where(.keepwork-workbench) :is(ul, ol, menu) { list-style: none; }
:where(.keepwork-workbench) :is(img, svg, video, canvas, audio, iframe, embed, object) { display: block; vertical-align: middle; }
:where(.keepwork-workbench) :is(img, video) { max-width: 100%; height: auto; }
:where(.keepwork-workbench) hr { height: 0; color: inherit; border-top-width: 1px; }
:where(.keepwork-workbench) table { text-indent: 0; border-color: inherit; border-collapse: collapse; }
:where(.keepwork-workbench) :is(code, kbd, pre, samp) { font-family: ui-monospace, monospace; font-size: 1em; }
:where(.keepwork-workbench) .hidden, :where(.keepwork-workbench) [hidden]:where(:not([hidden="until-found"])) { display: none; }

:root {
    color-scheme: dark;
    /* Dark chat canvas, matching the VS Code reference while keeping raised controls. */
    --bg-base: #181818; --bg-sidebar: #2b2b2b; --bg-card: #404040;
    --bg-pill: #4a4a4a; --bg-pill-hover: #565656;
    --border: #4d4d4d; --border-card: #5a5a5a;
    --text-primary: #e8e8e8; --text-secondary: #cccccc;
    --text-muted: #b0b0b0; --text-faint: #969696;
    --scrollbar: #6e6e6e; --scrollbar-hover: #888888;
    --placeholder: #b0b0b0; --topbar-bg: var(--bg-base);
    --input-bg: #454545; --accent: #6366f1; --accent-light: #a5b4fc;
    --bubble-user: #6366f1; --bubble-ai: #404040;
}
:root[data-aichat-boot-theme="light"], :root[data-aichat-boot-skin="teacher"], body.light {
    color-scheme: light;
    --bg-base: #ffffff; --bg-sidebar: #f2f3f7; --bg-card: #ffffff;
    --bg-pill: #eef0f6; --bg-pill-hover: #e2e6ef;
    --border: #e0e3ec; --border-card: #dde0ea;
    --text-primary: #1a1a2e; --text-secondary: #4a4a5a;
    --text-muted: #777; --text-faint: #aaa;
    --scrollbar: #ccc; --scrollbar-hover: #aaa;
    --placeholder: #aaa; --topbar-bg: rgba(255,255,255,0.85);
    --input-bg: #f8f9fc; --accent-light: #4f46e5;
    --bubble-user: #6366f1; --bubble-ai: #eef0f6;
}

/* Keep the browser canvas in sync after the head hands off to the body. */
:root:has(> body.light, > body[data-skin="teacher"]) { color-scheme: light; }

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; font-size: 16px; background: var(--bg-base); color: var(--text-primary); height: 100vh; overflow: hidden; transition: background 0.3s, color 0.3s; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%,100% { opacity: 0.2; } 50% { opacity: 1; } }
.fade-in { animation: fadeIn 0.3s ease-out; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--scrollbar); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }

/* Visible while the initial packages, SDK and workbench are loading. */
#startup-progress {
    position: fixed; inset: 0 0 auto; height: 4px; z-index: 1000;
    overflow: hidden; pointer-events: none; background: var(--bg-pill);
}
#startup-progress::before {
    content: ''; display: block; width: 36%; height: 100%;
    background: var(--accent); animation: startup-sweep 1.4s ease-in-out infinite alternate;
}
@keyframes startup-sweep { to { transform: translateX(177.78%); } }
@media (prefers-reduced-motion: reduce) {
    #startup-progress::before { animation: none; margin-inline: auto; }
}

/* ========== Toast ========== */
/* Both desktop shells mount a fixed 34px title bar above the workbench. */
:root:has(> #keepwork-desktop-titlebar) { --desktop-top-inset: 34px; }
.toast-stack, .local-file-connection-alert {
    top: calc(16px + var(--desktop-top-inset, 0px) + env(safe-area-inset-top, 0px));
}
.toast-stack {
    position: fixed;
    right: max(16px, env(safe-area-inset-right, 0px));
    left: max(16px, env(safe-area-inset-left, 0px));
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    margin-left: auto;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    overflow-y: auto;
    pointer-events: none;
    z-index: 100000;
}
.toast {
    flex: none;
    max-width: 100%;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    overflow-wrap: anywhere;
    pointer-events: auto;
}
@media (prefers-reduced-motion: no-preference) {
    .toast { animation: toastFadeIn 0.3s ease-out; }
}
@keyframes toastFadeIn { from { opacity: 0; } to { opacity: 1; } }
.toast-success { background: #065f46; color: #6ee7b7; border: 1px solid #10b981; }
.toast-error   { background: #7f1d1d; color: #fca5a5; border: 1px solid #ef4444; }
.toast-warning { background: #78350f; color: #fcd34d; border: 1px solid #f59e0b; }
.toast-info    { background: #1e1b4b; color: #a5b4fc; border: 1px solid #6366f1; }
.local-file-connection-alert { position:fixed; left:50%; transform:translateX(-50%); z-index:1100; box-sizing:border-box; width:min(560px, calc(100vw - 24px)); padding:18px 20px; border:2px solid #f59e0b; border-radius:14px; background:#78350f; color:#fff7ed; box-shadow:0 8px 30px #0005; font-size:14px; line-height:1.6; }
.local-file-connection-alert strong { display:block; padding-right:32px; font-size:18px; }
.local-file-connection-alert p { margin:8px 0 12px; }
.local-file-connection-alert button { padding:6px 14px; margin-right:10px; border:1px solid #fcd34d; border-radius:8px; background:#451a03; color:#fff7ed; cursor:pointer; font:inherit; }
.local-file-connection-alert button:disabled { opacity:.6; cursor:wait; }
body:has(#mcpManageModal:not(.hidden)) .local-file-connection-alert { display:none; }

/* ========== Mobile ========== */
.mobile-hamburger { display: none; background: none; border: none; color: var(--text-primary); cursor: pointer; padding: 4px; border-radius: 6px; }
.mobile-overlay { display: none; position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,0.5); }
.mobile-overlay.open { display: block; }

@media (max-width: 768px) {
    /* Sidebar drawer rules live in shell.css (must follow `.sidebar { position: relative }`). */
    .mobile-hamburger { display: flex; }
    .composer-mobile-label { display: none; }
    .gallery-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .chat-msg-bubble { max-width: 80%; }
    .prompt-modal-body { grid-template-columns: 1fr; grid-template-rows: 220px 1fr; }
    .prompt-list-panel { border-right: none; border-bottom: 1px solid var(--border); }
    .prompt-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .prompt-editor-actions { justify-content: stretch; }
    .prompt-editor-actions button { flex: 1; }
}

.local-file-connection-alert a { color:#fff7ed; text-decoration:underline; display:inline-block; margin-right:16px; }
.local-file-connection-alert .local-file-alert-close { position:absolute; top:8px; right:8px; margin:0; padding:2px 10px; font-size:22px; }
