/* ==========================================================================
   OS App Kit — shared "advanced app shell" design system for the coming-soon
   open-source-tool demos (os-*). Sidebar + topbar + themeable content area,
   reused across many tool pages via a per-page --os-accent + data attributes.

   Not related to demo-ui.css (the _shell-based business-prototype cohort's
   kit) — this is a separate, richer system for the developer-tool clones.

   Contract: the page sets --os-accent (and optionally --os-accent-ink) on
   .os-app, includes this file + os-app-kit.js, and marks up:
     .os-app > .os-sidebar (nav) + .os-main > .os-topbar + .os-view[data-view]
   Views are toggled by os-app-kit.js via [data-nav] click -> data-view match.
   ========================================================================== */

.os-app {
  --os-accent: #6366f1;
  --os-accent-ink: #ffffff;
  --os-bg: #0b0d12;
  --os-sidebar: #0f1117;
  --os-panel: #12141b;
  --os-panel-2: #171a22;
  --os-line: #232733;
  --os-ink: #e7e9ee;
  --os-muted: #8a8fa3;
  --os-faint: #565b70;
  --os-radius: 10px;
  --os-radius-lg: 14px;
  --os-shadow: 0 20px 50px -20px rgba(0, 0, 0, .55);
  --os-font: 'Inter', ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --os-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  position: fixed; inset: 0;
  display: flex;
  background: var(--os-bg);
  color: var(--os-ink);
  font: 400 13.5px/1.5 var(--os-font);
  -webkit-font-smoothing: antialiased;
}

.os-app * { box-sizing: border-box; }
.os-app button, .os-app input, .os-app select, .os-app textarea {
  -webkit-appearance: none; appearance: none; font-family: inherit;
}
.os-app ::selection { background: color-mix(in srgb, var(--os-accent) 35%, transparent); }

/* ── Sidebar ─────────────────────────────────────────────────────────── */

.os-sidebar {
  width: 230px; flex: none;
  display: flex; flex-direction: column;
  background: var(--os-sidebar);
  border-right: 1px solid var(--os-line);
  overflow-y: auto;
}

.os-brand {
  display: flex; align-items: center; gap: .55rem;
  padding: .95rem 1rem; border-bottom: 1px solid var(--os-line);
  font-weight: 800; font-size: .95rem; letter-spacing: -.01em;
}
.os-brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: var(--os-accent); color: var(--os-accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 800;
}
.os-brand small { display: block; font-size: .68rem; font-weight: 600; color: var(--os-muted); }

