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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a1a;
  color: #ede9e0;
}

/* ── LAYOUT ── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #171717;
  border-right: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-top {
  padding: 20px 16px 12px;
  border-bottom: 1px solid #2a2a2a;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ede9e0;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-brand h1 span { color: #cc7b5c; }

.sidebar-new-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  color: #9a9590;
  font-size: 0.875rem;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-align: left;
}

.sidebar-new-btn:hover { background: #222; color: #ede9e0; }

.sidebar-nav {
  padding: 8px 8px 4px;
  flex-shrink: 0;
}

.sidebar-new-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.sidebar-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #5e5a55;
  padding: 14px 16px 6px;
  flex-shrink: 0;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
}

.sidebar-body { scrollbar-width: thin; scrollbar-color: #2e2e2e transparent; }
.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-track { background: transparent; }
.sidebar-body::-webkit-scrollbar-thumb { background: #2e2e2e; border-radius: 4px; }

/* ── MAIN AREA ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: #1a1a1a;
}

.main { scrollbar-width: thin; scrollbar-color: #2e2e2e transparent; }
.main::-webkit-scrollbar { width: 4px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb { background: #2e2e2e; border-radius: 4px; }
.main::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 28px;
  flex-shrink: 0;
}

.header-badge {
  font-size: 0.72rem;
  color: #5e5a55;
  background: #242424;
  border: 1px solid #2e2e2e;
  padding: 3px 10px;
  border-radius: 20px;
}

.api-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: #5e5a55;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5e5a55;
}

.status-dot.online  { background: #4ade80; }
.status-dot.offline { background: #f87171; }

/* ── CONTAINER ── */
.container {
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 32px;
}

/* ── WELCOME ── */
.welcome {
  text-align: center;
  margin-bottom: 16px;
}

.welcome-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: #ede9e0;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.welcome-sub {
  font-size: 0.82rem;
  color: #5e5a55;
  line-height: 1.5;
}

/* ── SECTION TITLE ── */
.section-title {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: #5e5a55;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 10px;
}

/* ── CARD ── */
.card {
  background: #212121;
  border: 1px solid #2e2e2e;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
}


/* ── FORM ── */
label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: #9a9590;
  margin-bottom: 6px;
  margin-top: 18px;
}

label:first-of-type { margin-top: 0; }

.field-wrap { position: relative; }

textarea, input[type="text"] {
  width: 100%;
  background: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 10px;
  color: #ede9e0;
  font-size: 0.9rem;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  resize: vertical;
}

textarea:focus, input[type="text"]:focus {
  border-color: #cc7b5c;
  box-shadow: 0 0 0 3px rgba(204, 123, 92, 0.12);
}

textarea { min-height: 80px; padding-bottom: 24px; }

.char-count {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 0.7rem;
  color: #4a4a4a;
  pointer-events: none;
}

.hint {
  font-size: 0.73rem;
  color: #4a4a4a;
  margin-top: 5px;
  line-height: 1.4;
}

/* ── CONTEXT TOOLS ── */
.context-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s;
  margin-top: 12px;
}

.context-toggle:hover { border-color: #3a3a3a; }

.context-toggle-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #9a9590;
}

.context-toggle-icon { font-size: 0.9rem; }

.context-optional { color: #4a4a4a; font-size: 0.75rem; }

.context-toggle-right { display: flex; align-items: center; gap: 8px; }

.context-chevron {
  font-size: 0.65rem;
  color: #4a4a4a;
  transition: transform 0.2s;
}

.context-toggle.open .context-chevron { transform: rotate(90deg); }

.active-tools {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tool-pill {
  font-size: 0.65rem;
  background: #3d2218;
  color: #cc7b5c;
  border: 1px solid #6b3a28;
  padding: 1px 8px;
  border-radius: 20px;
}

.collapsible {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.22s ease;
}
.collapsible.open { max-height: 500px; }

.tool-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.tool-row {
  background: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 10px;
  padding: 10px;
}

.tool-row-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}


.tool-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #c9c5bc;
}

.tool-row input[type="text"] {
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.85rem;
}

/* ── SUBMIT ── */
button[type="submit"] {
  margin-top: 14px;
  width: 100%;
  padding: 12px;
  background: #cc7b5c;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.01em;
}

