:root {
  --bg: #0f1419;
  --bg-elev: #171d26;
  --bg-elev-2: #1f2733;
  --border: #2a3340;
  --text: #e6edf3;
  --text-dim: #8b97a6;
  --accent: #5b8cff;
  --accent-press: #4778ee;
  --up: #3fb950;
  --down: #f85149;
  --neutral: #6e7681;
  --radius: 10px;
  --topbar-h: 52px;
  --sidebar-w: 184px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ── Top bar ───────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  width: 24px;
  height: 24px;
}

.brand-name {
  font-weight: 650;
  letter-spacing: 0.2px;
  font-size: 15px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-email {
  color: var(--text-dim);
  font-size: 12.5px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  color: var(--text);
  background: var(--bg-elev-2);
  transition: background 0.12s ease, transform 0.06s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-press);
}

.btn-icon {
  font-size: 15px;
  line-height: 1;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.icon-btn:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

/* ── Body / sidebar ────────────────────────────────────── */
.body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
}

.search-wrap {
  position: relative;
  margin: 8px 2px 10px;
}

.search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.search-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover {
  background: var(--bg-elev);
}

.search-result-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-meta {
  color: var(--text-dim);
  font-size: 11px;
}

.search-empty {
  padding: 10px;
  color: var(--text-dim);
  font-size: 12px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 auto;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}

/* Green count badge (open items / due-today). Sits inline next to the label;
   in icon-only (mobile) mode it overlaps the top-right of the icon. */
.nav-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--up);
  color: #04140a;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.nav-item:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--bg-elev-2);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}

.nav-icon {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  flex: 0 0 20px;
}

.nav-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
  background: var(--neutral);
}

.status-dot[data-state="up"] {
  background: var(--up);
  box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.15);
}

.status-dot[data-state="down"] {
  background: var(--down);
  box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.15);
}

.status-dot[data-state="neutral"] {
  background: var(--neutral);
}

.sidebar-footer {
  padding: 8px 10px 2px;
}

.hint {
  color: var(--text-dim);
  font-size: 11px;
}

/* ── Frames host ───────────────────────────────────────── */
.frames-host {
  flex: 1 1 auto;
  position: relative;
  background: var(--bg);
  min-width: 0;
}

.tool-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
}

.placeholder.error {
  color: var(--down);
  padding: 24px;
  text-align: center;
}

/* ── Modal ─────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal.open {
  display: flex;
}

.modal-card {
  width: min(520px, 92vw);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.capture-text {
  width: 100%;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
}

.capture-text:focus {
  outline: none;
  border-color: var(--accent);
}

.capture-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1 1 0;
  font-size: 11.5px;
  color: var(--text-dim);
  text-transform: lowercase;
}

.field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 8px 9px;
  font-size: 13px;
  font-family: inherit;
}

.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  gap: 12px;
}

.capture-status {
  font-size: 12.5px;
  color: var(--text-dim);
}

/* ── ✦ Agent ───────────────────────────────────────────── */
.agent-launch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.18), rgba(91, 140, 255, 0.05));
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.agent-launch:hover {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.28), rgba(91, 140, 255, 0.08));
}

.agent-spark {
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
}

.agent-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  width: min(380px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: -16px 0 48px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 95;
}

.agent-drawer.open {
  transform: translateX(0);
}

.agent-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
}

.agent-title {
  font-weight: 650;
  font-size: 14px;
}

.agent-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.agent-msg {
  max-width: 86%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.agent-msg.assistant {
  align-self: flex-start;
  background: var(--bg-elev-2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.agent-msg.thinking {
  opacity: 0.6;
  font-style: italic;
}

.agent-form {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.agent-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.4;
}

.agent-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Mobile ────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root {
    --sidebar-w: 56px;
  }
  .nav-label,
  .btn-text,
  .agent-launch-label {
    display: none;
  }
  /* Header agent button collapses to the ✦ spark only (label hidden above). */
  .agent-launch {
    justify-content: center;
    padding: 7px 10px;
  }
  /* Agent chat opens as a TOP sheet (~upper ⅔) on phones — the app stays
     visible below, and width:100% (not 100vw) avoids the scrollbar-width
     overhang that made it look "over-justified" edge to edge. Its own header
     has the ✕ close. */
  .agent-drawer {
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    height: 62dvh;
    max-height: 62dvh;
    border-left: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0 0 14px 14px;
    transform: translateY(-100%);
  }
  .agent-drawer.open {
    transform: translateY(0);
  }
  .user-email {
    max-width: 90px;
  }
  /* Icon-only sidebar: float the count over the icon's top-right corner. */
  .nav-badge {
    position: absolute;
    top: 3px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 10px;
    padding: 0 4px;
  }
}
