/* Keep — Rose Pine themed UI */

:root {
  --rp-bg: #191724;
  --rp-bg-surface: #1f1d2e;
  --rp-overlay: #26233a;
  --rp-border: #403d52;
  --rp-hl-low: #21202e;
  --rp-hl-med: #403d52;
  --rp-hl-high: #524f67;
  --rp-fg: #e0def4;
  --rp-fg-muted: #6e6a86;
  --rp-fg-subtle: #908caa;
  --rp-accent: #c4a7e7;
  --rp-accent-green: #9ccfd8;
  --rp-accent-yellow: #f6c177;
  --rp-accent-red: #eb6f92;
  --rp-radius: 8px;
  --rp-radius-sm: 6px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Iosevka Term', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

[data-theme="moon"] {
  --rp-bg: #232136;
  --rp-bg-surface: #2a273f;
  --rp-overlay: #393552;
  --rp-border: #44415a;
  --rp-hl-low: #2a283e;
  --rp-hl-med: #3e3555;
  --rp-hl-high: #4a4266;
}

[data-theme="dawn"] {
  --rp-bg: #faf4ed;
  --rp-bg-surface: #fffaf3;
  --rp-overlay: #f2e9e1;
  --rp-border: #dfdad9;
  --rp-hl-low: #f4ede8;
  --rp-hl-med: #dfdad9;
  --rp-hl-high: #cecacd;
  --rp-fg: #575279;
  --rp-fg-muted: #9893a5;
  --rp-fg-subtle: #797593;
  --rp-accent: #907aa9;
  --rp-accent-green: #56949f;
  --rp-accent-yellow: #ea9d34;
  --rp-accent-red: #b4637a;
}

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

body {
  font-family: var(--font-sans);
  background: var(--rp-bg);
  color: var(--rp-fg);
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Layout ── */

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  height: 44px;
  background: var(--rp-bg-surface);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--rp-border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
}
.topbar-icon { color: var(--rp-accent); }

.topbar-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--rp-fg);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  margin-right: 4px;
}

@media (max-width: 767px) {
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .topbar-nav {
    display: none;
    position: absolute;
    top: 44px;
    left: 0;
    right: 0;
    background: var(--rp-bg-surface);
    flex-direction: column;
    align-items: stretch;
    border-bottom: 1px solid var(--rp-border);
    z-index: 20;
    padding: 4px 0;
  }
  .topbar-nav.open {
    display: flex;
  }
  .topbar-nav .nav-link {
    padding: 12px 16px;
  }
}


.sidebar {
  display: none;
  width: 200px;
  background: var(--rp-bg-surface);
  border-right: 1px solid var(--rp-border);
  padding: 8px 0;
  flex-shrink: 0;
  overflow-y: auto;
}

@media (min-width: 768px) {
  .app-layout { flex-direction: row; flex-wrap: wrap; }
  .topbar { width: 100%; }
  .sidebar { display: flex; flex-direction: column; }
  .bottom-nav { display: none; }
  .main-content { flex: 1; height: calc(100vh - 44px); overflow-y: auto; }
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--rp-fg-muted);
  text-decoration: none;
  font-size: 14px;
  border-radius: 0;
  transition: background 0.15s;
}

.sidebar-link:hover { background: var(--rp-hl-low); color: var(--rp-fg); }
.sidebar-link.active { background: var(--rp-hl-med); color: var(--rp-accent); }
.sidebar-icon { width: 20px; text-align: center; }
.sidebar-spacer { flex: 1; }

/* ── Bottom nav (mobile) ── */

.bottom-nav {
  display: flex;
  height: 56px;
  background: var(--rp-bg-surface);
  border-top: 1px solid var(--rp-border);
  justify-content: space-around;
  align-items: center;
  flex-shrink: 0;
}

.bottom-nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--rp-fg-muted);
  text-decoration: none;
  font-size: 10px;
  padding: 4px 12px;
}

.bottom-nav-link.active { color: var(--rp-accent); }
.bottom-nav-icon { font-size: 20px; }

@media (min-width: 768px) {
  .bottom-nav { display: none; }
}

/* ── Main content ── */

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* ── Login ── */

.login-card {
  max-width: 400px;
  margin: 20vh auto;
  background: var(--rp-bg-surface);
  padding: 32px;
  border-radius: var(--rp-radius);
  text-align: center;
}

.login-logo {
  font-size: 48px;
  margin-bottom: 8px;
  color: var(--rp-accent);
}

.login-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--rp-fg-muted);
  margin-bottom: 24px;
}

/* ── Forms ── */