button[type="submit"]:hover  { opacity: 0.88; }
button[type="submit"]:active { transform: scale(0.99); }
button[type="submit"]:disabled { background: #5a3628; cursor: not-allowed; opacity: 0.6; }

/* ── SPINNER ── */
.spinner { display: none; text-align: center; padding: 48px 0; }
.spinner.visible { display: block; }

.spinner-ring {
  width: 40px;
  height: 40px;
  border: 3px solid #2e2e2e;
  border-top-color: #cc7b5c;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

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

.spinner-text { font-size: 0.875rem; color: #5e5a55; }
.spinner-sub  { font-size: 0.75rem; color: #4a4a4a; margin-top: 4px; }

/* ── ERROR ── */
.error-box {
  display: none;
  background: #2d1515;
  border: 1px solid #7f1d1d;
  border-radius: 10px;
  padding: 14px 16px;
  color: #fca5a5;
  font-size: 0.85rem;
  margin-bottom: 20px;
  align-items: flex-start;
  gap: 10px;
}

.error-box.visible { display: flex; }
.error-icon { flex-shrink: 0; font-size: 1rem; }

/* ── PLAN OUTPUT ── */
.plan-output { display: none; }
.plan-output.visible { display: block; }

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.output-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.output-header h2 { font-size: 1rem; font-weight: 700; color: #ede9e0; }

.badge-complete {
  font-size: 0.72rem;
  background: #14291e;
  color: #4ade80;
  border: 1px solid #166534;
  padding: 3px 9px;
  border-radius: 20px;
}

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

.btn-sm {
  font-size: 0.78rem;
  padding: 6px 13px;
  border-radius: 20px;
  border: 1px solid #2e2e2e;
  background: #212121;
  color: #9a9590;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  display: flex;
  align-items: center;
  gap: 5px;
}

.btn-sm:hover    { background: #2e2e2e; color: #ede9e0; border-color: #3a3a3a; }
.btn-sm.active   { background: #3d2218; border-color: #cc7b5c; color: #cc7b5c; }
.btn-sm:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── SUMMARY ── */
.summary-box {
  background: #242420;
  border: 1px solid #3a3530;
  border-radius: 10px;
  padding: 16px 18px;
  font-size: 0.875rem;
  color: #d4c9b8;
  line-height: 1.7;
  margin-bottom: 16px;
}

.summary-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #cc7b5c;
  margin-bottom: 8px;
}

/* ── PLAN SECTIONS ── */
.plan-section {
  background: #212121;
  border: 1px solid #2e2e2e;
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.plan-section:hover { border-color: #3a3a3a; }

.plan-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: background 0.1s;
}

.plan-section-header:hover { background: #272727; }
.plan-section-header.open  { border-bottom-color: #2e2e2e; background: #272727; }

.plan-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}


.section-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #ede9e0;
}

.section-count {
  font-size: 0.7rem;
  background: #2e2e2e;
  color: #5e5a55;
  padding: 1px 6px;
  border-radius: 8px;
}

.plan-section-arrow {
  font-size: 0.6rem;
  color: #4a4a4a;
  transition: transform 0.2s;
}

.plan-section-header.open .plan-section-arrow { transform: rotate(90deg); }

.plan-section-body { display: none; padding: 14px 16px; }
.plan-section-body.open { display: block; }
.plan-section-body ul { list-style: none; padding: 0; }

.plan-section-body li {
  font-size: 0.875rem;
  color: #c9c5bc;
  padding: 8px 0 8px 16px;
  border-bottom: 1px solid #242424;
  line-height: 1.6;
  position: relative;
}

.plan-section-body li:last-child { border-bottom: none; }

.plan-section-body li::before {
  content: "›";
  color: #cc7b5c;
  position: absolute;
  left: 0;
  top: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  line-height: 1.3;
}

/* ── GENERATE TASKS BTN ── */
.generate-tasks-btn {
  margin-top: 16px;
  width: 100%;
  padding: 13px;
  background: #242424;
  color: #ede9e0;
  border: 1px solid #3a3a3a;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.generate-tasks-btn:hover    { background: #2e2e2e; border-color: #4a4a4a; }
.generate-tasks-btn:active   { transform: scale(0.99); }
.generate-tasks-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── TASK OUTPUT ── */
.task-output { display: none; margin-top: 32px; }
.task-output.visible { display: block; }

.ticket-card {
  background: #212121;
  border: 1px solid #2e2e2e;
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.ticket-card:hover { border-color: #3a3a3a; }

.ticket-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: background 0.1s;
}

.ticket-header:hover { background: #272727; }
.ticket-header.open  { border-bottom-color: #2e2e2e; background: #272727; }

.ticket-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ticket-id {
  font-size: 0.72rem;
  font-weight: 700;
  background: #1e2e3a;
  color: #60b8e0;
  border: 1px solid #2a5070;
  padding: 2px 7px;
  border-radius: 6px;
  flex-shrink: 0;
}

.ticket-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #ede9e0;
}

.ticket-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.priority-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.priority-high   { background: #3d1010; color: #f87171; border: 1px solid #7f1d1d; }
.priority-medium { background: #2d1e00; color: #fbbf24; border: 1px solid #78350f; }
.priority-low    { background: #0f2d1e; color: #4ade80; border: 1px solid #166534; }

.estimate-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: #1e1e2e;
  color: #a5b4fc;
  border: 1px solid #3730a3;
  letter-spacing: 0.03em;
}

.ticket-arrow {
  font-size: 0.6rem;
  color: #4a4a4a;
  transition: transform 0.2s;
  margin-left: 6px;
}

.ticket-header.open .ticket-arrow { transform: rotate(90deg); }

.ticket-body { display: none; padding: 14px 16px; }
.ticket-body.open { display: block; }

.ticket-description {
  font-size: 0.875rem;
  color: #9a9590;
  line-height: 1.6;
  margin-bottom: 14px;
}

.ticket-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #4a4a4a;
  margin-bottom: 6px;
  margin-top: 12px;
}

.ticket-section-label:first-child { margin-top: 0; }

.ticket-criteria {
  list-style: none;
  padding: 0;
}

.ticket-criteria li {
  font-size: 0.82rem;
  color: #c9c5bc;
  padding: 5px 0;
  border-bottom: 1px solid #242424;
  display: flex;
  gap: 8px;
  line-height: 1.5;
}

.ticket-criteria li:last-child { border-bottom: none; }

.ticket-criteria li::before {
  content: "✓";
  color: #4ade80;
  flex-shrink: 0;
  font-size: 0.75rem;
  margin-top: 1px;
}

.ticket-labels {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.ticket-label {
  font-size: 0.65rem;
  background: #242424;
  color: #9a9590;
  border: 1px solid #2e2e2e;
  padding: 2px 8px;
  border-radius: 20px;
}

.ticket-deps {
  font-size: 0.8rem;
  color: #5e5a55;
  margin-top: 4px;
}

.phase-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5e5a55;
  padding: 16px 0 8px;
  border-bottom: 1px solid #2e2e2e;
  margin-bottom: 10px;
}

.phase-header:first-child { padding-top: 0; }


/* ── HISTORY LIST (in sidebar) ── */
.history-list { display: flex; flex-direction: column; gap: 2px; }

.history-empty {
  font-size: 0.8rem;
  color: #3a3a3a;
  text-align: center;
  padding: 32px 8px;
  line-height: 1.5;
}

.history-row {
  display: flex;
  flex-direction: column;
  padding: 10px 10px;
  border-radius: 8px;
  gap: 2px;
  transition: background 0.12s;
  cursor: pointer;
}

.history-row:hover { background: #222; }
.history-row:hover .history-row-actions { opacity: 1; }

.history-row-title {
  font-size: 0.82rem;
  font-weight: 400;
  color: #c9c5bc;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.history-row-date {
  font-size: 0.68rem;
  color: #4a4a4a;
  margin-top: 2px;
}

.history-row-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.12s;
}

.btn-danger { border-color: #7f1d1d; color: #f87171; }
.btn-danger:hover { background: #2d1515; border-color: #f87171; color: #f87171; }

/* ── SAVE BTN ── */
.btn-save { border-color: #166534; color: #4ade80; }
.btn-save:hover { background: #14291e; border-color: #4ade80; }
.btn-save:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #2e2e2e;
  border: 1px solid #3a3a3a;
  color: #ede9e0;
  font-size: 0.82rem;
  padding: 10px 16px;
  border-radius: 10px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 200;
}

.toast.show { opacity: 1; transform: translateY(0); }
