:root {
  --bg: #0b0d12;
  --sidebar: #12141b;
  --panel: #171a22;
  --panel-2: #1e222c;
  --border: #262b36;
  --text: #eef0f4;
  --muted: #8a92a3;
  --accent: #6d8dff;
  --accent-2: #8f9dff;
  --danger: #ff6b6b;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --sidebar: #ffffff;
    --panel: #ffffff;
    --panel-2: #f3f4f7;
    --border: #e2e5ec;
    --text: #171a22;
    --muted: #656d7d;
    --shadow: 0 4px 20px rgba(20, 24, 40, 0.06);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- Login gate ---------- */
.gate-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.gate-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.gate-logo {
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
}

.gate-box h1 { margin: 0 0 6px; font-size: 1.25rem; }
.gate-box p { color: var(--muted); margin: 0 0 22px; font-size: 0.9rem; }

.gate-box input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s;
}
.gate-box input:focus { border-color: var(--accent); }

.gate-box button {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.gate-box button:hover { opacity: 0.9; }

.error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-top: 10px;
}

/* ---------- Shell layout ---------- */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  padding: 6px 10px 22px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.nav-item span:first-child { display: flex; align-items: center; gap: 8px; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); font-weight: 600; }

.nav-item .count {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--muted);
}
.dot-new { background: var(--muted); }
.dot-planned { background: var(--accent); }
.dot-approved { background: var(--warn); }
.dot-in_progress { background: var(--warn); }
.dot-done { background: var(--ok); }
.dot-blocked { background: var(--danger); }

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 12px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--accent);
  flex-shrink: 0;
}

.user-meta { min-width: 0; }
.user-email {
  font-size: 0.82rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-role {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: capitalize;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }
.ghost-btn.full { width: 100%; }

.main {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 60px;
  max-width: 1000px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.topbar h1 { font-size: 1.4rem; margin: 0; }

.primary-btn {
  padding: 10px 18px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  transition: opacity 0.15s;
}
.primary-btn:hover { opacity: 0.9; }

/* ---------- Task rows ---------- */
.task-rows { display: flex; flex-direction: column; gap: 10px; }

.task-row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task-row:hover { border-color: var(--accent); }

.task-row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.task-row h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.task-row .desc {
  color: var(--muted);
  font-size: 0.87rem;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  font-size: 0.72rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  text-transform: capitalize;
  white-space: nowrap;
}

.badge.status-new { color: var(--muted); }
.badge.status-planned { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.badge.status-approved { color: var(--warn); border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.badge.status-in_progress { color: var(--warn); border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.badge.status-done { color: var(--ok); border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.badge.status-blocked { color: var(--danger); border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }

.badge.priority-high { color: var(--danger); border-color: var(--danger); }
.badge.priority-med { color: var(--warn); border-color: var(--warn); }
.badge.priority-low { color: var(--muted); }

.badge.role-developer { color: var(--accent); border-color: var(--accent); }
.badge.role-client { color: var(--muted); }

.empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 40px 0;
  text-align: center;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 20px;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
.icon-btn:hover { color: var(--text); }

.field-label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 4px 0 6px;
}

#task-form input[type="text"],
#task-form textarea,
#task-form select,
#comment-form textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.92rem;
  margin-bottom: 12px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
#task-form input:focus, #task-form textarea:focus, #task-form select:focus, #comment-form textarea:focus {
  border-color: var(--accent);
}

.repo-checks {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 0.88rem;
  color: var(--text);
}
.repo-checks label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

/* ---------- Detail view ---------- */
.back-btn { margin-bottom: 18px; }
.detail-title { font-size: 1.4rem; margin: 0 0 20px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 28px;
  align-items: start;
}

.detail-main { min-width: 0; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 10px 4px;
  margin-right: 18px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--text); }

.tab-panel h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 10px;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.rendered { font-size: 0.95rem; line-height: 1.65; }
.rendered p { margin: 0 0 12px; }
.rendered ul, .rendered ol { margin: 0 0 12px; padding-left: 22px; }
.rendered li { margin-bottom: 6px; }
.rendered code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.85em;
}
.rendered pre {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
}
.rendered pre code { background: none; border: none; padding: 0; }
.rendered h1, .rendered h2, .rendered h3 { margin: 18px 0 8px; }
.rendered strong { color: var(--text); }

.detail-side {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: sticky;
  top: 32px;
}

.side-block { margin-bottom: 18px; }
.side-block h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 8px;
}
.side-block p { margin: 0; font-size: 0.88rem; }

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.action-btn {
  padding: 10px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  width: 100%;
}
.action-btn.approve { background: var(--warn); color: #1b1e24; }
.action-btn.start { background: var(--ok); color: #0f1115; }
.action-btn.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.action-btn:hover { opacity: 0.9; }

.status-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.85rem;
}

.override-label {
  font-size: 0.75rem;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

/* ---------- Comments ---------- */
.comment {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 10px;
}
.comment-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}
.comment-body { font-size: 0.92rem; }
.comment-body p:last-child { margin-bottom: 0; }

#comment-form { margin-top: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 12px 16px;
  }
  .brand { padding: 0 16px 0 0; }
  .nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .main { padding: 20px 16px 60px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-side { position: static; }
}