input, textarea {
  font-family: var(--font-sans);
  background: var(--rp-bg);
  border: 1px solid var(--rp-border);
  color: var(--rp-fg);
  padding: 12px;
  border-radius: var(--rp-radius-sm);
  width: 100%;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, textarea:focus { border-color: var(--rp-accent); }
::placeholder { color: var(--rp-fg-muted); }

.input-group { margin-bottom: 12px; }

.error-message {
  color: var(--rp-accent-red);
  font-size: 14px;
  margin-bottom: 8px;
}

.hidden { display: none !important; }

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--rp-radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  font-family: var(--font-sans);
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }
.btn:active { opacity: 0.75; }

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

.btn-danger {
  background: var(--rp-accent-red);
  color: #191724;
}

.btn-ghost {
  background: transparent;
  color: var(--rp-fg-muted);
  border: 1px solid var(--rp-border);
}

.btn-ghost:hover { background: var(--rp-hl-low); color: var(--rp-fg); }

/* ── Status colors ── */

.state-executing { color: var(--rp-accent-green); }
.state-exploring { color: var(--rp-pine); }
.state-awaiting { color: var(--rp-accent-yellow); }
.state-input { color: var(--rp-accent-yellow); }
.state-failed { color: var(--rp-accent-red); }
.state-completed { opacity: 0.6; }
.state-cancelled { opacity: 0.4; }

/* ── Cards ── */

.card {
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius);
  padding: 16px;
  margin-bottom: 8px;
}

/* ── Dashboard ── */

.page-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.page-header .page-title { margin-bottom: 0; }

.stat-cards {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 100px;
  padding: 16px;
  text-align: center;
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius);
  border: 1px solid var(--rp-border);
}

.stat-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--rp-fg-muted);
  margin-top: 4px;
}

.stat-active .stat-value { color: var(--rp-accent-green); }
.stat-input .stat-value { color: var(--rp-accent-yellow); }
.stat-escape .stat-value { color: var(--rp-accent-red); }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 767px) { .dashboard-grid { grid-template-columns: 1fr; } }

.dashboard-panel h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--rp-fg-subtle);
  margin-bottom: 12px;
}

.empty-state {
  color: var(--rp-fg-muted);
  font-size: 14px;
  padding: 24px;
  text-align: center;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--rp-fg-muted);
}
/* ── Chat feed ── */

.chat-feed {
  max-height: 400px;
  overflow-y: auto;
}

.chat-entry {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--rp-radius-sm);
  margin-bottom: 2px;
  transition: background 0.15s;
}

.chat-entry:hover { background: var(--rp-hl-low); }

.chat-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  margin-bottom: 2px;
}

.chat-status {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
}

.chat-time {
  color: var(--rp-fg-muted);
}

.chat-task {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-summary {
  font-size: 12px;
  color: var(--rp-fg-subtle);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


.session-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius-sm);
  margin-bottom: 4px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.session-card:hover { border-color: var(--rp-border); }

.session-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.session-indicator.state-executing { background: var(--rp-accent-green); }
.session-indicator.state-awaiting { background: var(--rp-accent-yellow); }
.session-indicator.state-failed { background: var(--rp-accent-red); }
.session-indicator.state-completed { background: var(--rp-fg-muted); }

.session-info { flex: 1; min-width: 0; }
.session-task {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-meta {
  font-size: 12px;
  color: var(--rp-fg-muted);
}

/* ── Session detail page ── */

.session-detail-card {
  display: block;
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius);
  padding: 16px;
  margin-bottom: 8px;
  text-decoration: none;
  color: inherit;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}

.session-detail-card:hover { border-color: var(--rp-border); }

.session-card-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.session-state-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--rp-bg);
}

.session-card-body { margin-bottom: 8px; }

.session-summary {
  font-size: 13px;
  color: var(--rp-fg-subtle);
  margin-top: 4px;
}

.session-card-footer {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--rp-fg-muted);
}

.back-link {
  color: var(--rp-accent);
  text-decoration: none;
  font-size: 14px;
}

.back-link:hover { text-decoration: underline; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.detail-panel {
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius);
  padding: 16px;
}

.detail-panel h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--rp-fg-subtle);
  margin-bottom: 12px;
}

.detail-fields { display: grid; gap: 8px; }

.detail-field {
  display: flex;
  gap: 8px;
}

.field-label {
  width: 100px;
  font-size: 13px;
  color: var(--rp-fg-muted);
  flex-shrink: 0;
}

.field-value { font-size: 13px; }

.session-detail-actions {
  display: flex;
  gap: 8px;
}

/* ── Timeline ── */

.timeline {
  border-left: 2px solid var(--rp-border);
  padding-left: 16px;
}

.timeline-item {
  position: relative;
  padding: 6px 0;
}

