/* ============================= Base ============================= */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* Elements toggled via the [hidden] attribute must keep display:none working:
   overlays default to display:none, and this belt-and-braces rule prevents
   author rules like .btn { display:inline-flex } from overriding [hidden]. */
[hidden] { display: none !important; }

/* ============================= Buttons ============================= */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 13px; background: none; white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { color: var(--text-muted); border-color: var(--border); background: var(--surface); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }

.btn-danger-ghost { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }

.btn-sm { padding: 5px 9px; font-size: 12.5px; }

.btn-icon { padding: 8px; }
.btn-icon svg { width: 18px; height: 18px; }

/* ============================= Top bar ============================= */
.topbar {
  flex: none;
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-height);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 9px; margin-right: 6px; }
.brand h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: 0.2px; }
.brand-icon { width: 20px; height: 20px; fill: var(--accent); }

.topbar-spacer { flex: 1; }

.search-wrap { position: relative; flex: 0 1 300px; min-width: 160px; }
.search-wrap .field-icon {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; fill: var(--text-muted); pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 8px 30px 8px 30px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
#search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
#search-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.filter-field select {
  padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  max-width: 170px;
}
.filter-field select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; font-size: 11px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
}

/* ============================= Board ============================= */
.board {
  flex: 1;
  display: flex; align-items: flex-start; gap: 14px;
  padding: 18px 16px 24px;
  overflow-x: auto; overflow-y: hidden;
}

.board-empty {
  margin: auto; text-align: center; color: var(--text-muted);
  max-width: 380px; padding: 40px;
}
.board-empty h2 { color: var(--text); margin: 0 0 8px; font-size: 18px; }
.board-empty p { margin: 0 0 18px; line-height: 1.5; }
.board-empty svg { width: 56px; height: 56px; fill: var(--border-strong); margin-bottom: 12px; }

