@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --sb-bg: #bec4d4;
  --sb-surface: #ffffff;
  --sb-surface-hover: #f5f6f8;
  --sb-border: #e8eaee;
  --sb-border-light: #f0f2f5;
  --sb-text: #1a1a2e;
  --sb-text-secondary: #374151;
  --sb-text-muted: #9ca3af;
  --sb-text-tertiary: #6b7280;
  --sb-accent: #6c5ce7;
  --sb-accent-light: #a29bfe;
  --sb-accent-bg: #ede9fe;
  --sb-green: #059669;
  --sb-green-light: #6ee7b7;
  --sb-green-bg: #d1fae5;
  --sb-red: #e17055;
  --sb-red-bg: #fff5f0;
  --sb-yellow: #f0b429;
  --sb-yellow-bg: #fef3c7;
  --sb-blue: #2563eb;
  --sb-blue-bg: #dbeafe;
  --sb-orange: #c2410c;
  --sb-orange-bg: #ffedd5;
  --sb-sidebar-w: 56px;
  --sb-topbar-h: 48px;
  --sb-left-panel-w: 220px;
  --sb-radius: 10px;
  --sb-radius-sm: 6px;
  --sb-radius-window: 14px;
  --sb-shadow: 0 1px 3px rgba(0,0,0,.07), 0 3px 10px rgba(0,0,0,.04);
  --sb-shadow-hover: 0 2px 8px rgba(0,0,0,.12), 0 6px 20px rgba(0,0,0,.07);
  --sb-shadow-window: 0 2px 8px rgba(0,0,0,.10), 0 8px 24px rgba(0,0,0,.14), 0 24px 64px rgba(0,0,0,.16), 0 1px 0 rgba(255,255,255,.7) inset;
  --sb-content-bg: #eef0f5;
  --sb-window-gap: 12px;
  --sb-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --sb-font-mono: 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

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

body {
  font-family: var(--sb-font);
  background: var(--sb-bg);
  color: var(--sb-text);
  overflow: hidden;
  height: 100vh;
  display: flex;
  align-items: stretch;
  padding: var(--sb-window-gap);
  gap: var(--sb-window-gap);
  line-height: 1.5;
}

/* ── Sidebar ── */
.sb-sidebar {
  width: var(--sb-sidebar-w);
  background: transparent;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 4px;
  flex-shrink: 0;
  z-index: 50;
  transition: width .2s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.sb-sidebar.expanded { width: 190px; }
.sb-sidebar-logo {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform .15s;
}
.sb-sidebar-logo:hover { transform: scale(1.08); }
.sb-sidebar-logo:active { transform: scale(.95); }
.sb-sidebar-logo img {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: block;
}
.sb-sidebar-btn {
  position: relative;
  width: 38px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center;
  justify-content: center;
  color: #6b7280;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  flex-shrink: 0;
  /* visible so the badge can overhang the corner; the label clips itself */
  overflow: visible;
}
/* Unread counter, chat-app style: overhangs the icon's top-right corner when
   the sidebar is collapsed, moves to the end of the row when it is expanded. */
.sb-sidebar-badge {
  position: absolute;
  top: -1px; right: -1px;
  min-width: 14px; height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  background: var(--sb-orange);
  color: #fff;
  font-size: 9px; font-weight: 600;
  line-height: 14px; text-align: center;
  letter-spacing: -.01em;
  box-shadow: 0 0 0 2px var(--sb-bg);
  pointer-events: none;
  animation: sb-badge-in .18s cubic-bezier(.34,1.56,.64,1);
}
.sb-sidebar.expanded .sb-sidebar-badge {
  top: 50%; right: 10px;
  transform: translateY(-50%);
  box-shadow: none;
  animation: none;
}
@keyframes sb-badge-in {
  from { transform: scale(.4); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}
.sb-sidebar-btn:hover { background: rgba(0,0,0,.07); color: #374151; }
.sb-sidebar-btn.active { background: var(--sb-accent-bg); color: var(--sb-accent); }
.sb-sidebar-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.sb-sidebar-btn-label {
  font-size: 13px; font-weight: 500; color: inherit;
  white-space: nowrap;
  width: 0; opacity: 0;
  overflow: hidden;
  transition: width .2s, opacity .15s;
  pointer-events: none;
}
.sb-sidebar.expanded .sb-sidebar-btn {
  width: 100%;
  justify-content: flex-start;
  padding: 0 14px;
  margin: 0 0;
}
.sb-sidebar.expanded .sb-sidebar-btn-label {
  width: auto; opacity: 1;
  margin-left: 12px;
  pointer-events: auto;
}
/* Health dot on "Settings" (docs/adr/0018-structured-logs-and-health-in-ui.md,
   moved here from "Журнал") — same corner as
   .sb-sidebar-badge above, but a plain dot (no count) and its own link
   target: the rest of the button still opens /settings, only this dot opens
   /logs?level=error. Only rendered while GET /api/health reports `alert`. */
.sb-sidebar-dot {
  position: absolute;
  top: 3px; right: 3px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--sb-red);
  box-shadow: 0 0 0 2px var(--sb-bg);
  cursor: pointer;
}
.sb-sidebar.expanded .sb-sidebar-dot { top: 8px; right: 8px; }

.sb-sidebar-spacer { flex: 1; }
.sb-sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: #d1d5db;
  display: flex; align-items: center; justify-content: center;
  color: #374151; font-size: 11px; font-weight: 600;
  flex-shrink: 0;
}

/* ── Left panel ── */
.sb-left-panel {
  width: var(--sb-left-panel-w);
  background: transparent;
  border-right: 1px solid var(--sb-border);
  padding: 20px 16px;
  overflow-y: auto;
  flex-shrink: 0;
  z-index: 5;
}
.sb-left-panel h2 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.sb-panel-section { margin-bottom: 18px; }
.sb-panel-title {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--sb-text-muted); margin-bottom: 8px;
}
.sb-panel-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: var(--sb-radius-sm);
  font-size: 12px; color: var(--sb-text-secondary);
  cursor: pointer; transition: background .15s;
  text-decoration: none;
}
.sb-panel-item:hover { background: var(--sb-surface-hover); }
.sb-panel-item.active { background: var(--sb-accent-bg); color: var(--sb-accent); font-weight: 500; }
.sb-panel-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.sb-panel-divider { height: 1px; background: var(--sb-border-light); margin: 12px 0; }

