/* Percival Agent UI — dark ops theme */
:root {
  --bg-base: #0d0f14;
  --bg-surface: #151820;
  --bg-elevated: #1c2030;
  --bg-input: #1e2235;
  --border: #2a2f45;

  --text-primary: #e2e8f0;
  --text-secondary: #8892a4;
  --text-muted: #4a5568;

  --accent: #6366f1;          /* indigo */
  --accent-hover: #818cf8;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  --orange: #fb923c;

  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --radius: 8px;
  --sidebar-w: 260px;
  --events-w: 280px;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Layout ─────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--events-w);
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.brand-icon { font-size: 20px; display: inline-block; vertical-align: middle; }
img.brand-icon { width: 24px; height: 24px; }
.message-avatar img { width: 24px; height: 24px; object-fit: contain; }

.btn-new-chat {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  width: 28px; height: 28px;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.btn-new-chat:hover { background: var(--accent-hover); }

.status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-dot.connected { background: var(--green); }
.status-dot.error { background: var(--red); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.convo-item {
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.convo-item.active { background: var(--bg-elevated); color: var(--text-primary); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.connected-servers { display: flex; flex-wrap: wrap; gap: 4px; }

.server-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.server-badge.online { border-color: var(--green); color: var(--green); }

/* ── Chat Area ─────────────────────────────────────────── */
.chat-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome-message {
  max-width: 480px;
  margin: auto;
  text-align: center;
  color: var(--text-secondary);
}
.welcome-message h2 { font-size: 24px; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.welcome-message .hint { margin-top: 12px; font-size: 13px; }

/* Message bubbles */
.message { display: flex; gap: 12px; max-width: 800px; }
.message.user { flex-direction: row-reverse; margin-left: auto; }

.message-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.message.user .message-avatar { background: var(--accent); }

.message-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text-primary);
  line-height: 1.7;
  max-width: 100%;
  overflow-wrap: break-word;
}
.message.user .message-content { background: var(--accent); border-color: var(--accent); }

.message-content code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(0,0,0,0.3);
  padding: 1px 4px;
  border-radius: 3px;
}

.message-content pre {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.message-content pre code { background: none; padding: 0; }

/* Typing indicator */
.message.typing .message-content {
  color: var(--text-muted);
  padding: 12px 14px;
  display: inline-flex;
  align-items: center;
}
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 10px;
}
.typing-dots span {
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--accent-hover);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Tool Activity ─────────────────────────────────────── */
.tool-activity {
  padding: 8px 24px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}
.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  margin-right: 6px;
}
.tool-pill.running { border-color: var(--yellow); color: var(--yellow); }
.tool-pill.done { border-color: var(--green); color: var(--green); }
.tool-pill.denied { border-color: var(--red); color: var(--red); }

/* ── Approval Dialog ─────────────────────────────────────── */
.approval-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.approval-overlay[hidden] { display: none !important; }
.approval-dialog {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 90%;
}
.approval-dialog h3 { font-size: 16px; margin-bottom: 12px; color: var(--yellow); }
.approval-tool { margin-bottom: 8px; color: var(--text-secondary); }
.approval-tool code { color: var(--accent-hover); }
.approval-input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  overflow-x: auto;
  margin-bottom: 16px;
  max-height: 200px;
  overflow-y: auto;
}
.approval-buttons { display: flex; gap: 10px; justify-content: flex-end; }

.approval-snapshot {
  background: var(--bg-base); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px;
  font-size: 12px; color: var(--text-secondary);
}
.approval-snapshot[hidden] { display: none !important; }
.approval-snapshot .snap-line { line-height: 1.6; }
.approval-snapshot .snap-ok { color: var(--green); }
.approval-snapshot .snap-skip { color: var(--yellow); }
.approval-snapshot code {
  font-family: var(--font-mono); font-size: 11px;
  background: rgba(0,0,0,0.25); padding: 1px 5px; border-radius: 3px; color: var(--text-primary);
}

.btn-approve {
  background: var(--green);
  color: #000;
  border: none;
  border-radius: var(--radius);
  padding: 8px 20px;
  font-weight: 600;
  cursor: pointer;
}
.btn-deny {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 8px 20px;
  font-weight: 600;
  cursor: pointer;
}

/* ── Input Area ─────────────────────────────────────────── */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px 24px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

#messageInput {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 14px;
  resize: none;
  max-height: 160px;
  line-height: 1.5;
  outline: none;
}
#messageInput:focus { border-color: var(--accent); }
#messageInput::placeholder { color: var(--text-muted); }