/* ============================= Column ============================= */
.column {
  flex: none;
  width: var(--column-width);
  max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.column-header {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
}
.column-header:active { cursor: grabbing; }
.column.dragging-source { opacity: 0.45; }

/* column reorder drop indicators */
.column.reorder-before { box-shadow: inset 4px 0 0 var(--accent); }
.column.reorder-after { box-shadow: inset -4px 0 0 var(--accent); }

/* card drop insertion line inside a column body */
.drop-indicator {
  height: 0; flex: none;
  border-top: 2px dashed var(--accent);
  margin: -2px 0 6px;
}

.column-grip { fill: var(--text-muted); width: 14px; height: 18px; flex: none; opacity: 0.6; }
.column-header:hover .column-grip { opacity: 1; }

.column-title-input {
  flex: 1; min-width: 0;
  font-weight: 650; font-size: 14px;
  padding: 4px 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.column-title-input:hover { border-color: var(--border); }
.column-title-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.column.rename-error .column-title-input { border-color: var(--danger); }

.column-count {
  flex: none; font-size: 11.5px; font-weight: 700; color: var(--text-muted);
  background: var(--surface-3); border-radius: 9px; padding: 2px 8px;
}

.column-menu-btn {
  flex: none; border: none; background: none; border-radius: var(--radius-sm);
  padding: 4px 6px; color: var(--text-muted); font-size: 16px; line-height: 1;
}
.column-menu-btn:hover { background: var(--surface-3); color: var(--text); }

.column-body {
  flex: 1; min-height: 40px; max-height: 100%;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; overflow-y: auto;
}
.column-body.drag-over { background: var(--card-drag-ghost); border-radius: 0 0 var(--radius) var(--radius); }

.column-footer { padding: 4px 10px 12px; }
.add-card-btn {
  width: 100%; justify-content: flex-start;
  border: 1px dashed var(--border-strong); color: var(--text-muted);
  background: none; border-radius: var(--radius-sm); padding: 8px 10px;
}
.add-card-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.add-card-btn svg { width: 14px; height: 14px; }
.column-add-ghost { height: 46px; flex: none; align-self: stretch; }

.column-empty {
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 12.5px; text-align: center;
  padding: 18px 10px; line-height: 1.4;
}

/* ============================= Card ============================= */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.card:active { cursor: grabbing; }
.card.dragging { opacity: 0.5; }

.card-title { font-weight: 600; line-height: 1.35; word-break: break-word; }
.card-desc {
  margin-top: 4px; color: var(--text-muted); font-size: 12.5px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; white-space: pre-line; word-break: break-word;
}
.card-meta { margin-top: 8px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.card-label {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 650;
  color: #fff; background: var(--label-color, var(--accent));
  border-radius: 99px; padding: 2px 8px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* labels that are too light get dark text (class set by JS) */
.card-label.label-on-light { color: #1b2130; }

.card-assignee {
  display: inline-flex; align-items: center; gap: 5px;
  margin-left: auto; font-size: 11.5px; color: var(--text-muted);
  max-width: 100%;
}
.avatar {
  width: 19px; height: 19px; flex: none; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
}
.avatar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Done-column completion indicator */
.card.is-done { border-left-color: var(--success); }
.card.is-done .card-title { color: var(--text-muted); text-decoration: line-through; text-decoration-color: var(--border-strong); }
.card.is-done::after {
  content: "✓ Done";
  display: inline-block; margin-top: 6px;
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.4px;
  color: #fff; background: var(--success); border-radius: 99px; padding: 1px 8px;
}

/* highlight cards matched by an active search (subtle cue, cards are otherwise just filtered) */
mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ============================= Modal ============================= */
.modal-overlay {
  display: none;                 /* hidden by default; [hidden] stays consistent */
  position: fixed; inset: 0; z-index: 100;
  background: var(--overlay);
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay:not([hidden]) { display: flex; }

.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: pop var(--transition);
}
.modal-sm { max-width: 400px; }
@keyframes pop { from { transform: scale(0.97); opacity: 0; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 16px; }

.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px 16px;
}
.modal-footer-spacer { flex: 1; }

.field { display: block; margin-bottom: 14px; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; min-width: 0; }
.field-label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.4px; }
.req { color: var(--danger); }
.input {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 84px; }
.field-error { display: block; margin-top: 5px; color: var(--danger); font-size: 12px; }

.label-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.label-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 99px;
  padding: 5px 11px; background: var(--surface-2); font-size: 12.5px; font-weight: 600;
  transition: border-color var(--transition), background var(--transition);
}
.label-chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--label-color, var(--accent)); flex: none; }
.label-chip .check { display: none; font-weight: 900; }
.label-chip.selected { background: color-mix(in srgb, var(--label-color) 16%, transparent); border-color: var(--label-color); }
.label-chip.selected .check { display: inline; }

.confirm-message { margin: 0; line-height: 1.55; color: var(--text-muted); }
.confirm-message strong { color: var(--text); }

/* ============================= Archive panel ============================= */
.panel-backdrop {
  display: none;
  position: fixed; inset: 0; background: var(--overlay); z-index: 110;
}
.panel-backdrop:not([hidden]) { display: block; }

.panel {
  display: none;
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 120;
  width: 440px; max-width: 92vw;
  flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: slide-in 160ms ease;
}
.panel:not([hidden]) { display: flex; }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.panel-header h2 { margin: 0; font-size: 16px; }

.panel-tabs { display: flex; gap: 4px; padding: 10px 14px 0; border-bottom: 1px solid var(--border); }
.tab {
  border: none; background: none; padding: 8px 12px;
  color: var(--text-muted); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel-body { flex: 1; overflow-y: auto; padding: 12px 14px 20px; display: flex; flex-direction: column; gap: 8px; }

.archive-item {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 10px 12px;
}
.archive-item .ai-head { display: flex; align-items: center; gap: 8px; }
.archive-item .ai-title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.archive-item .ai-sub { margin-top: 3px; font-size: 12px; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.archive-item .ai-actions { display: flex; gap: 6px; margin-top: 9px; }
.ai-col-tag { font-size: 11px; background: var(--surface-3); border-radius: 99px; padding: 1px 8px; }

.panel-empty {
  margin: auto; text-align: center; color: var(--text-muted); padding: 30px;
}
.panel-empty svg { width: 44px; height: 44px; fill: var(--border-strong); display: block; margin: 0 auto 10px; }

/* ============================= Toasts ============================= */
.toast-container {
  position: fixed; right: 16px; bottom: 16px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 10px 14px; font-size: 13px;
  animation: toast-in 180ms ease;
  pointer-events: auto;
  max-width: 380px;
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-danger { border-left-color: var(--danger); }
.toast button {
  border: none; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; border-radius: var(--radius-sm); padding: 4px 10px; font-size: 12px;
}
.toast button:hover { background: var(--accent); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.toast.hiding { transition: opacity 250ms, transform 250ms; opacity: 0; transform: translateY(4px); }

/* ============================= Scrollbars ============================= */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); border: 2px solid transparent; background-clip: content-box; }

/* ============================= Narrow screens ============================= */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; }
  .brand { display: none; }
}
