/* ===== CSS Custom Properties ===== */
:root {
  --bg-primary: #f6f8fa;
  --bg-secondary: #ffffff;
  --bg-column: #f0f2f5;
  --bg-card: #ffffff;
  --bg-card-hover: #fafbfc;
  --bg-modal: #ffffff;
  --bg-overlay: rgba(0, 0, 0, 0.4);
  --bg-input: #ffffff;
  --bg-header: #ffffff;

  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-tertiary: #8b949e;
  --text-link: #0969da;

  --border-default: #d0d7de;
  --border-muted: #d8dee4;

  --btn-primary-bg: #2da44e;
  --btn-primary-text: #ffffff;
  --btn-secondary-bg: #f6f8fa;
  --btn-secondary-text: #24292f;
  --btn-danger-bg: #cf222e;
  --btn-danger-text: #ffffff;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 3px 12px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.16);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --card-max-height: 300px;

  --drag-opacity: 0.5;
  --drop-highlight: #ddf4ff;

  --state-open: #2da44e;
  --state-closed: #8250df;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-column: #161b22;
    --bg-card: #1c2128;
    --bg-card-hover: #252b35;
    --bg-modal: #1c2128;
    --bg-overlay: rgba(0, 0, 0, 0.6);
    --bg-input: #0d1117;
    --bg-header: #161b22;

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-tertiary: #6e7681;
    --text-link: #58a6ff;

    --border-default: #30363d;
    --border-muted: #21262d;

    --btn-primary-bg: #238636;
    --btn-primary-text: #ffffff;
    --btn-secondary-bg: #21262d;
    --btn-secondary-text: #c9d1d9;
    --btn-danger-bg: #da3633;
    --btn-danger-text: #ffffff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 3px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

    --drop-highlight: #1a3a52;
  }
}

/* ===== Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-default);
  gap: 16px;
  flex-shrink: 0;
}

.header-left {
  flex-shrink: 0;
}

.logo {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 480px;
  margin: 0 auto;
}

.filter-bar {
  display: flex;
  align-items: center;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0 10px;
  transition: border-color 0.15s;
}

.filter-bar:focus-within {
  border-color: var(--text-link);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

.filter-icon {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.filter-input {
  border: none;
  background: transparent;
  padding: 8px;
  font-size: 14px;
  color: var(--text-primary);
  width: 100%;
  outline: none;
}

.filter-input::placeholder {
  color: var(--text-tertiary);
}

.header-right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ===== Buttons ===== */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--bg-column);
  color: var(--text-primary);
}

.btn {
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border-color: transparent;
}

.btn-primary:hover {
  filter: brightness(0.9);
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
}

.btn-secondary:hover {
  background: var(--border-muted);
}

.btn-danger {
  background: var(--btn-danger-bg);
  color: var(--btn-danger-text);
  border-color: transparent;
}

.btn-danger:hover {
  filter: brightness(0.9);
}

/* ===== Notes Section ===== */
.notes-section {
  padding: 0 20px;
  flex-shrink: 0;
}

.notes-header {
  display: flex;
  align-items: center;
}

.notes-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}

.notes-toggle:hover {
  color: var(--text-primary);
}

.notes-chevron {
  transition: transform 0.15s;
}

.notes-section.open .notes-chevron {
  transform: rotate(90deg);
}

.notes-body {
  display: none;
  padding-bottom: 12px;
}

.notes-section.open .notes-body {
  display: block;
}

.notes-textarea {
  width: 100%;
  height: 120px;
  resize: vertical;
  max-height: 250px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  outline: none;
  tab-size: 2;
}

.notes-textarea:focus {
  border-color: var(--text-link);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

/* ===== Links Widget (header popover) ===== */
.links-widget {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
}

.links-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.links-toggle:hover {
  background: var(--bg-column);
  color: var(--text-primary);
}

.links-count {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-column);
  border-radius: 10px;
  padding: 0 6px;
  min-width: 18px;
  text-align: center;
  line-height: 18px;
}

.btn-add-link {
  color: var(--text-tertiary);
  padding: 4px;
}

.btn-add-link:hover {
  color: var(--text-primary);
}

.links-popover {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  width: 480px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg-modal);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  z-index: 100;
}

.links-widget.open .links-popover {
  display: block;
}

.links-search-bar {
  margin-bottom: 8px;
}

.links-search-bar .links-input {
  width: 100%;
}

.links-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.links-categories:empty {
  display: none;
}

.links-cat-pill {
  padding: 2px 10px;
  font-size: 12px;
  border-radius: 12px;
  border: 1px solid var(--border-default);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.links-cat-pill:hover {
  background: var(--bg-column);
  color: var(--text-primary);
}

.links-cat-pill.active {
  background: var(--text-link);
  color: #fff;
  border-color: var(--text-link);
}

.links-input-cat {
  min-width: 100px;
  flex: 0.6;
}

.link-cat-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 400;
  border-radius: 10px;
  background: var(--bg-column);
  color: var(--text-secondary);
  line-height: 18px;
  vertical-align: middle;
}

.links-add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.links-input {
  flex: 1;
  min-width: 120px;
  padding: 5px 10px;
  font-size: 13px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
}

.links-input:focus {
  border-color: var(--text-link);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

.links-form-actions {
  display: flex;
  gap: 6px;
}

.links-table {
  width: 100%;
  border-collapse: collapse;
}

.links-table td {
  padding: 5px 8px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-muted);
  vertical-align: middle;
}

.links-table tr:last-child td {
  border-bottom: none;
}

.links-table .link-title-cell {
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
}

.links-table .link-url-cell {
  color: var(--text-link);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 0;
  width: 100%;
}

