:root {
  --primary: #cc785c;
  --primary-active: #a9583e;
  --canvas: #faf9f5;
  --card: #efe9de;
  --ink: #141413;
  --body: #3d3d3a;
  --border: #e6dfd8;
  --dark: #181715;
  --on-dark: #faf9f5;
  --ok: #5db872;
  --warn: #d4a017;
  --state-new-bg: #f2ece3;
  --state-working-bg: #fff1da;
  --state-review-bg: #dae9ff;
  --state-done-bg: #dff7e5;
  --state-archived-bg: #ece7e1;
  --layout-max-width: 1400px;
}

body.dark {
  --canvas: #181715;
  --card: #252320;
  --ink: #faf9f5;
  --body: #d5d2cb;
  --border: #37322d;
  --dark: #252320;
  --on-dark: #faf9f5;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  background: var(--canvas);
  color: var(--body);
}
.wrap {
  width: 100%;
  max-width: min(var(--layout-max-width), calc(100vw - 48px));
  margin: 0 auto;
  padding: 24px;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; background: var(--canvas); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo-link { display: inline-flex; align-items: center; }
.logo { height: 44px; }
.brand-sub { font-size: 13px; color: #6c6a64; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--border); background: var(--canvas); color: var(--ink);
  border-radius: 8px; padding: 9px 12px; text-decoration: none; cursor: pointer;
}
.nav-btn.active {
  background: var(--dark);
  color: var(--on-dark);
  border-color: var(--dark);
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-active); }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px;
}
.label { font-size: 13px; display: block; margin-bottom: 6px; color: var(--body); }
input, textarea, select {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; background: var(--canvas); color: var(--ink);
}
input:disabled, textarea:disabled, select:disabled {
  background: #e7e2d9;
  color: #8e8b82;
  border-color: #d8d1c6;
  cursor: not-allowed;
  opacity: 1;
}
textarea { min-height: 100px; }
.issues-board {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px;
}
.col { background: var(--canvas); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.issue {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; margin-bottom: 8px;
}
.issue-link {
  display: block;
  text-decoration: none;
  color: inherit;
}
.issue-link:hover {
  border-color: var(--primary);
}
.muted { color: #8e8b82; font-size: 13px; }
.pill { border-radius: 999px; padding: 3px 9px; font-size: 12px; border: 1px solid var(--border); }
.pill.new { background: var(--state-new-bg); }
.pill.working { background: var(--state-working-bg); }
.pill.review { background: var(--state-review-bg); }
.pill.done { background: var(--state-done-bg); }
.pill.archived { background: var(--state-archived-bg); }
.state-select.state-new { background: var(--state-new-bg); }
.state-select.state-working { background: var(--state-working-bg); }
.state-select.state-review { background: var(--state-review-bg); }
.state-select.state-done { background: var(--state-done-bg); }
.state-select.state-archived { background: var(--state-archived-bg); }
select.state-select:disabled {
  color: var(--ink);
  border-color: var(--border);
  cursor: not-allowed;
  opacity: 1;
}
.danger { background: #c64545; border-color: #c64545; color: #fff; }
.btn-text-danger {
  background: transparent;
  border-color: transparent;
  color: #8e8b82;
  padding-left: 0;
  padding-right: 0;
  text-align: left;
}
.btn-text-danger:hover {
  color: #b35a5a;
}
.icon-btn {
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  min-width: auto;
}
a { color: var(--primary); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.projects-actions {
  display: flex;
  margin-left: auto;
  justify-content: flex-end;
  align-items: center;
}
.projects-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 12px;
  align-items: center;
}
.projects-header h2 {
  margin: 0;
}
.section-title-left {
  margin: 0;
  text-align: left;
}
.project-board-header {
  margin-left: -18px;
  margin-right: -18px;
}
.projects-header .projects-actions {
  justify-self: end;
}
.section-title-spaced {
  margin-bottom: 10px;
}
.projects-list-grid {
  margin-top: 10px;
}
.user-chip { display: inline-flex; align-items: center; gap: 8px; }
.current-user {
  display: inline-block;
  position: relative;
}
.current-user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  min-height: 38px;
  cursor: pointer;
}
.current-user .avatar,
.current-user .avatar-sm {
  width: 24px;
  height: 24px;
}
.current-user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: none;
  min-width: 220px;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  padding: 10px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.15);
  z-index: 35;
}
.current-user.open .current-user-menu {
  display: grid;
}
.current-user-menu .inline-control {
  width: 100%;
  justify-content: space-between;
}
.inline-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}
.inline-control span {
  font-size: 12px;
  color: var(--body);
}
.inline-control select {
  min-width: 78px;
  padding: 6px 8px;
  border-radius: 6px;
}
.page-content {
  display: grid;
  gap: 18px;
}
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  padding-bottom: 16px;
}
.footer-admin-link {
  color: #8e8b82;
  font-size: 12px;
  text-decoration: none;
  opacity: 0.75;
}
.footer-admin-link:hover {
  opacity: 1;
}
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--body);
  font-size: 13px;
}
.crumb-sep {
  color: #8e8b82;
}
.stats {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.stat-card {
  display: grid;
  gap: 4px;
}
.stat-link {
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.stat-link:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}
.recent-issue-link {
  padding: 8px 10px;
}
.recent-issue-main {
  justify-content: space-between;
  gap: 12px;
}
.recent-issue-title {
  min-width: 0;
}
.recent-issue-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.recent-issue-sep {
  opacity: 0.7;
}
.stat-value {
  color: var(--ink);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border); background: var(--canvas); display: inline-block;
}
.avatar-sm {
  width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); font-size: 11px; color: var(--ink);
  background: var(--canvas); font-weight: 700;
}
.meta-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.board-issue {
  display: grid;
  gap: 6px;
}
.board-issue-title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-issue-title a {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.board-issue-owner .user-chip {
  max-width: 100%;
}
.board-issue-owner .user-chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.issue-section-title {
  margin-top: 18px;
}
.comment-item {
  margin-top: 10px;
}
.comment-body {
  margin-top: 0.25rem;
}
.mention-compose {
  position: relative;
}
.mention-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}
.mention-suggest[hidden] {
  display: none;
}
.mention-suggest-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.mention-suggest-item:hover,
.mention-suggest-item.is-active {
  background: var(--card);
}
.mention-suggest-handle {
  margin-left: auto;
  font-size: 12px;
  color: #6c6a64;
}
.mention-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(204, 120, 92, 0.14);
  border: 1px solid rgba(204, 120, 92, 0.35);
  border-radius: 999px;
  padding: 0 7px 0 3px;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.92em;
  line-height: 1.4;
  vertical-align: middle;
  margin: 0 2px;
  white-space: nowrap;
}
body.dark .mention-chip {
  background: rgba(204, 120, 92, 0.22);
  border-color: rgba(204, 120, 92, 0.45);
}
.mention-chip-avatar {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--canvas);
  flex-shrink: 0;
}
.mention-chip-emoji {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
}
.mention-chip-name {
  line-height: inherit;
}
.comment-body :first-child {
  margin-top: 0;
}
.comment-body :last-child {
  margin-bottom: 0;
}
.comment-body p {
  margin: 8px 0;
}
.comment-body h1,
.comment-body h2,
.comment-body h3,
.comment-body h4,
.comment-body h5,
.comment-body h6,
.issue-description-preview h1,
.issue-description-preview h2,
.issue-description-preview h3,
.issue-description-preview h4,
.issue-description-preview h5,
.issue-description-preview h6 {
  color: var(--ink);
  font-weight: 700;
  line-height: 1.3;
  margin: 14px 0 8px;
}
.comment-body h1,
.issue-description-preview h1 {
  font-size: 1.5rem;
}
.comment-body h2,
.issue-description-preview h2 {
  font-size: 1.25rem;
}
.comment-body h3,
.issue-description-preview h3 {
  font-size: 1.1rem;
}
.comment-body h4,
.comment-body h5,
.comment-body h6,
.issue-description-preview h4,
.issue-description-preview h5,
.issue-description-preview h6 {
  font-size: 1rem;
}
.comment-body ul,
.comment-body ol {
  margin: 8px 0 8px 0;
  padding-left: 1.5em;
  list-style-position: outside;
}
.comment-body ul {
  list-style-type: disc;
}
.comment-body ol {
  list-style-type: decimal;
}
.comment-body li {
  display: list-item;
  margin: 3px 0;
}
.comment-body ul ul {
  list-style-type: circle;
}
.comment-body ul ul ul {
  list-style-type: square;
}
.comment-body blockquote {
  margin: 8px 0;
  padding: 8px 10px;
  border-left: 3px solid var(--border);
  background: rgba(0, 0, 0, 0.03);
  border-radius: 8px;
}
body.dark .comment-body blockquote {
  background: rgba(255, 255, 255, 0.05);
}
.comment-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12.5px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 6px;
}
body.dark .comment-body code {
  background: rgba(255, 255, 255, 0.08);
}
.comment-body pre {
  overflow: auto;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--canvas);
}
.comment-body pre code {
  background: transparent;
  padding: 0;
}

