:root {
  --bg: #ffffff;
  --bg-subtle: #f6f8fa;
  --bg-canvas: #f0f3f6;
  --border: #d0d7de;
  --border-muted: #e5e9ee;
  --fg: #1f2328;
  --fg-muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --danger: #cf222e;
  --danger-bg: #ffebe9;
  --success: #1a7f37;
  --success-bg: #dafbe1;
  --warning-bg: #fff8c5;
  --info-bg: #ddf4ff;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(31, 35, 40, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg-subtle);
}

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

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  height: 52px;
  background: #24292f;
  color: #ffffff;
  border-bottom: 1px solid #1b1f23;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  font-weight: 600;
  font-size: 15px;
}
.brand:hover { text-decoration: none; opacity: 0.9; }
.brand-sep { color: #8b949e; font-weight: 400; }
.brand-sub { font-weight: 400; color: #e6edf3; }

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.nav-link {
  color: #c9d1d9;
  padding: 6px 10px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13px;
}
.nav-link:hover { background: rgba(255,255,255,0.1); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(255,255,255,0.16); color: #fff; }

.user-pill {
  font-size: 13px;
  color: #c9d1d9;
}

/* Flash messages */
.flash-container {
  max-width: 1200px;
  margin: 12px auto 0;
  padding: 0 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.flash {
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
}
.flash-success { background: var(--success-bg); border-color: #4ac26b; color: #116329; }
.flash-error { background: var(--danger-bg); border-color: #ff8182; color: #82071e; }
.flash-warning { background: var(--warning-bg); border-color: #d4a72c; color: #4d2d00; }
.flash-info { background: var(--info-bg); border-color: #54aeff; color: #0550ae; }

/* Containers */
.container {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 18px 40px;
}

.board-main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
  overflow: hidden;
  background: var(--bg);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: #eaeef2; text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-primary {
  background: #1f883d;
  border-color: rgba(31, 35, 40, 0.15);
  color: #ffffff;
}
.btn-primary:hover { background: #1a7f37; }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.topbar .btn-ghost {
  color: #e6edf3;
  border-color: rgba(255,255,255,0.22);
}
.topbar .btn-ghost:hover { background: rgba(255,255,255,0.12); }

.btn-danger {
  background: var(--danger);
  border-color: rgba(31, 35, 40, 0.15);
  color: #ffffff;
}
.btn-danger:hover { background: #a40e26; }

.btn-danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}
.btn-danger-ghost:hover { background: var(--danger-bg); border-color: #ff8182; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--fg-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.btn-icon:hover { background: rgba(31, 35, 40, 0.08); color: var(--fg); }

.inline-form { display: inline; margin: 0; }
.muted { color: var(--fg-muted); }
.small { font-size: 12px; }

/* Auth pages */
.auth-page { background: var(--bg-subtle); }
.auth-card {
  max-width: 390px;
  margin: 56px auto;
  padding: 28px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-card .muted { margin: 0 0 20px; font-size: 13px; }
.auth-footer { margin: 18px 0 0; text-align: center; font-size: 13px; color: var(--fg-muted); }

/* Forms */
.stack-form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--fg); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="search"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.input-sm, .select-sm { padding: 4px 8px; font-size: 12px; width: auto; }
.color-input { width: 64px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.color-input-sm { width: 34px; height: 28px; padding: 1px; border: 1px solid var(--border); border-radius: 5px; cursor: pointer; }

/* Filter Bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-muted);
  background: var(--bg);
}

.filter-search {
  position: relative;
  flex: 1 1 280px;
  max-width: 460px;
}
.filter-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-muted);
  pointer-events: none;
}
.filter-search input { padding-left: 32px; }

.filter-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.filter-controls select { width: auto; min-width: 135px; }
.filter-count {
  font-size: 12px;
  color: var(--fg-muted);
  font-weight: 500;
  padding-left: 4px;
}

.quick-label-strip {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  padding: 7px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  overflow-x: auto;
}

.quick-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.quick-pill:hover { border-color: var(--fg-muted); }
.quick-pill.active {
  background: var(--pill-bg);
  color: var(--pill-fg);
  border-color: transparent;
}
.quick-pill.active .pill-dot { display: none; }
.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* Kanban Board */
.kanban-board {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 14px 18px 18px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--bg-canvas);
}

.kanban-column {
  flex: 0 0 315px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-muted);
}

.column-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.column-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.column-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.column-count {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(175, 184, 193, 0.28);
  color: var(--fg-muted);
}
.column-count.over-wip {
  background: var(--danger-bg);
  color: var(--danger);
}

.column-cards {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}

/* Cards */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 11px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.card:hover {
  border-color: #8c959f;
  box-shadow: 0 2px 6px rgba(31, 35, 40, 0.08);
}
.card:active { cursor: grabbing; }
.card[hidden] { display: none !important; }

.card.sortable-ghost {
  opacity: 0.35;
  background: #ddf4ff;
  border: 1px dashed var(--accent);
}
.card.sortable-chosen {
  box-shadow: var(--shadow-md);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
}

.card-ref-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.card-ref {
  font-size: 11px;
  color: var(--fg-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.card-title {
  display: block;
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.38;
  word-break: break-word;
}
.card-title:hover { color: var(--accent); text-decoration: none; }

.card-assignees {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid #ffffff;
  margin-left: -4px;
  background: #eaeef2;
}
.avatar:first-child { margin-left: 0; }
.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--fg);
  background: #d8dee4;
}

.card-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
}

.card-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.label-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
  white-space: nowrap;
}

.card-comments {
  font-size: 11px;
  color: var(--fg-muted);
  white-space: nowrap;
}

.priority-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 0 5px;
  border-radius: 4px;
}
.priority-p0 { background: #ffebe9; color: #cf222e; }
.priority-p1 { background: #fff8c5; color: #9a6700; }
.priority-p2 { background: #ddf4ff; color: #0969da; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27, 31, 36, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 20px;
}
.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;
}

/* Chip selector */
.chip-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-subtle);
  max-height: 150px;
  overflow-y: auto;
}
.chip-selector.compact { max-height: 130px; }
.chip-option {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}
.chip-option input { margin: 0; accent-color: var(--accent); }
.assignee-chip {
  font-size: 12px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--border);
}

/* Detail page */
.detail-breadcrumb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  font-size: 13px;
}
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}
.detail-header-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.detail-header-card h1 {
  margin: 8px 0 6px;
  font-size: 21px;
  line-height: 1.3;
}
.detail-meta-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}
.meta-chip {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

/* Panels */
.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-muted);
}
.panel-header h2 { margin: 0; font-size: 15px; }
.panel-body { padding: 16px; }

