/* ---------- Tokens ---------- */
:root {
  --bg: #f4f5f4;
  --surface: #fdfdfc;
  --surface-raised: #ffffff;
  --border: #e2e4e1;
  --border-strong: #cdd0cc;
  --text: #16181a;
  --text-muted: #585e60;
  --text-faint: #85898a;

  --accent: #2a52c9;
  --accent-hover: #2244a8;
  --accent-contrast: #fdfdfc;
  --accent-soft: #e7edfb;

  --status-todo: #5b6268;
  --status-todo-bg: #eceeef;
  --status-inprogress: #8a5110;
  --status-inprogress-bg: #fbeed9;
  --status-blocked: #b3261e;
  --status-blocked-bg: #fbe4e2;
  --status-done: #166238;
  --status-done-bg: #e2f2e7;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-card: 0 1px 2px rgba(20, 22, 20, 0.06), 0 1px 1px rgba(20, 22, 20, 0.04);
  --shadow-panel: -8px 0 32px rgba(20, 22, 20, 0.12);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --surface: #1d2022;
    --surface-raised: #232629;
    --border: #33373a;
    --border-strong: #43484b;
    --text: #f1f2f0;
    --text-muted: #aeb3b3;
    --text-faint: #7c8181;

    --accent: #6f93ef;
    --accent-hover: #89a7f3;
    --accent-contrast: #10141c;
    --accent-soft: #202a44;

    --status-todo: #b7bcc0;
    --status-todo-bg: #2b2e31;
    --status-inprogress: #e3ac59;
    --status-inprogress-bg: #3a2d16;
    --status-blocked: #f0938c;
    --status-blocked-bg: #3d201f;
    --status-done: #7ed6a3;
    --status-done-bg: #1c3325;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-panel: -8px 0 32px rgba(0, 0, 0, 0.5);
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, dl, dd, dt { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
button { font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Layout shell ---------- */
.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand__mark { color: var(--accent); display: inline-flex; }
.brand__name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand__tagline {
  color: var(--text-faint);
  font-size: 14px;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 24px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.field--search { flex: 1 1 260px; min-width: 200px; }
.field--filter { flex: 0 0 200px; }

input#search-input,
select#filter-select {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text);
}
input#search-input::placeholder { color: var(--text-faint); }

select#filter-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 20 20'%3E%3Cpath d='M5 8l5 5 5-5' fill='none' stroke='%23585e60' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.toolbar__count {
  color: var(--text-faint);
  font-size: 13px;
  font-family: var(--font-mono);
  margin-left: auto;
  align-self: center;
}

/* ---------- Board ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}
.board.board--single {
  grid-template-columns: minmax(0, 1fr);
  max-width: 640px;
}

.column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.column__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
}
.column__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: none;
}
.column__header h2 {
  font-size: 14px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
}
.column__count {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-faint);
}

.column__list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- Card ---------- */
.card {
  position: relative;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 13px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 3px 10px rgba(20, 22, 20, 0.08);
}
.card:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card__open {
  all: unset;
  cursor: pointer;
}
.card__open::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.card__open:focus-visible {
  outline: none;
}

.card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: 5px;
}
.badge--priority-high { background: var(--status-blocked-bg); color: var(--status-blocked); }
.badge--priority-medium { background: var(--status-inprogress-bg); color: var(--status-inprogress); }
.badge--priority-low { background: var(--status-todo-bg); color: var(--status-todo); }

.card__due {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
}
.card__due--overdue {
  color: var(--status-blocked);
  font-weight: 600;
}

.card__title {
  font-size: 14.5px;
  font-weight: 650;
  line-height: 1.35;
  margin-bottom: 6px;
  color: var(--text);
}

.card__summary {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.card__project { font-weight: 600; color: var(--text-muted); }

.card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag {
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 72px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  max-width: 480px;
  margin: 0 auto;
}
.empty-state__title {
  font-size: 16px;
  font-weight: 650;
  margin-bottom: 6px;
}
.empty-state__hint {
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn--secondary {
  background: var(--surface-raised);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn--secondary:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Detail dialog ---------- */
dialog.detail {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  height: 100dvh;
  max-height: 100dvh;
  width: min(460px, 100vw);
  border: none;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-panel);
}
dialog.detail::backdrop {
  background: rgba(10, 12, 10, 0.38);
}

@media (prefers-reduced-motion: no-preference) {
  dialog.detail {
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.24s ease, display 0.24s allow-discrete, overlay 0.24s allow-discrete;
    transform: translateX(24px);
    opacity: 0;
  }
  dialog.detail[open] {
    transform: translateX(0);
    opacity: 1;
  }
  @starting-style {
    dialog.detail[open] {
      transform: translateX(24px);
      opacity: 0;
    }
  }
  dialog.detail::backdrop {
    transition: background-color 0.24s ease;
  }
}

.detail__inner {
  height: 100%;
  overflow-y: auto;
  padding: 20px 24px 36px;
}

.detail__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.detail__status-badge {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 9px;
  border-radius: 6px;
}

.detail__close {
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  cursor: pointer;
  color: var(--text-muted);
}
.detail__close:hover { color: var(--text); border-color: var(--border-strong); }

.detail__title {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-bottom: 18px;
}

.detail__meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.detail__meta dt {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.detail__meta dd {
  font-size: 13.5px;
  color: var(--text);
  font-weight: 550;
}

.detail__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.field--status-control {
  margin-bottom: 22px;
  gap: 8px;
}
.field--status-control select {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 20 20'%3E%3Cpath d='M5 8l5 5 5-5' fill='none' stroke='%23585e60' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.detail__feedback {
  font-size: 12.5px;
  color: var(--status-done);
  font-weight: 600;
  min-height: 16px;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.detail__feedback.is-visible { opacity: 1; }

.detail__body {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.65;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.detail__body p + p { margin-top: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app { padding: 20px 16px 40px; }
  .board { grid-template-columns: minmax(0, 1fr); }
  .board.board--single { max-width: none; }
  .toolbar__count { margin-left: 0; order: 3; flex-basis: 100%; }
  dialog.detail { width: 100vw; }
  .detail__meta { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 420px) {
  .detail__meta { grid-template-columns: 1fr; }
}
