/* ─── Design tokens — Light (default) ───────────────────────────────────── */
:root {
  --bg:           #f5f6f8;
  --surface:      #ffffff;
  --border:       #e5e7eb;
  --text:         #1f2328;
  --muted:        #57606a;
  --accent:       #3b82d4;
  --accent-hover: #2563b5;
  --danger:       #d94f4f;
  --green:        #2da44e;
  --radius:       8px;
}

/* ─── Design tokens — Dark ───────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #0d1117;
  --surface:      #161b22;
  --border:       #30363d;
  --text:         #e6edf3;
  --muted:        #8b949e;
  --accent:       #58a6ff;
  --accent-hover: #79b8ff;
  --danger:       #f85149;
  --green:        #3fb950;
}

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

/* ─── Base ───────────────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
/* ─── Sticky header block (header row + toolbar row, zero gap) ───────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.site-logo {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.3px;
  flex-shrink: 0;
  white-space: nowrap;
}
.site-logo a {
  text-decoration: none;
  color: inherit;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* On desktop the search bar floats right; the header-right cluster follows it */
@media (min-width: 769px) {
  .search-wrap { margin-left: auto; }
}

/* ─── Search bar ─────────────────────────────────────────────────────────── */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px 4px 12px;
  width: 260px;
  transition: border-color .15s, box-shadow .15s;
}
.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.search-icon {
  display: flex;
  align-items: center;
  color: var(--muted);
  flex-shrink: 0;
  user-select: none;
}
.search-icon svg { display: block; }
#widget-search {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text);
  outline: none;
  padding: 0;
  min-width: 0;
}
#widget-search::placeholder { color: var(--muted); }
#widget-search::-webkit-search-cancel-button { display: none; }
.search-clear {
  display: none;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 11px;
  border-radius: 50%;
  background: var(--muted);
  color: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
  border: none;
  transition: background .1s;
}
.search-clear:hover { background: var(--danger); }

/* Mobile search-icon button — hidden on desktop */
.search-icon-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
  padding: 0;
  transition: color .15s;
}
.search-icon-btn svg { display: block; }
.search-icon-btn:hover { color: var(--text); }

/* Close button inside expanded search — hidden by default */
.search-close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: color .1s, background .1s;
}
.search-close-btn:hover { background: var(--bg); color: var(--text); }

