:root {
  --bg: #0b0d11;
  --surface: #12151c;
  --surface-2: #181c26;
  --surface-hover: #1e2432;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1f7;
  --text-muted: #8b95a7;
  --text-dim: #5d677a;
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #f43f5e;
  --red-soft: rgba(244, 63, 94, 0.14);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.14);
  --radius: 10px;
  --radius-sm: 7px;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Inter", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 12px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }
.row-gap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Buttons & Inputs */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #5558e6; }
.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost {
  color: var(--text-muted);
  border: 1px solid transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger {
  color: var(--red);
  border: 1px solid rgba(244, 63, 94, 0.3);
  background: rgba(244, 63, 94, 0.08);
}
.btn-danger:hover { background: rgba(244, 63, 94, 0.18); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; }
.btn-full { width: 100%; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.mini-btn {
  font-size: 11px;
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 5px;
}
.mini-btn:hover { background: var(--accent-soft); }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}
.field input, .field select, .field textarea {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}
.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  padding-top: 20px;
}

.form-error {
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid rgba(244, 63, 94, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, rgba(99, 102, 241, 0.14), transparent 55%), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 28px;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.brand-lockup h1 { margin: 0; font-size: 19px; }
.brand-lockup p { margin: 2px 0 0; }
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  overflow: hidden;
}

.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.mobile-title { font-weight: 600; font-size: 15px; }

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.sidebar-top {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand-text strong { font-size: 15px; letter-spacing: -0.01em; }
.sse-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}
.sse-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}
.sse-pill.disconnected .dot { background: var(--amber); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px;
}
.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.nav-section-header.clickable { cursor: pointer; list-style: none; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); font-weight: 500; }
.nav-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow: hidden;
}
.nav-label-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.bell-toggle {
  font-size: 12px;
  opacity: 0.7;
  padding: 2px 4px;
  border-radius: 4px;
}
.bell-toggle:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }
.bell-toggle.off { opacity: 0.3; }
.ttl-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
}
.count-badge {
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--text-muted);
}
.count-badge.has-items {
  background: var(--amber-soft);
  color: var(--amber);
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.footer-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

/* Main panel */
.main-panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-wrap: wrap;
}
.toolbar-left { display: flex; align-items: baseline; gap: 10px; }
.toolbar-left h2 { margin: 0; font-size: 17px; font-weight: 600; }
.toolbar-right { display: flex; align-items: center; gap: 10px; }

.search-wrap input {
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
}
.toggle-chip:hover { color: var(--text); border-color: var(--border-strong); }

.project-banner {
  margin: 12px 22px 0;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.task-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px 28px;
}

.group-section { margin-bottom: 24px; }
.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
.group-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.group-dot.urgent { background: var(--amber); }
.group-dot.ready { background: var(--green); }
.group-dot.running { background: var(--accent); animation: pulse 1.8s infinite; }
.group-dot.done { background: var(--text-dim); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Task Card */
.task-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color 0.14s, background 0.14s, transform 0.12s;
  cursor: pointer;
}
.task-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}
.task-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.35);
}
.task-card.unread::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.task-card.status-needs_input.unread::before { background: var(--amber); }
.task-card.status-failed.unread::before { background: var(--red); }
.task-card.status-ready.unread::before { background: var(--green); }

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  flex-wrap: wrap;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}
.pill-project {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-family: var(--mono);
}
.pill-status-needs_input { background: var(--amber-soft); color: var(--amber); }
.pill-status-failed { background: var(--red-soft); color: var(--red); }
.pill-status-ready { background: var(--green-soft); color: var(--green); }
.pill-status-running { background: var(--accent-soft); color: #9ea3ff; }
.pill-status-done { background: rgba(100, 116, 139, 0.18); color: #94a3b8; }

.pill-source {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 7px;
  max-width: 360px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill-notify {
  font-size: 11px;
  color: var(--text-dim);
}

.card-title {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.card-summary {
  margin: 0 0 10px;
  padding-left: 16px;
  color: #c8d0df;
  font-size: 13px;
}
.card-summary li { margin-bottom: 3px; }

.action-box {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 10px;
  font-size: 13px;
  color: #fde68a;
}
.action-box.ready {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
  color: #a7f3d0;
}
.action-box.failed {
  background: rgba(244, 63, 94, 0.09);
  border-color: rgba(244, 63, 94, 0.3);
  color: #fecdd3;
}
.action-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.85;
  margin-right: 6px;
}

.suggested-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.chip-action {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  transition: border-color 0.14s, background 0.14s;
}
.chip-action:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.resume-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 440px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  font-family: var(--mono);
  font-size: 11.5px;
  color: #c7d2fe;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.resume-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

.artifact-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #93c5fd;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.1);
}
.artifact-link:hover { background: rgba(59, 130, 246, 0.2); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}
.empty-state h3 { margin: 0 0 8px; color: var(--text); font-size: 16px; }
.empty-state p { margin: 0 0 18px; font-size: 13px; }

.kbd-hint {
  padding: 8px 22px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}
kbd {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Detail Drawer */
.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.45);
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.meta-grid {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 6px 10px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.meta-grid dt { color: var(--text-dim); }
.meta-grid dd {
  margin: 0;
  font-family: var(--mono);
  word-break: break-all;
  color: var(--text);
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.timeline-item {
  border-left: 2px solid var(--border-strong);
  padding-left: 12px;
  font-size: 12px;
}
.timeline-item .muted { font-size: 11px; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 20px;
}
.modal-wide { max-width: 720px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.code-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}
.code-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.code-panel pre {
  margin: 0;
  padding: 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: #dbe4ff;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
}

/* Toast & Backdrop */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e2433;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 99px;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  z-index: 60;
}
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 25;
}

/* Mobile Responsive */
@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .mobile-header { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 270px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .toolbar { padding: 12px 14px; }
  .search-wrap input { width: 160px; }
  .task-container { padding: 12px 14px 24px; }
  .project-banner { margin: 10px 14px 0; }
  .kbd-hint { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
}