.os-nav { padding: .6rem; display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.os-nav-label {
  padding: .8rem .55rem .3rem; font-size: .66rem; font-weight: 800;
  letter-spacing: .07em; text-transform: uppercase; color: var(--os-faint);
}
.os-nav a, .os-nav button {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .6rem; border-radius: 8px;
  color: var(--os-muted); text-decoration: none; font-size: .82rem; font-weight: 600;
  background: none; border: none; cursor: pointer; width: 100%; text-align: left;
  font-family: inherit;
}
.os-nav a:hover, .os-nav button:hover { background: var(--os-panel-2); color: var(--os-ink); }
.os-nav a.is-active, .os-nav button.is-active {
  background: color-mix(in srgb, var(--os-accent) 16%, transparent);
  color: var(--os-ink);
}
.os-nav a.is-active .os-nav-ic, .os-nav button.is-active .os-nav-ic { color: var(--os-accent); }
.os-nav-ic { width: 16px; text-align: center; flex: none; font-size: .95rem; }
.os-nav-badge {
  margin-left: auto; font-size: .65rem; font-weight: 800; padding: .1rem .4rem;
  border-radius: 999px; background: var(--os-panel-2); color: var(--os-muted);
}

.os-sidebar-foot {
  padding: .75rem 1rem; border-top: 1px solid var(--os-line);
  display: flex; align-items: center; gap: .5rem;
}
.os-back {
  display: inline-flex; align-items: center; gap: .4rem;
  color: var(--os-muted); text-decoration: none; font-size: .76rem; font-weight: 700;
}
.os-back:hover { color: var(--os-ink); }

/* ── Main / topbar ───────────────────────────────────────────────────── */

.os-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.os-topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem .9rem; border-bottom: 1px solid var(--os-line);
  background: var(--os-panel);
}
.os-topbar h1 { font-size: .92rem; font-weight: 800; margin: 0; }
.os-topbar-sub { font-size: .74rem; color: var(--os-muted); font-weight: 600; }
.os-search {
  display: flex; align-items: center; gap: .45rem;
  background: var(--os-panel-2); border: 1px solid var(--os-line); border-radius: 8px;
  padding: .4rem .6rem; color: var(--os-faint); font-size: .78rem; font-weight: 600;
  min-width: 200px; cursor: pointer;
}
.os-kbd {
  margin-left: auto; font-family: var(--os-mono); font-size: .68rem;
  background: var(--os-panel); border: 1px solid var(--os-line); border-radius: 4px;
  padding: .05rem .32rem; color: var(--os-faint);
}
.os-topbar-spacer { flex: 1; }
.os-pill {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .68rem; font-weight: 800; letter-spacing: .02em;
  padding: .28rem .6rem; border-radius: 999px;
  background: color-mix(in srgb, var(--os-accent) 16%, transparent);
  color: var(--os-accent);
}
.os-pill::before { content: ""; width: .4rem; height: .4rem; border-radius: 50%; background: currentColor; }
.os-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--os-panel-2); border: 1px solid var(--os-line);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 800; color: var(--os-muted);
}

/* ── Views / content ─────────────────────────────────────────────────── */

.os-body { flex: 1; min-height: 0; overflow-y: auto; padding: 1.1rem 1.25rem 3rem; }
.os-view { display: none; animation: osFadeIn .25s ease both; }
.os-view.is-active { display: block; }
@keyframes osFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.os-hero { margin-bottom: 1.1rem; }
.os-hero h2 { margin: 0 0 .2rem; font-size: 1.15rem; font-weight: 800; letter-spacing: -.01em; }
.os-hero p { margin: 0; color: var(--os-muted); font-size: .82rem; max-width: 46rem; }

/* Stat grid */
.os-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: 1.1rem; }
.os-stat {
  background: var(--os-panel); border: 1px solid var(--os-line); border-radius: var(--os-radius-lg);
  padding: .85rem .95rem;
}
.os-stat-label { font-size: .68rem; font-weight: 700; color: var(--os-muted); text-transform: uppercase; letter-spacing: .04em; }
.os-stat-value { font-size: 1.4rem; font-weight: 800; margin-top: .25rem; letter-spacing: -.02em; }
.os-stat-delta { font-size: .72rem; font-weight: 700; margin-top: .2rem; }
.os-stat-delta.up { color: #34d399; }
.os-stat-delta.down { color: #f87171; }

/* Card / panel */
.os-card {
  background: var(--os-panel); border: 1px solid var(--os-line); border-radius: var(--os-radius-lg);
  overflow: hidden; margin-bottom: 1rem;
}
.os-card-hd {
  display: flex; align-items: center; gap: .6rem;
  padding: .8rem .95rem; border-bottom: 1px solid var(--os-line);
}
.os-card-hd h3 { margin: 0; font-size: .86rem; font-weight: 800; }
.os-card-body { padding: .95rem; }
.os-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem; padding: .95rem; }

/* Buttons */
.os-btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  padding: .42rem .8rem; border-radius: 8px; font: 700 .78rem/1 var(--os-font);
  border: 1px solid var(--os-line); background: var(--os-panel-2); color: var(--os-ink);
  cursor: pointer; text-decoration: none;
}
.os-btn:hover { border-color: var(--os-faint); }
.os-btn.primary { background: var(--os-accent); color: var(--os-accent-ink); border-color: transparent; }
.os-btn.primary:hover { filter: brightness(1.08); }
.os-btn.ghost { background: transparent; border-color: transparent; color: var(--os-muted); }
.os-btn.ghost:hover { color: var(--os-ink); background: var(--os-panel-2); }
.os-btn.sm { padding: .3rem .6rem; font-size: .72rem; }
.os-btn.danger { color: #f87171; }

/* Table */
.os-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.os-table th {
  text-align: left; padding: .55rem .8rem; font-size: .68rem; font-weight: 800;
  color: var(--os-muted); text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--os-line);
}
.os-table td { padding: .6rem .8rem; border-bottom: 1px solid var(--os-line); }
.os-table tr:last-child td { border-bottom: none; }
.os-table tr:hover td { background: var(--os-panel-2); }