/* ─── Search highlight ───────────────────────────────────────────────────── */
mark.search-highlight {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ─── No-results message ─────────────────────────────────────────────────── */
.search-no-results {
  display: none;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 40px 20px;
}

/* ─── Card hidden by search ──────────────────────────────────────────────── */
.card[style*="display: none"] { pointer-events: none; }

/* Shrink search on mid-size screens */
@media (max-width: 900px) {
  .search-wrap { width: 200px; }
}
@media (max-width: 768px) {
  /* Below 768px: hide full search bar, show icon-only button instead */
  .search-wrap  { display: none; }
  .search-icon-btn { display: flex; }
}

/* ─── Toolbar ────────────────────────────────────────────────────────────── */
.toolbar {
  /* toolbar lives inside .site-header which is sticky — no separate sticky needed */
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
}

/* Desktop: inline pill row */
.filter-pills-desktop {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

/* Desktop: right-side count + sort */
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.widget-count {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.sort-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.sort-select {
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.sort-select:focus { border-color: var(--accent); outline: none; }

/* Desktop pills */
.pill {
  padding: 3px 11px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
.pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Mobile toggle buttons — hidden on desktop */
.sheet-toggle {
  display: none;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}
.sheet-toggle:hover { background: var(--bg); }
.sheet-toggle.active {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-color: var(--accent);
  color: var(--accent);
}
.sheet-toggle-arrow { font-size: 10px; }

/* Mobile widget count — hidden on desktop */
.widget-count-mobile {
  display: none;
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  white-space: nowrap;
}

/* ── Bottom sheets — hidden everywhere until mobile media query ── */
.bottom-sheet {
  display: none;
}
.sheet-backdrop {
  display: none;
}

/* ── Mobile ≤768px: search icon mode ──────────────────────────────────── */
@media (max-width: 768px) {
  /* search-icon pushes itself + theme to the right */
  .search-icon-btn { margin-left: auto; }
  .header-right    { margin-left: 0; }
}

/* Expanded search state — triggered by .search-active on <header> */
header.search-active .site-logo       { display: none; }
header.search-active .search-icon-btn { display: none; }
header.search-active .header-right    { display: none; }
header.search-active .search-wrap     {
  display: flex;
  flex: 1;
  width: auto;
  margin: 0;
}
header.search-active .search-close-btn { display: flex; }

/* ── Mobile ≤640px ─────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Header adjustments */
  header { padding: 10px 12px; gap: 8px; }

  /* Toolbar: hide desktop elements, show mobile toggles */
  .toolbar { padding: 6px 12px; gap: 8px; }
  .filter-pills-desktop { display: none; }
  .toolbar-right { display: none; }
  .sheet-toggle { display: flex; }
  .widget-count-mobile { display: block; }

  /* ── Bottom sheet base ── */
  .bottom-sheet {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 300;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    padding: 0 0 calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 32px rgba(0,0,0,.18);
    /* start off-screen */
    transform: translateY(100%);
    visibility: hidden;
    pointer-events: none;
    transition: transform .28s cubic-bezier(.4,0,.2,1),
                visibility 0s .28s;
  }
  .bottom-sheet.open {
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
    transition: transform .28s cubic-bezier(.4,0,.2,1),
                visibility 0s 0s;
  }

  /* Drag handle */
  .sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 12px auto 0;
  }

  /* Sheet title */
  .sheet-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 14px 20px 10px;
    margin: 0;
    border-bottom: 1px solid var(--border);
  }

  /* Pill list — one per row */
  .sheet-pills {
    display: flex;
    flex-direction: column;
    padding: 8px 0;
  }
  .sheet-pill {
    display: block;
    width: 100%;
    text-align: left;
    padding: 14px 20px;
    font-size: 15px;
    font-family: inherit;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    border-radius: 0;
  }
  .sheet-pill:last-child { border-bottom: none; }
  .sheet-pill:active { background: var(--bg); }
  .sheet-pill.active {
    color: var(--accent);
    font-weight: 700;
  }
  .sheet-pill.active::after {
    content: ' ✓';
    float: right;
    color: var(--accent);
  }

  /* Backdrop */
  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 299;
    background: rgba(0,0,0,.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s;
  }
  .sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 400px) {
  .site-logo { font-size: 14px; }
  .sheet-toggle { font-size: 12px; padding: 5px 10px; }
}

/* ─── Grid ───────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 16px 20px;
  max-width: 1400px;
  margin: 0 auto;
  /* rows size to content — no forced equal heights */
  align-items: start;
}

/* ─── Card ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s, opacity .15s, transform .15s;
}
.card-header {
  padding: 8px 10px 8px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  flex-shrink: 0;
}
/* title text inside header fills remaining space */
.card-header .card-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-body {
  padding: 14px 16px;
}

/* ─── Drag handle ────────────────────────────────────────────────────────── */
.drag-handle {
  cursor: grab;
  color: var(--border);
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
  user-select: none;
  flex-shrink: 0;
  transition: color .1s;
}
.drag-handle:hover { color: var(--muted); }
.drag-handle:active { cursor: grabbing; }

/* ─── Star button ────────────────────────────────────────────────────────── */
.star-btn {
  background: transparent;
  border: none;
  padding: 2px 4px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  color: var(--border);
  flex-shrink: 0;
  border-radius: 3px;
  transition: color .15s, transform .15s;
}
.star-btn:hover { color: #f5a623; background: transparent; transform: scale(1.2); }
.star-btn.starred { color: #f5a623; }
.star-btn.starred:hover { color: #d4881a; }

/* ─── Expand button (opens full-page widget view) ───────────────────────── */
.expand-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 14px;
  line-height: 1;
  border-radius: 3px;
  color: var(--border);
  text-decoration: none;
  flex-shrink: 0;
  transition: color .1s, background .1s;
  user-select: none;
}
.expand-btn:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* ─── Drag-and-drop states ───────────────────────────────────────────────── */
/* position:relative + z-index only while actively dragging, never at rest */
.card.dragging {
  position: relative;
  z-index: 100;
  opacity: .45;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  transform: scale(1.02);
}
.card.drag-over {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* ─── Starred banner ─────────────────────────────────────────────────────── */
.card.starred-card {
  border-color: #f5a623;
  box-shadow: 0 0 0 1px #f5a62340;
}

/* ─── Starred section divider ────────────────────────────────────────────── */
.starred-divider, .all-divider, .category-divider {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  padding: 4px 0 2px;
}
.starred-divider::after, .all-divider::after, .category-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Form controls ──────────────────────────────────────────────────────── */
input[type=text],
input[type=url],
input[type=email],
input[type=number],
input[type=search],
textarea,
select {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  outline: none;
}
input[type=text]:focus,
input[type=url]:focus,
input[type=email]:focus,
input[type=number]:focus,
input[type=search]:focus,
textarea:focus,
select:focus { border-color: var(--accent); }

textarea { resize: vertical; line-height: 1.5; width: 100%; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 12px;
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
}
button:hover { background: var(--bg); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 3px 6px;
}
.btn-ghost:hover { color: var(--danger); background: transparent; }
.btn-sm  { padding: 3px 8px;  font-size: 12px; }
.btn-icon{ padding: 2px 7px;  font-size: 13px; }

/* ─── Utility ────────────────────────────────────────────────────────────── */
.row { display: flex; gap: 6px; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono  { font-family: monospace; }

/* ─── Progress bar ───────────────────────────────────────────────────────── */
.progress-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}
.progress-bar {
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  width: 100%;
  transition: width .5s linear;
}

/* ─── Divider list ───────────────────────────────────────────────────────── */
.div-list { list-style: none; }
.div-list li {
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.div-list li:last-child { border-bottom: none; }

/* ─── Tabs ───────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}
.tab-btn {
  flex: 1;
  padding: 5px;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  background: var(--bg);
  border: none;
  color: var(--muted);
  border-radius: 0;
}
.tab-btn.active { background: var(--accent); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Theme switcher (in header) ─────────────────────────────────────────── */
.theme-switcher {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.theme-btn {
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.theme-btn:hover { background: var(--surface); color: var(--text); }
.theme-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
[data-theme="dark"] .theme-btn.active {
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}

/* On mobile show only the icon — hide the text label */
@media (max-width: 768px) {
  .theme-btn { padding: 4px 7px; font-size: 14px; }
  .theme-btn-label { display: none; }
}

/* ─── Cookie / storage notice ───────────────────────────────────────────── */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  display: none;
  justify-content: center;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  font-size: 13px;
  transition: opacity .3s, transform .3s;
}
.cookie-banner.cookie-hide {
  opacity: 0;
  transform: translateY(100%);
}
.cookie-msg {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  color: var(--text);
  line-height: 1.5;
  text-align: center;
}
.cookie-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
}
.cookie-link {
  font-size: 12px;
  color: var(--muted);
  text-decoration: underline;
}
.cookie-link:hover { color: var(--accent); }
.cookie-btn {
  padding: 5px 16px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.cookie-btn:hover { background: var(--accent-hover); }
.cookie-btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.cookie-btn-secondary:hover {
  background: var(--surface);
  border-color: var(--muted);
}

@media (max-width: 640px) {
  .cookie-banner { gap: 10px; padding: 12px 14px; }
  .cookie-actions { width: 100%; justify-content: flex-end; }
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .grid { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  /* force every card to single column — overrides inline span 2/3 */
  .grid .card { grid-column: span 1 !important; }
  /* theme switcher stays visible on mobile */
  /* Kanban internal columns: stack on mobile */
  #kanban-board { grid-template-columns: 1fr !important; }
}

/* ─── Prevent horizontal overflow on all viewports ──────────────────────── */
/* NOTE: overflow-x:hidden is intentionally NOT set on html/body — it would
   break position:sticky on the header and toolbar. Overflow is contained at
   the card level instead (see .card / .card-body below). */

/* Make sure widgets inside cards can't blow past the card boundary */
.card-body {
  overflow-x: auto;
  min-width: 0;
}
.card {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 480px) {
  .grid { padding: 8px; gap: 8px; }
  .card-body { padding: 10px 12px; }
  .card-header { padding: 6px 10px 6px 12px; }
}

/* ─── Site footer ────────────────────────────────────────────────────────── */
.site-footer {
  margin-top: 48px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 32px 24px 20px;
}
.site-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: 32px;
}
.footer-col strong {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: 10px;
}
.footer-col p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}
.footer-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.footer-col ul li {
  font-size: 13px;
  color: var(--muted);
}
.footer-bottom {
  max-width: 1200px;
  margin: 24px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .site-footer-inner {
    grid-template-columns: 1fr 1fr;
  }
}
@media (max-width: 560px) {
  .site-footer-inner {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}
