:root {
  --bg: #EEF1F6;
  --surface: #FFFFFF;
  --ink: #171B23;
  --muted: #6B7280;
  --line: #DCE1E9;

  --accent: #2F6FED;
  --accent-soft: #E7EEFE;

  --danger: #E5484D;

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;

  --radius: 14px;
  --nav-h: 72px;
}

* { box-sizing: border-box; }

/* Generic hide utility — overrides any element's own display value so
   classList.add/remove/toggle("hidden") works reliably everywhere. */
.hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  width: 100%;
}

body {
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 18px 20px 10px;
}

.topbar h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.01em;
}

#app {
  padding: 4px 16px 24px;
}

.view.hidden { display: none; }

/* ---------- Keyword select (dropdown, replaces old calendar/tabs) ---------- */
.filter-bar {
  margin: 8px 0 14px;
}

.keyword-select-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.filter-checkbox {
  margin: 10px 0 0;
}

.keyword-select-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

.keyword-select-row select {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: var(--font-body);
  font-weight: 600;
  background: var(--surface);
  color: var(--ink);
}

/* ---------- List views ---------- */
.list-empty {
  color: var(--muted);
  text-align: center;
  padding: 60px 20px;
  font-size: 14px;
}

/* ---------- Sort chip bar ---------- */
.sort-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.sort-chip {
  flex: 0 0 auto;
  border: none;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(23,27,35,0.06);
}

.sort-chip.active { background: var(--row-color, var(--ink)); color: white; }

.sort-arrow { font-size: 9px; margin-left: 2px; opacity: 0.85; }

.row-title {
  font-weight: 700;
  font-size: 15px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}
.row-title.done { text-decoration: line-through; color: var(--muted); font-weight: 500; }

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

/* ---------- Swipeable item card ---------- */
.swipe-row {
  position: relative;
  overflow: hidden;
  background: var(--danger);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(23,27,35,0.08);
  min-width: 0;
}

.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  display: flex;
}

.swipe-action-btn {
  width: 70px;
  border: none;
  color: white;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
}

.swipe-action-edit { background: var(--row-color, var(--accent)); }
.swipe-action-delete { background: var(--danger); }

.swipe-content {
  background: var(--surface);
  position: relative;
  z-index: 1;
  touch-action: pan-y;
  border-radius: var(--radius);
}

/* Card content layout */
.item-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  min-width: 0;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.card-badges { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }

.card-dates {
  display: flex;
  gap: 20px;
  min-width: 0;
  flex-wrap: wrap;
}

.card-date-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  color: var(--ink);
  min-width: 0;
}

.card-date-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.card-link-btn {
  padding: 8px 14px;
  font-size: 13px;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}
.card-link-btn.disabled {
  background: var(--bg);
  color: var(--muted);
  opacity: 0.6;
}

.card-photo-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  flex-shrink: 0;
}

.card-photo-empty {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  opacity: 0.35;
  flex-shrink: 0;
}

.row-done-check {
  width: 22px;
  height: 22px;
  accent-color: var(--row-color, var(--accent));
  flex-shrink: 0;
}

/* ---------- Keyword rows (MyKeywords list) ---------- */
.keyword-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  min-width: 0;
}

.keyword-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--row-color, var(--accent));
}

.keyword-name {
  font-weight: 700;
  font-size: 15px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.keyword-count {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
}

.keyword-card-protected {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(23,27,35,0.08);
  opacity: 0.75;
}

.keyword-protected-note {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: white;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(23,27,35,0.28);
  z-index: 10;
}
.fab.hidden { display: none; }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 20;
}

.navbtn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  padding-top: 6px;
}

.navbtn svg { width: 22px; height: 22px; }

.navbtn.active { color: var(--ink); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23,27,35,0.45);
  display: flex;
  align-items: flex-end;
  z-index: 30;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-head h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0;
}

.icon-btn {
  border: none;
  background: var(--bg);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  color: var(--muted);
}

.field {
  display: block;
  margin-bottom: 14px;
  min-width: 0;
}
.field span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="file"],
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
}

.field input[type="date"] {
  width: 100%;
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
}

.field textarea { resize: vertical; }

.field-row {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.photo-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.photo-preview {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--line);
}
.photo-preview.hidden { display: none; }

.hidden-file-input { display: none; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lightbox.hidden { display: none; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--row-color-soft, var(--accent-soft));
  color: var(--row-color, var(--accent));
}

.badge.badge-muted { background: var(--bg); color: var(--muted); }
.badge.badge-done { background: #E4F6EF; color: #1FA37B; }

.btn-link {
  background: var(--bg);
  color: var(--ink);
  font-weight: 600;
}

/* ---------- Link field + QR scan button ---------- */
.link-row {
  display: flex;
  gap: 8px;
  min-width: 0;
}
.link-row input { flex: 1; min-width: 0; }

.btn-icon-only {
  white-space: nowrap;
  padding: 11px 14px;
}

/* ---------- Color swatches (MyKeywords form) ---------- */
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 2px;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
}

.color-swatch.selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--surface) inset;
}
.color-swatch.selected::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 700;
}

/* ---------- QR scanner overlay ---------- */
.qr-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.qr-overlay.hidden { display: none; }

.qr-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  padding-top: calc(16px + env(safe-area-inset-top));
  color: white;
  font-family: var(--font-display);
  font-weight: 600;
}
.qr-header .icon-btn {
  background: rgba(255,255,255,0.15);
  color: white;
}

.qr-video {
  flex: 1;
  width: 100%;
  object-fit: cover;
  background: #000;
}

.qr-hint {
  text-align: center;
  color: white;
  font-size: 13px;
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  margin: 0;
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}
.field-checkbox input { width: 20px; height: 20px; }

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.modal-actions-right { display: flex; gap: 8px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-body);
}

.btn-primary { background: var(--ink); color: white; }
.btn-ghost { background: var(--bg); color: var(--ink); }
.btn-danger { background: #FCE8E8; color: var(--danger); }