/* Badges / tags */
.os-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .68rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px;
  background: var(--os-panel-2); color: var(--os-muted); border: 1px solid var(--os-line);
}
.os-badge.ok { color: #34d399; border-color: color-mix(in srgb, #34d399 40%, var(--os-line)); }
.os-badge.warn { color: #fbbf24; border-color: color-mix(in srgb, #fbbf24 40%, var(--os-line)); }
.os-badge.err { color: #f87171; border-color: color-mix(in srgb, #f87171 40%, var(--os-line)); }
.os-badge.accent { color: var(--os-accent); border-color: color-mix(in srgb, var(--os-accent) 40%, var(--os-line)); }

/* Tabs */
.os-tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--os-line); padding: 0 .2rem; }
.os-tab {
  padding: .55rem .75rem; font-size: .78rem; font-weight: 700; color: var(--os-muted);
  border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent;
  font-family: inherit; margin-bottom: -1px;
}
.os-tab:hover { color: var(--os-ink); }
.os-tab.is-active { color: var(--os-ink); border-color: var(--os-accent); }

/* Inputs / forms */
.os-input, .os-select, .os-textarea {
  -webkit-appearance: none; appearance: none;
  width: 100%; padding: .5rem .65rem; border-radius: 8px;
  border: 1px solid var(--os-line); background: var(--os-panel-2); color: var(--os-ink);
  font: 500 .8rem/1.3 var(--os-font);
}
.os-input::placeholder, .os-textarea::placeholder { color: var(--os-faint); opacity: 1; }
.os-input:focus, .os-select:focus, .os-textarea:focus { outline: 2px solid color-mix(in srgb, var(--os-accent) 45%, transparent); }
.os-field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; }
.os-field label { font-size: .72rem; font-weight: 700; color: var(--os-muted); }

/* Empty state */
.os-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 2.5rem 1rem; color: var(--os-muted);
}
.os-empty-ic { font-size: 1.8rem; margin-bottom: .5rem; opacity: .7; }
.os-empty h4 { margin: 0 0 .25rem; color: var(--os-ink); font-size: .88rem; }
.os-empty p { margin: 0; font-size: .78rem; max-width: 22rem; }

/* Modal */
.os-modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 7, 10, .6); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center; z-index: 500; padding: 1rem;
}
.os-modal-backdrop.is-open { display: flex; }
.os-modal {
  width: min(520px, 100%); background: var(--os-panel); border: 1px solid var(--os-line);
  border-radius: var(--os-radius-lg); box-shadow: var(--os-shadow);
  animation: osPopIn .18s cubic-bezier(.22,1,.36,1) both;
}
@keyframes osPopIn { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: none; } }
.os-modal-hd { display: flex; align-items: center; gap: .6rem; padding: .9rem 1rem; border-bottom: 1px solid var(--os-line); }
.os-modal-hd h3 { margin: 0; font-size: .88rem; font-weight: 800; }
.os-modal-body { padding: 1rem; max-height: 60vh; overflow-y: auto; }
.os-modal-ft { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1rem; border-top: 1px solid var(--os-line); }