/* ── Main area — floating window ── */
.sb-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--sb-surface);
  border-radius: var(--sb-radius-window);
  box-shadow: var(--sb-shadow-window);
}

/* ── Top bar ── */
.sb-topbar {
  height: var(--sb-topbar-h);
  background: transparent;
  border-bottom: 1px solid var(--sb-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  border-radius: var(--sb-radius-window) var(--sb-radius-window) 0 0;
}
.sb-breadcrumb { font-size: 13px; color: var(--sb-text-muted); }
.sb-breadcrumb strong { color: var(--sb-text); font-weight: 600; }
/* Ссылка на параллельную версию той же страницы — пока две версии живут рядом
   и сравниваются в работе. Место в общем chrome, а не в странице: ссылка
   парная, и два экземпляра в двух <style> разъехались бы первым же правкой. */
.sb-version-link {
  margin-left: 10px; font-size: 11px; color: var(--sb-text-tertiary);
  text-decoration: none; border-bottom: 1px dashed currentColor;
}
.sb-version-link:hover { color: var(--sb-accent); }
.sb-topbar-actions { display: flex; gap: 8px; }

/* ── Buttons ── */
.sb-btn {
  padding: 6px 14px; border-radius: 7px;
  font-size: 12px; font-weight: 500;
  cursor: pointer; font-family: var(--sb-font);
  transition: all .15s;
  display: inline-flex; align-items: center; gap: 5px;
  text-decoration: none;
}
.sb-btn-outline {
  border: 1px solid var(--sb-border);
  background: var(--sb-surface); color: var(--sb-text-secondary);
}
.sb-btn-outline:hover { background: var(--sb-surface-hover); border-color: #d1d5db; }
.sb-btn-primary {
  border: none;
  background: var(--sb-accent); color: #fff;
}
.sb-btn-primary:hover { background: #5b4cdb; }
.sb-btn-primary:disabled { opacity: .5; cursor: default; }

/* ── Content area ── */
.sb-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px 48px;
  background: var(--sb-content-bg);
}

/* ── Page container ──
   Every document page wraps its content in .sb-page: one padding (above), one
   of three widths, always flush left. The width lives here and not on
   .sb-content because that element carries the page background — capping it
   would cut the background short.

   Pages that lay out their own columns (projects, person, triage) zero the
   padding and skip the container entirely; they are full-bleed by design. */
.sb-page          { max-width: 1100px; }
.sb-page--wide    { max-width: 1320px; }
.sb-page--narrow  { max-width: 720px; }

/* ── Cards ── */
.sb-card {
  background: var(--sb-surface);
  border-radius: var(--sb-radius);
  box-shadow: var(--sb-shadow);
  border: 1.5px solid var(--sb-border);
  transition: box-shadow .2s, border-color .2s;
}
.sb-card:hover {
  box-shadow: var(--sb-shadow-hover);
  border-color: #c4b5fd;
}

/* ── Tags ── */
.sb-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 4px;
}
.sb-tag-src  { background: var(--sb-accent-bg); color: var(--sb-accent); }
.sb-tag-skl  { background: var(--sb-green-bg); color: var(--sb-green); }
.sb-tag-agt  { background: var(--sb-orange-bg); color: var(--sb-orange); }
.sb-tag-str  { background: var(--sb-blue-bg); color: var(--sb-blue); }
.sb-tag-wk   { background: var(--sb-yellow-bg); color: #92400e; }

/* ── Stat cards (dashboard) ── */
.sb-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.sb-stat-card {
  background: var(--sb-surface); border-radius: var(--sb-radius);
  padding: 20px; border: 1px solid var(--sb-border);
}
.sb-stat-label { font-size: 12px; color: var(--sb-text-muted); margin-bottom: 4px; }
.sb-stat-value { font-size: 28px; font-weight: 700; color: var(--sb-text); }
.sb-stat-sub { font-size: 12px; color: var(--sb-text-tertiary); margin-top: 4px; }

/* ── Link cards (dashboard) ── */
.sb-link-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.sb-link-card {
  background: var(--sb-surface); border-radius: var(--sb-radius);
  padding: 20px; border: 1px solid var(--sb-border);
  text-decoration: none; color: var(--sb-text);
  transition: all .2s; cursor: pointer;
}
.sb-link-card:hover { border-color: var(--sb-accent-light); box-shadow: var(--sb-shadow-hover); }
.sb-link-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.sb-link-card p { font-size: 13px; color: var(--sb-text-muted); }

/* ── Progress bar ── */
.sb-progress { height: 6px; background: var(--sb-border-light); border-radius: 3px; overflow: hidden; }
.sb-progress-fill { height: 100%; border-radius: 3px; transition: width .3s; }

/* ── Spinner — inline "checking…" state on a button (settings' "Проверить",
   inbox-process's "Проверить сейчас") ── */
.sb-spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid rgba(0,0,0,.15); border-top-color: currentColor;
  border-radius: 50%; animation: sb-spin .7s linear infinite;
  flex-shrink: 0; vertical-align: -1px;
}
@keyframes sb-spin { to { transform: rotate(360deg); } }

/* Wrapped monospace block — raw stderr, an LLM response, anything that must
   not force horizontal scroll (settings' Claude check, server/pages/logs.html's
   expanded event detail). */
.sb-pre {
  font-family: var(--sb-font-mono); font-size: 11.5px; line-height: 1.5;
  background: var(--sb-bg); color: var(--sb-text-secondary);
  padding: 8px 10px; border-radius: 6px;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
}

/* ── Utility ── */
.sb-mono { font-family: var(--sb-font-mono); }
.sb-muted { color: var(--sb-text-muted); }
.sb-hidden { display: none !important; }

/* ── Mobile template ──
   One breakpoint for the whole site. Below it the floating window fills the
   screen and the sidebar turns into a bottom tab bar — the same nav items, the
   same badges, just laid along the thumb instead of the left edge. Items that
   are desktop chrome (logo toggle, labels, avatar, log out) drop out; Settings
   stays, it carries the health dot. Pages opt into the notch area with
   `viewport-fit=cover`; without it the safe-area insets are simply 0. */
@media (max-width: 640px) {
  body {
    height: 100dvh;
    flex-direction: column;
    padding: 0;
    gap: 0;
  }
  .sb-main {
    border-radius: 0;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
  }
  .sb-topbar { border-radius: 0; padding: 0 16px; }
  .sb-content { padding: 16px 16px 32px; }

  .sb-sidebar,
  .sb-sidebar.expanded {
    order: 2;
    width: 100%;
    flex-direction: row;
    justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    gap: 0;
    background: var(--sb-surface);
    border-top: 1px solid var(--sb-border);
    overflow: visible;
  }
  .sb-sidebar-logo,
  .sb-sidebar-spacer,
  .sb-sidebar-avatar,
  .sb-sidebar-btn[title="Log out"],
  .sb-sidebar-btn-label { display: none; }
  .sb-sidebar-btn,
  .sb-sidebar.expanded .sb-sidebar-btn {
    width: 44px; height: 40px;
    padding: 0; margin: 0;
    justify-content: center;
  }
  .sb-sidebar-btn svg { width: 22px; height: 22px; }
  .sb-sidebar.expanded .sb-sidebar-badge {
    top: -1px; right: -1px; transform: none;
    box-shadow: 0 0 0 2px var(--sb-surface);
  }
  .sb-sidebar-badge { box-shadow: 0 0 0 2px var(--sb-surface); }
  .sb-sidebar-dot,
  .sb-sidebar.expanded .sb-sidebar-dot { top: 4px; right: 6px; box-shadow: 0 0 0 2px var(--sb-surface); }
}