.timeline-item::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--rp-accent);
  border-radius: 50%;
  position: absolute;
  left: -21px;
  top: 10px;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  position: absolute;
  left: -21px;
  top: 10px;
}

.timeline-dot.state-executing { background: var(--rp-accent-green); }
.timeline-dot.state-awaiting { background: var(--rp-accent-yellow); }
.timeline-dot.state-failed { background: var(--rp-accent-red); }

.timeline-content { padding: 0 0 4px; }

.timeline-status {
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.timeline-summary {
  font-size: 13px;
  color: var(--rp-fg-subtle);
}

.timeline-meta {
  font-size: 11px;
  color: var(--rp-fg-muted);
  margin-top: 2px;
}

/* ── Repos ── */

.repo-item {
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius-sm);
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.repo-item:hover { border-color: var(--rp-border); }

.repo-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  cursor: pointer;
}

.repo-icon { color: var(--rp-accent); }
.repo-name { flex: 1; font-weight: 500; font-size: 14px; }
.repo-active { font-size: 12px; color: var(--rp-fg-muted); }
.repo-expand { color: var(--rp-fg-muted); font-size: 12px; }

.repo-worktrees {
  padding: 0 12px 12px 36px;
  display: flex;
  gap: 8px;
}

/* ── Git ── */

.git-info {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  font-size: 14px;
}

.git-branch-label strong { color: var(--rp-accent); }

.git-ahead {
  font-size: 12px;
  color: var(--rp-fg-muted);
}

.git-changes { margin-top: 12px; }

.git-changes h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--rp-fg-subtle);
  margin-bottom: 8px;
}

.git-change-item {
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius-sm);
  margin-bottom: 2px;
}

.git-change-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-mono);
}

.git-change-header:hover { background: var(--rp-hl-low); }

.git-change-status {
  width: 20px;
  font-weight: 700;
  text-align: center;
}

.git-change-file { flex: 1; }
.git-change-expand { color: var(--rp-fg-muted); }

.git-change-diff { padding: 0 12px 8px; }

.diff-content {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--rp-bg);
  padding: 12px;
  border-radius: var(--rp-radius-sm);
  overflow-x: auto;
  line-height: 1.6;
  white-space: pre;
}

/* ── Files ── */

.files-split {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  margin-top: 12px;
}

@media (max-width: 767px) { .files-split { grid-template-columns: 1fr; } }

.files-tree-panel {
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius);
  padding: 12px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

.files-content-panel {
  background: var(--rp-bg-surface);
  border-radius: var(--rp-radius);
  padding: 12px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

.tree-node {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 4px 0;
  cursor: pointer;
  white-space: nowrap;
}

.tree-node:hover { color: var(--rp-accent); }
.tree-file.selected { color: var(--rp-accent); font-weight: 600; }
.tree-toggle { margin-right: 4px; font-size: 10px; color: var(--rp-fg-muted); }

.file-content { width: 100%; border-collapse: collapse; }

.line-num {
  width: 40px;
  text-align: right;
  padding: 0 12px;
  color: var(--rp-fg-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  user-select: none;
  vertical-align: top;
}

.line-code {
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: pre;
  padding: 0;
  line-height: 1.6;
}

/* ── Syntax highlight classes ── */

.hl-comment { color: var(--rp-fg-muted); font-style: italic; }
.hl-string { color: var(--rp-accent-green); }
.hl-keyword { color: var(--rp-accent); font-weight: 600; }
.hl-number { color: var(--rp-accent-yellow); }

/* ── Terminal ── */

.terminal-container {
  background: #000;
  border-radius: var(--rp-radius);
  padding: 12px;
  min-height: 300px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 14px;
}

.terminal-output {
  color: #e0def4;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.terminal-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.terminal-form input { flex: 1; }

/* ── Theme picker ── */

.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--rp-fg-subtle);
  margin-bottom: 12px;
}

.settings-sub {
  font-size: 13px;
  color: var(--rp-fg-muted);
  margin-top: 4px;
}

.theme-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--rp-bg-surface);
  border: 1px solid var(--rp-border);
  border-radius: var(--rp-radius-sm);
  color: var(--rp-fg);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-sans);
}

.theme-btn.active {
  border-color: var(--rp-accent);
  background: var(--rp-hl-med);
}

.theme-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-block;
}

.swatch-pine { background: #191724; border: 1px solid #c4a7e7; }
.swatch-moon { background: #232136; border: 1px solid #c4a7e7; }
.swatch-dawn { background: #faf4ed; border: 1px solid #907aa9; }

/* ── Spinner ── */

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--rp-border);
  border-top-color: var(--rp-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

/* ── Links ── */

a { color: var(--rp-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Scrollbar ── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rp-hl-med); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--rp-hl-high); }

::selection { background: var(--rp-hl-med); }
