:root {
  --sara-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sara-font-mono: "Source Code Pro", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  
  --sara-bg: #fcfcfb;
  --sara-surface: #ffffff;
  --sara-panel: #ffffff;
  --sara-subtle: #f4f4f0;
  --sara-border: #e6e6e0;
  --sara-border-strong: #d0d0c8;
  --sara-text: #17191d;
  --sara-text-muted: #66686d;
  --sara-text-subtle: #8e9096;
  
  --sara-accent: #1e40af;
  --sara-accent-hover: #1d4ed8;
  --sara-accent-subtle: #eff6ff;
  
  --sara-rail-width: 17.5rem;
  --sara-inspector-width: 30rem;
}

.dark {
  --sara-bg: #0c0e12;
  --sara-surface: #14161d;
  --sara-panel: #181b24;
  --sara-subtle: #1f232e;
  --sara-border: #292e3d;
  --sara-border-strong: #3b4257;
  --sara-text: #f0f2f7;
  --sara-text-muted: #9ba1b0;
  --sara-text-subtle: #6d7485;
  
  --sara-accent: #3b82f6;
  --sara-accent-hover: #60a5fa;
  --sara-accent-subtle: #1e293b;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; height: 100%; margin: 0; padding: 0; }
body {
  color: var(--sara-text);
  background: var(--sara-bg);
  font-family: var(--sara-font-sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--sara-accent);
  outline-offset: 2px;
}

mark { background-color: rgba(254, 240, 138, 0.9); color: #1e293b; font-weight: 600; border-radius: 2px; padding: 0 2px; }
.dark mark { background-color: rgba(133, 77, 14, 0.7); color: #fef08a; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Workspace 3-Zone Layout */
.sara-workspace {
  display: flex;
  height: calc(100dvh - 58px);
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* 1. Left Session Rail */
.session-rail {
  width: var(--sara-rail-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sara-surface);
  border-right: 1px solid var(--sara-border);
  z-index: 10;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  color: var(--sara-text-muted);
  transition: all 0.15s ease;
  user-select: none;
}

.session-item:hover {
  background: var(--sara-subtle);
  color: var(--sara-text);
}

.session-item.is-active {
  background: var(--sara-accent-subtle);
  color: var(--sara-accent);
  font-weight: 600;
}

.session-item .session-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item .session-delete {
  opacity: 0;
  transition: opacity 0.15s ease;
  padding: 2px 6px;
  border-radius: 4px;
}

.session-item:hover .session-delete {
  opacity: 0.7;
}

.session-item .session-delete:hover {
  opacity: 1;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* 2. Center Agent Canvas */
.agent-canvas {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--sara-bg);
  position: relative;
  overflow: hidden;
}

.conversation-feed {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem 7rem 1rem;
  scroll-behavior: smooth;
}

@media (min-width: 640px) {
  .conversation-feed {
    padding: 2rem 2rem 8rem 2rem;
  }
}

.message-turn {
  max-width: 50rem;
  margin: 0 auto 1.5rem auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-bubble {
  align-self: flex-end;
  max-width: 85%;
  background: var(--sara-accent);
  color: #ffffff;
  padding: 0.85rem 1.15rem;
  border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.agent-bubble {
  align-self: flex-start;
  width: 100%;
  background: transparent;
  color: var(--sara-text);
  padding: 0.5rem 0;
  font-size: 0.9375rem;
  line-height: 1.6;
}

/* Prompt Dock */
.prompt-dock-container {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.75rem 1rem 1.25rem 1rem;
  background: linear-gradient(to top, var(--sara-bg) 75%, transparent);
  z-index: 20;
}

.prompt-dock {
  max-width: 50rem;
  margin: 0 auto;
  background: var(--sara-surface);
  border: 1px solid var(--sara-border-strong);
  border-radius: 1.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.prompt-dock:focus-within {
  border-color: var(--sara-accent);
  box-shadow: 0 4px 24px rgba(37, 99, 235, 0.12);
}

.prompt-textarea {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  resize: none;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--sara-text);
  max-height: 12rem;
  min-height: 2.75rem;
  padding: 0.25rem 0.5rem;
}

.prompt-textarea::placeholder {
  color: var(--sara-text-subtle);
}

/* 3. Right Context Inspector */
.context-inspector {
  width: var(--sara-inspector-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sara-surface);
  border-left: 1px solid var(--sara-border);
  z-index: 15;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), width 0.25s ease;
}

/* Chips & Citation Pills */
.celex-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  background: var(--sara-subtle);
  border: 1px solid var(--sara-border);
  font-family: var(--sara-font-mono);
  font-size: 0.75rem;
  color: var(--sara-accent);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.celex-pill:hover {
  background: var(--sara-accent-subtle);
  border-color: var(--sara-accent);
}

/* Responsive Drawers */
.workspace-backdrop {
  position: fixed;
  inset: 58px 0 0 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

@media (max-width: 1024px) {
  .session-rail {
    position: fixed;
    top: 58px;
    bottom: 0;
    left: 0;
    width: min(85vw, 20rem);
    transform: translateX(-105%);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 40;
  }
  .session-rail.is-drawer-open {
    transform: translateX(0);
  }
  
  .context-inspector {
    position: fixed;
    top: 58px;
    bottom: 0;
    right: 0;
    width: min(92vw, 32rem);
    transform: translateX(105%);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 40;
  }
  .context-inspector.is-drawer-open {
    transform: translateX(0);
  }
}

/* Mode tab compatibility */
.mode-tab {
  background: transparent;
  color: var(--sara-text-muted);
}
.mode-tab.is-active {
  background: var(--sara-subtle);
  color: var(--sara-text);
  font-weight: 600;
}
