:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

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

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; }
#main-content { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: 80px; }

/* ── Nav bar ── */
#nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 8px 0 env(safe-area-inset-bottom);
  z-index: 100;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; background: none; border: none; color: var(--text-muted);
  font-size: 10px; cursor: pointer; padding: 4px 8px; border-radius: 8px;
  transition: color 0.15s;
}
.nav-btn .icon { font-size: 20px; }
.nav-btn.active { color: var(--primary); }

/* ── Header ── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.page-title { font-size: 20px; font-weight: 700; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.card-meta { font-size: 12px; color: var(--text-muted); }
.card-row { display: flex; justify-content: space-between; align-items: center; }

/* ── Badges ── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 100px;
  font-size: 11px; font-weight: 600;
}
.badge-active { background: #1e3a5f; color: #60a5fa; }
.badge-completed { background: #14532d; color: #4ade80; }
.badge-blocked { background: #450a0a; color: #fca5a5; }
.badge-backlog { background: #1c1917; color: #a8a29e; }
.badge-draft { background: #2d1d00; color: #fcd34d; }
.badge-milestone { background: #1e1b4b; color: #a5b4fc; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px; border-radius: 8px; border: none;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity 0.15s;
}
.btn:active { opacity: 0.8; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }
.btn-ghost { background: none; color: var(--text-muted); border: 1px solid var(--border); }

/* ── Inputs ── */
input[type="text"], input[type="password"], input[type="date"],
textarea, select {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 10px 12px; font-size: 14px;
  font-family: var(--font);
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary); border-color: transparent;
}
textarea { resize: vertical; min-height: 80px; }
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }

/* ── Toggle switch ── */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--surface2); border-radius: 24px;
  cursor: pointer; transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle-slider::before {
  content: ''; position: absolute; width: 18px; height: 18px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s;
}
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Chat ── */
#chat-messages {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 16px;
}
.chat-bubble {
  max-width: 88%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.5;
}
.chat-bubble.user { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-bubble.assistant { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-tool-note { font-size: 11px; color: var(--text-muted); background: var(--surface2); border-radius: 6px; padding: 4px 8px; margin-top: 4px; }
#chat-input-row { display: flex; gap: 8px; position: sticky; bottom: 72px; background: var(--bg); padding: 8px 0; }
#chat-input { flex: 1; }

/* ── Image preview strip ── */
#image-preview-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 0;
  scrollbar-width: thin;
}
.preview-thumb {
  position: relative; flex-shrink: 0;
  width: 72px; height: 72px; border-radius: 8px; overflow: hidden;
  border: 2px solid var(--border);
}
.preview-thumb img { width: 100%; height: 100%; object-fit: cover; }
.preview-remove {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
  background: rgba(0,0,0,0.7); color: #fff; border: none; border-radius: 50%;
  font-size: 11px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ── Breadcrumb ── */
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; font-size: 13px; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb .sep { color: var(--text-muted); }

/* ── Table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; color: var(--text-muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 8px; border-bottom: 1px solid var(--surface2); vertical-align: top; }

/* ── Milestones checklist ── */
.milestone-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; background: var(--surface); border-radius: 8px; margin-bottom: 8px;
}
.milestone-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--surface2); color: var(--text); padding: 10px 20px;
  border-radius: 20px; font-size: 14px; z-index: 999;
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
  border: 1px solid var(--border);
}
#toast.show { opacity: 1; }

/* ── Loading spinner ── */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--surface2); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; width: 100%; max-width: 420px;
}
.modal h3 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Config tabs ── */
.tab-bar { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn { padding: 10px 16px; background: none; border: none; color: var(--text-muted); font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--text); border-bottom-color: var(--primary); }

/* ── Log viewer ── */
#log-content {
  background: #0a0a0a; color: #a8ff78; font-family: monospace; font-size: 12px;
  padding: 12px; border-radius: 8px; overflow-y: auto; height: 400px;
  white-space: pre-wrap; word-break: break-all;
  border: 1px solid var(--border);
}

/* ── Filters ── */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-chip {
  padding: 5px 12px; border-radius: 100px; border: 1px solid var(--border);
  background: none; color: var(--text-muted); font-size: 13px; cursor: pointer;
}
.filter-chip.active { background: var(--primary); color: #fff; border-color: transparent; }

/* ── Section header ── */
.section-header {
  font-size: 13px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin: 20px 0 10px;
}

/* ── Config section ── */
.config-section { margin-bottom: 24px; }
.config-section-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.config-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--surface2); }
.config-row-label { font-size: 14px; }
.config-row-sub { font-size: 12px; color: var(--text-muted); }

/* ── Jobs screen ── */
.job-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px; background: var(--surface); border-radius: 8px; margin-bottom: 8px;
  border: 1px solid var(--border);
}
.job-info { flex: 1; }
.job-name { font-size: 14px; font-weight: 600; }
.job-times { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

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