.issue-description-preview {
  height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--canvas);
  color: var(--ink);
  cursor: pointer;
}
.issue-description-preview:hover {
  border-color: var(--primary);
}
.issue-description-preview p {
  margin: 8px 0;
}
.issue-description-preview ul,
.issue-description-preview ol {
  margin: 8px 0 8px 0;
  padding-left: 1.5em;
  list-style-position: outside;
}
.issue-description-preview ul {
  list-style-type: disc;
}
.issue-description-preview ol {
  list-style-type: decimal;
}
.issue-description-preview li {
  display: list-item;
  margin: 3px 0;
}
.issue-description-preview ul ul {
  list-style-type: circle;
}
.issue-description-preview ul ul ul {
  list-style-type: square;
}
.issue-description-preview pre {
  overflow: auto;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--canvas);
}
.issue-description-textarea {
  height: 300px;
  overflow-y: auto;
  resize: none;
  min-height: 0;
}
.issue-description-textarea,
.issue-description-preview {
  scrollbar-gutter: stable;
}
.date-field {
  position: relative;
}
.date-field input[type="date"] {
  width: 100%;
}
.date-field.is-empty input[type="date"] {
  color: transparent;
}
.date-field.is-empty input[type="date"]::-webkit-datetime-edit {
  color: transparent;
}
.date-field-placeholder {
  display: none;
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #8e8b82;
  pointer-events: none;
  font-size: inherit;
}
.date-field.is-empty .date-field-placeholder {
  display: block;
}
.timeline-toggle {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.timeline-toggle:hover {
  color: var(--primary);
}
.issue-meta-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 12px 20px;
  margin-bottom: 10px;
}
.issue-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.tab {
  display: inline-flex;
  align-items: center;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--canvas);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
}
.tab.active {
  background: var(--dark);
  color: var(--on-dark);
  border-color: var(--dark);
}
.issues-table {
  display: grid;
  grid-template-columns: 80px minmax(190px, 2fr) minmax(170px, 1.2fr) 120px minmax(170px, 1.2fr) 150px;
  gap: 8px 10px;
  align-items: center;
}
.issues-table > div {
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 42px;
  display: flex;
  align-items: center;
}
.issues-head {
  background: transparent !important;
  border: none !important;
  padding: 0 2px !important;
  min-height: auto !important;
  font-size: 12px;
  font-weight: 700;
  color: var(--body);
}
.issues-empty {
  grid-column: 1 / -1;
}
.form-row-triple {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}
.form-row-triple .label {
  margin-bottom: 0;
}
.card-narrow { max-width: 760px; }
.issue-detail-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 0;
}
.issue-done-check {
  font-size: 1em;
  line-height: inherit;
  flex-shrink: 0;
}
.issue-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 18px;
  align-items: start;
}
.issue-sidebar {
  position: sticky;
  top: 104px;
  display: grid;
  gap: 10px;
}
.issue-sidebar .issue-meta-strip {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}
.issue-sidebar .issue-meta-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  width: 100%;
  align-items: center;
  gap: 12px;
}
.issue-sidebar .issue-meta-item .muted {
  min-width: 72px;
}
.issue-sidebar .issue-meta-item .user-chip {
  justify-self: start;
}
.issue-sidebar .btn {
  width: 100%;
}
.issue-sidebar .btn.btn-text-danger {
  width: auto;
  justify-self: start;
  background: transparent;
  border: 0;
  padding: 0;
  color: #8e8b82;
  font-size: 12px;
  opacity: 0.75;
}
.issue-sidebar .btn.btn-text-danger:hover {
  color: #8e8b82;
  opacity: 1;
}
.issue-sidebar form {
  margin: 0;
}
.files-upload-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}
.files-upload-form input[type="file"] {
  width: auto;
  max-width: 100%;
  min-width: 280px;
}
.login-wrap {
  max-width: 520px;
  padding-top: 8vh;
}
.login-wrap .remember-login {
  margin: 2px 0 4px;
}
.login-wrap .remember-login input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
}
.login-error {
  border-color: #c64545;
}

@media (max-width: 920px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .actions {
    width: 100%;
  }
  .inline-control {
    flex: 1 1 220px;
  }
  .current-user {
    order: 98;
  }
  .current-user-menu {
    right: auto;
    left: 0;
  }
  .issues-table {
    grid-template-columns: 1fr;
  }
  .issues-head {
    display: none !important;
  }
  .form-row-triple {
    grid-template-columns: 1fr;
  }
  .issue-layout {
    grid-template-columns: 1fr;
  }
  .issue-sidebar {
    position: static;
  }
  .files-upload-form input[type="file"] {
    width: 100%;
    min-width: 0;
  }
  .projects-header {
    display: flex;
    flex-wrap: wrap;
  }
  .projects-actions {
    width: 100%;
    justify-content: flex-start;
    margin-left: 0;
  }
}