/* Command palette */
.os-cmdk { width: min(560px, 100%); }
.os-cmdk-input {
  width: 100%; padding: .9rem 1rem; border: none; border-bottom: 1px solid var(--os-line);
  background: transparent; color: var(--os-ink); font: 600 .92rem/1 var(--os-font); outline: none;
}
.os-cmdk-list { max-height: 50vh; overflow-y: auto; padding: .4rem; }
.os-cmdk-item {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem; border-radius: 8px;
  font-size: .82rem; font-weight: 600; cursor: pointer; color: var(--os-ink);
}
.os-cmdk-item:hover, .os-cmdk-item.is-sel { background: var(--os-panel-2); }
.os-cmdk-item .os-nav-ic { color: var(--os-muted); }

/* Toast */
.os-toast-host { position: fixed; right: 1rem; bottom: 1rem; z-index: 600; display: flex; flex-direction: column; gap: .5rem; }
.os-toast {
  background: var(--os-panel); border: 1px solid var(--os-line); border-radius: 10px;
  padding: .65rem .9rem; font-size: .78rem; font-weight: 700; box-shadow: var(--os-shadow);
  display: flex; align-items: center; gap: .5rem;
  animation: osToastIn .22s cubic-bezier(.22,1,.36,1) both;
}
@keyframes osToastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.os-toast.ok::before { content: "✓"; color: #34d399; font-weight: 800; }
.os-toast.err::before { content: "✕"; color: #f87171; font-weight: 800; }

/* Chat / playground (Ollama-style) */
.os-chat { display: flex; flex-direction: column; gap: .8rem; max-width: 46rem; }
.os-msg { display: flex; gap: .6rem; }
.os-msg-av {
  width: 26px; height: 26px; border-radius: 7px; flex: none; display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 800; background: var(--os-panel-2); color: var(--os-muted);
}
.os-msg.user .os-msg-av { background: var(--os-accent); color: var(--os-accent-ink); }
.os-msg-bubble {
  background: var(--os-panel); border: 1px solid var(--os-line); border-radius: 10px;
  padding: .6rem .8rem; font-size: .82rem; line-height: 1.55; max-width: 40rem;
}
.os-msg.user .os-msg-bubble { background: color-mix(in srgb, var(--os-accent) 12%, var(--os-panel)); }
.os-typing { display: inline-flex; gap: .2rem; }
.os-typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--os-muted); animation: osTyping 1s infinite ease-in-out; }
.os-typing i:nth-child(2) { animation-delay: .15s; }
.os-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes osTyping { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

/* Canvas surface (Excalidraw-style) */
.os-canvas-wrap { position: relative; height: calc(100vh - 108px); border-radius: var(--os-radius-lg); overflow: hidden; border: 1px solid var(--os-line); background: #f8f9fb; }
.os-canvas-wrap canvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.os-canvas-toolbar {
  position: absolute; top: .8rem; left: 50%; transform: translateX(-50%);
  display: flex; gap: .25rem; background: var(--os-panel); border: 1px solid var(--os-line);
  border-radius: 12px; padding: .3rem; box-shadow: var(--os-shadow); z-index: 5;
}
.os-canvas-tool {
  width: 34px; height: 34px; border-radius: 8px; border: none; background: none; cursor: pointer;
  color: var(--os-ink); display: flex; align-items: center; justify-content: center; font-size: .95rem;
}
.os-canvas-tool:hover { background: var(--os-panel-2); }
.os-canvas-tool.is-active { background: color-mix(in srgb, var(--os-accent) 22%, transparent); color: var(--os-accent); }

/* Sidebar mobile toggle (mobile-notice.js already nudges users to desktop; this
   just prevents unusable horizontal scroll if they proceed anyway). */
@media (max-width: 860px) {
  .os-sidebar { width: 72px; }
  .os-brand span:not(.os-brand-mark), .os-nav-label, .os-nav a span:not(.os-nav-ic), .os-nav button span:not(.os-nav-ic) { display: none; }
  .os-nav a, .os-nav button { justify-content: center; }
  .os-search, .os-topbar-sub { display: none; }
  .os-topbar { flex-wrap: wrap; }
}