.divider { border: 0; border-top: 1px solid var(--border-muted); margin: 16px 0; }

/* Markdown */
.markdown-body { font-size: 14px; line-height: 1.6; word-wrap: break-word; }
.markdown-body p:first-child { margin-top: 0; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body pre {
  background: var(--bg-subtle);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
}
.markdown-body code {
  background: rgba(175, 184, 193, 0.2);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 12.5px;
}
.markdown-body pre code { background: transparent; padding: 0; }
.markdown-body blockquote {
  margin: 8px 0;
  padding: 2px 12px;
  border-left: 3px solid var(--border);
  color: var(--fg-muted);
}

/* Comments */
.comment-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.comment-item {
  border: 1px solid var(--border-muted);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--bg-subtle);
}
.comment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 12.5px;
}
.comment-form { border-top: 1px solid var(--border-muted); padding-top: 14px; }

/* Admin */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.admin-header h1 { margin: 0; font-size: 22px; }
.admin-header .muted { margin: 2px 0 0; font-size: 13px; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.tab {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--fg); text-decoration: none; }
.tab.active { color: var(--fg); font-weight: 600; border-bottom-color: #fd8c73; }

.admin-split {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.inline-filter {
  display: flex;
  align-items: center;
  gap: 8px;
}
.inline-filter input { width: 200px; }
.inline-filter select { width: auto; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-muted);
  vertical-align: middle;
}
.data-table th { background: var(--bg-subtle); font-weight: 600; font-size: 12px; color: var(--fg-muted); }
.table-title { font-weight: 500; color: var(--fg); }
.actions-cell { white-space: nowrap; }
.inline-edit-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-gray { background: #eaeef2; color: var(--fg-muted); }

/* Toast */
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #24292f;
  color: #ffffff;
  padding: 9px 14px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 200;
}

@media (max-width: 900px) {
  .detail-layout, .admin-split { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