#sendBtn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  width: 40px; height: 40px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
#sendBtn:disabled { opacity: 0.4; cursor: not-allowed; }
#sendBtn:not(:disabled):hover { background: var(--accent-hover); }

/* ── Event Panel ─────────────────────────────────────────── */
.event-panel {
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.event-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.btn-toggle-events {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
}

.event-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.event-item {
  padding: 8px 10px;
  border-radius: var(--radius);
  margin-bottom: 4px;
  border-left: 3px solid var(--border);
  font-size: 12px;
}
.event-item.critical { border-left-color: var(--red); background: rgba(248,113,113,0.05); }
.event-item.warning  { border-left-color: var(--yellow); background: rgba(251,191,36,0.05); }
.event-item.info     { border-left-color: var(--accent); background: rgba(99,102,241,0.05); }

.event-source { color: var(--text-secondary); font-size: 11px; margin-bottom: 2px; }
.event-summary { color: var(--text-primary); line-height: 1.4; }

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Capabilities Drawer ─────────────────────────────────── */
.btn-capabilities {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: var(--radius);
  width: 28px; height: 28px; font-size: 14px; cursor: pointer;
  margin-left: 4px;
}
.btn-capabilities:hover { color: var(--accent-hover); border-color: var(--accent); }

.capabilities-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 420px; max-width: 90vw;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
  box-shadow: -8px 0 40px rgba(0,0,0,0.5);
}
.capabilities-drawer[hidden] { display: none !important; }
.slash-palette[hidden] { display: none !important; }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 15px;
}
.btn-close-drawer {
  background: transparent; color: var(--text-secondary); border: none;
  font-size: 22px; cursor: pointer; line-height: 1;
}
.drawer-summary {
  padding: 10px 16px; color: var(--text-secondary); font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.drawer-body { overflow-y: auto; padding: 12px 0; flex: 1; }
.drawer-server {
  padding: 8px 16px;
}
.drawer-server-name {
  font-family: var(--font-mono); font-size: 12px; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.drawer-tool {
  padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.03);
}
.drawer-tool:last-child { border-bottom: none; }
.drawer-tool-name {
  font-family: var(--font-mono); font-size: 12px; color: var(--text-primary);
}
.drawer-tool-desc {
  font-size: 11px; color: var(--text-secondary); margin-top: 2px;
}
.drawer-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px;
  border-radius: 10px; margin-left: 6px;
  background: var(--orange); color: #111;
}
.drawer-badge-schedule { background: var(--accent); color: #fff; }

/* ── Slash Palette ───────────────────────────────────────── */
.slash-palette {
  position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
  width: min(520px, 80vw);
  background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  max-height: 320px; overflow-y: auto;
  z-index: 50;
}
.slash-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.slash-item:last-child { border-bottom: none; }
.slash-item.active, .slash-item:hover { background: var(--bg-surface); }
.slash-cmd { font-family: var(--font-mono); font-size: 13px; color: var(--accent); min-width: 110px; }
.slash-desc { font-size: 12px; color: var(--text-secondary); }

/* ── Mobile top bar (hidden on desktop) ─────────────────── */
.mobile-bar { display: none; }
.drawer-backdrop { display: none; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: var(--sidebar-w) 1fr; }
  .event-panel { display: none; }
}

@media (max-width: 600px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar, .event-panel {
    position: fixed;
    top: 0; bottom: 0;
    width: min(280px, 85vw);
    z-index: 90;
    display: flex;
    transition: transform 0.25s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  .sidebar { left: 0; transform: translateX(-100%); }
  .sidebar.is-open { transform: translateX(0); }

  .event-panel { right: 0; transform: translateX(100%); border-left: 1px solid var(--border); }
  .event-panel.is-open { transform: translateX(0); }

  .drawer-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 80;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .mobile-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 38px; height: 38px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    position: relative;
  }
  .mobile-btn:active { background: var(--bg-elevated); }
  .mobile-title {
    display: flex; align-items: center; gap: 8px;
    font-weight: 600; font-size: 15px;
  }
  .mobile-events-dot {
    position: absolute; top: 6px; right: 6px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 0 2px var(--bg-surface);
  }
  .mobile-events-dot[hidden] { display: none; }

  .messages { padding: 16px; }
  .input-area { padding: 12px 14px; }
  .capabilities-drawer { width: 100vw; max-width: 100vw; }
}