.links-table .link-url-cell a {
  color: var(--text-link);
  text-decoration: none;
}

.links-table .link-url-cell a:hover {
  text-decoration: underline;
}

.links-table .link-actions-cell {
  width: 30px;
  text-align: right;
}

.links-table .link-actions-cell .btn-icon {
  opacity: 0;
  padding: 2px;
  color: var(--text-tertiary);
}

.links-table tr:hover .link-actions-cell .btn-icon {
  opacity: 1;
}

.links-table .link-actions-cell .btn-icon:hover {
  color: var(--btn-danger-bg);
}

.links-empty {
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
  padding: 16px 12px;
  border: 2px dashed var(--border-muted);
  border-radius: var(--radius-md);
}

.btn-sm {
  padding: 3px 10px;
  font-size: 12px;
}

/* ===== Board ===== */
.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 20px;
  flex: 1;
  overflow-x: auto;
  min-height: 0;
}

.column {
  background: var(--bg-column);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-width: 260px;
  min-height: 0;
}

.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  flex-shrink: 0;
}

.column-title-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.column-title {
  font-size: 14px;
  font-weight: 600;
}

.column-subtitle {
  font-size: 11px;
  color: var(--text-tertiary);
}

.column-count {
  font-size: 12px;
  color: var(--text-tertiary);
  background: var(--bg-card);
  border-radius: 10px;
  padding: 0 7px;
  min-width: 20px;
  text-align: center;
  line-height: 20px;
}

.btn-add {
  color: var(--text-tertiary);
}

.btn-add:hover {
  color: var(--text-primary);
}

/* ===== Card List ===== */
.card-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}

.card-list.drag-over {
  background: var(--drop-highlight);
  border-radius: var(--radius-md);
}

.empty-state {
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
  padding: 24px 12px;
  border: 2px dashed var(--border-muted);
  border-radius: var(--radius-md);
  user-select: none;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: grab;
  position: relative;
  transition: box-shadow 0.15s, opacity 0.15s;
  max-height: var(--card-max-height);
  display: flex;
  flex-direction: column;
}

.card:hover {
  box-shadow: var(--shadow-sm);
  background: var(--bg-card-hover);
}

.card.dragging {
  opacity: var(--drag-opacity);
}

.card-color-strip {
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 2px;
}

.card.has-color {
  padding-left: 18px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

.card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  margin: -2px -2px 0 0;
}

.card-action {
  flex-shrink: 0;
  padding: 2px;
}

.card-action-delete:hover {
  color: var(--btn-danger-bg);
}

.card-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  word-break: break-word;
  overflow: hidden;
}

.card-body p {
  margin: 0 0 8px;
}

.card-body p:last-child {
  margin-bottom: 0;
}

.card-body code {
  background: var(--bg-column);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

.card-body pre {
  background: var(--bg-column);
  padding: 8px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 12px;
  margin: 4px 0;
}

/* GitHub Issue card specifics */
.card-issue-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border-muted);
}

.card-issue-link {
  font-size: 12px;
  color: var(--text-tertiary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-issue-link:hover {
  color: var(--text-link);
}

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

.issue-state-dot.open {
  background: var(--state-open);
}

.issue-state-dot.closed {
  background: var(--state-closed);
}

/* ===== Modals ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.15s ease-out;
}

.modal-sm {
  max-width: 380px;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  font-size: 22px;
  line-height: 1;
}

.modal-tabs {
  display: flex;
  gap: 0;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border-muted);
}

.modal-tab {
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}

.modal-tab.active {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom-color: var(--btn-primary-bg);
}

.modal-tab:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 16px 20px;
}

.modal-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}

.modal-input:focus {
  border-color: var(--text-link);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

.modal-textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  resize: vertical;
  font-family: inherit;
  margin-top: 8px;
  transition: border-color 0.15s;
}

.modal-textarea:focus {
  border-color: var(--text-link);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 16px;
  gap: 8px;
}

.modal-footer-right {
  display: flex;
  gap: 8px;
}

/* ===== Color Picker ===== */
.color-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.color-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.color-options {
  display: flex;
  gap: 6px;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-default);
  cursor: pointer;
  transition: transform 0.1s;
  padding: 0;
}

.color-swatch:first-child {
  background: var(--bg-card);
  position: relative;
}

.color-swatch:first-child::after {
  content: '—';
  font-size: 10px;
  color: var(--text-tertiary);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.color-swatch.active {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

.color-swatch:hover {
  transform: scale(1.15);
}

/* ===== Tab Content ===== */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ===== Issue Preview ===== */
.issue-preview {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.issue-preview .issue-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.issue-preview .issue-meta {
  color: var(--text-tertiary);
  font-size: 12px;
}

.issue-error {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: #ffeef0;
  color: #cf222e;
  font-size: 13px;
}

@media (prefers-color-scheme: dark) {
  .issue-error {
    background: #3d1f24;
    color: #ff7b72;
  }
}

/* ===== Settings ===== */
.settings-label {
  font-size: 14px;
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}

.settings-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

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

.settings-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== Utilities ===== */
.hidden {
  display: none !important;
}

/* ===== Drop zone indicator for between cards ===== */
.drop-indicator {
  height: 3px;
  background: var(--text-link);
  border-radius: 2px;
  margin: -2px 0;
  pointer-events: none;
}

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

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

  .header {
    flex-wrap: wrap;
  }

  .header-center {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }
}

/* ===== Scrollbar styling ===== */
.card-list::-webkit-scrollbar {
  width: 6px;
}

.card-list::-webkit-scrollbar-track {
  background: transparent;
}

.card-list::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

.card-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}
