/* =================================================================
   COMPY 2.0 DESIGN SYSTEM
   Enhanced design system with improved consistency and maintainability
   ================================================================= */

:root {
  /* ============= COLOR SYSTEM ============= */
  /* Base theme colors */
  --bg: #0a0d10;
  --surface: #1a2026;
  --surface-elevated: #242b32;
  --surface-overlay: rgba(26, 32, 38, 0.95);
  
  /* Brand colors */
  --primary: #4ade80;
  --primary-hover: #22c55e;
  --primary-contrast: #052e16;
  --primary-muted: rgba(74, 222, 128, 0.1);
  
  /* Semantic colors */
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-muted: rgba(239, 68, 68, 0.1);
  --success: #10b981;
  --warning: #f59e0b;
  --info: #3b82f6;
  --accent: #3b82f6;
  
  /* Text colors */
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-disabled: #64748b;
  --text-inverse: #0f172a;
  
  /* Border colors */
  --border: rgba(255, 255, 255, 0.12);
  --border-light: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.2);
  --border-interactive: rgba(255, 255, 255, 0.15);
  
  /* Component-specific colors */
  --chip-bg: #334155;
  --chip-text: #f1f5f9;
  --input-bg: var(--bg);
  --card-bg: var(--surface);
  --navbar-bg: var(--surface);
  --modal-bg: var(--surface);
  --modal-overlay: rgba(0, 0, 0, 0.5);
  
  /* Interactive states */
  --hover-overlay: rgba(255, 255, 255, 0.06);
  --active-overlay: rgba(255, 255, 255, 0.1);
  --focus-ring: 2px solid var(--primary);
  
  /* ============= SPACING SYSTEM ============= */
  /* Consistent 4px-based spacing scale */
  --space-0: 0;
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 6px;
  --space-4: 8px;
  --space-5: 10px;
  --space-6: 12px;
  --space-7: 14px;
  --space-8: 16px;
  --space-10: 20px;
  --space-12: 24px;
  --space-14: 28px;
  --space-16: 32px;
  --space-20: 40px;
  --space-24: 48px;
  --space-32: 64px;
  --space-48: 96px;
  
  /* Component-specific spacing */
  --content-padding: clamp(14px, (100vw - 1200px)/2, 32px);
  --modal-padding: var(--space-14);
  --card-padding: var(--space-12);
  
  /* ============= TYPOGRAPHY SYSTEM ============= */
  /* Font families */
  --font-family-base: system-ui, -apple-system, Segoe UI, Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  --font-family-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  
  /* Font sizes - Type scale based on 1.125 ratio */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 20px;
  --text-3xl: 25px;
  --text-4xl: 28px;
  
  /* Line heights */
  --leading-none: 1;
  --leading-tight: 1.25;
  --leading-normal: 1.4;
  --leading-relaxed: 1.6;
  
  /* Font weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  
  /* ============= LAYOUT SYSTEM ============= */
  /* Border radius */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;
  
  /* Component dimensions */
  --ctrl-h: 36px;
  --ctrl-h-sm: 28px;
  --ctrl-h-lg: 44px;
  --nav-h: 56px;
  --card-min-h: 96px;
  --modal-max-w: 720px;
  --modal-max-w-sm: 520px;
  --search-max-w: 680px;
  
  /* ============= SHADOW SYSTEM ============= */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.35);
  --shadow-xl: 0 18px 50px rgba(0, 0, 0, 0.5);
  --shadow-primary: 0 2px 8px color-mix(in srgb, var(--primary) 25%, transparent);
  
  /* ============= ANIMATION SYSTEM ============= */
  /* Transition durations */
  --duration-fast: 120ms;
  --duration-normal: 140ms;
  --duration-slow: 180ms;
  --duration-slower: 250ms;
  
  /* Easing curves */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  
  /* Common transition combinations */
  --transition-fast: all var(--duration-fast) var(--ease-out);
  --transition-normal: all var(--duration-normal) var(--ease-out);
  --transition-colors: background-color var(--duration-normal) var(--ease-out), 
                       border-color var(--duration-normal) var(--ease-out), 
                       color var(--duration-normal) var(--ease-out);
  --transition-transform: transform var(--duration-fast) var(--ease-out);
  
  /* ============= Z-INDEX SYSTEM ============= */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-toast: 1080;
}

/* =================================================================
   THEME VARIATIONS
   ================================================================= */

/* ============= DARK THEMES ============= */
html[data-theme="dark-mystic-forest"] {
  --bg: #0a0d10;
  --surface: #1a2026;
  --primary: #4ade80;
  --text: #f1f5f9;
  --muted: #cbd5e1;
  --chip-bg: #334155;
  --chip-text: #f1f5f9;
}
html[data-theme="dark-crimson-night"] {
  --bg: #0f0a0a;
  --surface: #1f1214;
  --primary: #f87171;
  --text: #fef2f2;
  --muted: #fca5a5;
  --chip-bg: #450a0a;
  --chip-text: #fef2f2;
}
html[data-theme="dark-royal-elegance"] {
  --bg: #0c0a14;
  --surface: #1e1b3a;
  --primary: #a78bfa;
  --text: #f3f4f6;
  --muted: #d1d5db;
  --chip-bg: #4c1d95;
  --chip-text: #f3f4f6;
}
/* ============= LIGHT THEMES ============= */
html[data-theme="light-sunrise"] {
  --bg: #fef7ed;
  --surface: #ffffff;
  --primary: #ea580c;
  --primary-contrast: #ffffff;
  --text: #0c0a09;
  --muted: #57534e;
  --danger: #dc2626;
  --accent: #2563eb;
  --chip-bg: #fed7aa;
  --chip-text: #0c0a09;
}
html[data-theme="light-soft-glow"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-contrast: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --danger: #dc2626;
  --accent: #0ea5e9;
  --chip-bg: #dbeafe;
  --chip-text: #0f172a;
}
html[data-theme="light-floral-breeze"] {
  --bg: #f0fdf4;
  --surface: #ffffff;
  --primary: #16a34a;
  --primary-contrast: #ffffff;
  --text: #052e16;
  --muted: #374151;
  --danger: #dc2626;
  --accent: #2563eb;
  --chip-bg: #bbf7d0;
  --chip-text: #052e16;
}

/* Light theme border adjustments for better contrast */
html[data-theme^="light-"] .navbar {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
html[data-theme^="light-"] .search {
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
html[data-theme^="light-"] .search:focus-within {
  background: rgba(255, 255, 255, 0.95);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent), 
              0 4px 12px color-mix(in srgb, var(--primary) 15%, transparent),
              inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
html[data-theme^="light-"] .icon-btn,
html[data-theme^="light-"] .icon-text-btn,
html[data-theme^="light-"] .file-btn span,
html[data-theme^="light-"] .secondary-btn,
html[data-theme^="light-"] .menu > button {
  border: 1px solid rgba(0, 0, 0, 0.15);
}
html[data-theme^="light-"] select {
  border: 1px solid rgba(0, 0, 0, 0.15);
}
html[data-theme^="light-"] .card {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
html[data-theme^="light-"] .modal-content {
  border: 1px solid rgba(0, 0, 0, 0.15);
}
html[data-theme^="light-"] .modal-header,
html[data-theme^="light-"] .modal-footer {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
html[data-theme^="light-"] .modal-footer {
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  border-bottom: none;
}
html[data-theme^="light-"] .tags-input {
  border: 1px solid rgba(0, 0, 0, 0.15);
}
html[data-theme^="light-"] input[type="text"],
html[data-theme^="light-"] input[type="search"],
html[data-theme^="light-"] textarea {
  border: 1px solid rgba(0, 0, 0, 0.15);
}

/* =================================================================
   BASE STYLES
   ================================================================= */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue",
    Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg);
  padding-top: var(--nav-h);
}

/* Navbar */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px clamp(14px, (100vw - 1200px)/2, 32px);
  /* Ensure a consistent typography baseline for all navbar items */
  font-size: 14px;
  line-height: 1;
  font-family: inherit;
}
/* Make all interactive controls in the navbar inherit the base font for consistency */
/* Exclude the brand so it can remain larger and styled independently */
.navbar button:not(.brand),
.navbar select,
.navbar input,
.navbar .file-btn span {
  font: inherit;
}
.navbar .left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.navbar .center {
  display: flex;
  justify-content: center;
  min-width: 0;
}
.navbar .right {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: nowrap;
  overflow: visible;
  -webkit-overflow-scrolling: touch;
}

.brand {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  position: relative;
  cursor: pointer;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  height: var(--ctrl-h);
}
.brand::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 0;
  height: 2px;
  background: var(--primary);
  transition: width 180ms ease, left 180ms ease;
}
/* Strengthen specificity so brand styles always win over generic navbar button rules */
.brand:hover::after {
  width: 100%;
  left: 0;
}
.profile-display {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: clamp(100px, 20vw, 240px);
}

/* Search Bar - Single clean implementation */
.search {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  height: 40px;
  padding: 0;
  width: min(680px, 100%);
  transition: all var(--duration-normal) var(--ease-out);
  backdrop-filter: blur(8px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 
              0 1px 3px rgba(0, 0, 0, 0.2);
}

.search:focus-within {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15),
              0 0 0 1px var(--primary),
              0 2px 12px color-mix(in srgb, var(--primary) 25%, transparent);
  transform: translateY(-1px);
}

.search input {
  background: transparent;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  color: var(--text);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  -webkit-appearance: none;
  appearance: none;
  padding: 0 var(--space-12);
  padding-right: 44px;
  flex: 1;
  height: 100%;
  width: 100%;
}

.search input::placeholder {
  color: var(--text-muted);
  font-weight: var(--font-normal);
  opacity: 0.7;
}

.search input:focus {
  box-shadow: none !important;
  outline: none !important;
  border: none !important;
}

/* Search clear button - completely separate from icon-btn styles */
#searchClear {
  position: absolute !important;
  right: 8px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  width: 28px !important;
  height: 28px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  background: transparent !important;
  color: var(--text-muted) !important;
  border-radius: var(--radius-sm) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 12px !important;
  opacity: 0.6 !important;
  transition: all var(--duration-fast) var(--ease-out) !important;
  box-shadow: none !important;
  cursor: pointer !important;
  z-index: 10 !important;
}

#searchClear:hover {
  opacity: 1 !important;
  color: var(--danger) !important;
  background: color-mix(in srgb, var(--danger) 12%, transparent) !important;
  border: none !important;
  box-shadow: none !important;
}

#searchClear:focus-visible {
  outline: 2px solid var(--primary) !important;
  outline-offset: 1px !important;
  opacity: 1 !important;
}
.icon-btn,
.icon-text-btn,
.file-btn span,
.primary-btn,
.secondary-btn,
.menu > button {
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  height: var(--ctrl-h);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
  padding: 0 10px;
  transition: background-color 140ms ease, border-color 140ms ease,
    color 140ms ease, box-shadow 140ms ease, transform 120ms ease;
}
/* Subtle theme-aware hover/focus for toolbar buttons */
.icon-btn:hover,
.icon-text-btn:hover,
.file-btn span:hover,
.secondary-btn:hover,
.menu > button:hover,
select:hover {
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--primary) 25%, transparent);
}

.icon-btn:focus-visible,
.icon-text-btn:focus-visible,
.file-btn span:focus-visible,
.primary-btn:focus-visible,
.secondary-btn:focus-visible,
.menu > button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.icon-btn {
  border-radius: 6px;
  padding: 0 8px;
  height: var(--ctrl-h);
}
.primary-btn {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: transparent;
  font-weight: 600;
}
/* Slight lift for primary on hover to keep contrast */
.primary-btn:hover {
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 25%, transparent);
  transform: translateY(-1px);
}
.secondary-btn {
  background: transparent;
}
.file-btn {
  display: inline-flex;
  align-items: center;
}

/* Small badge for counters (e.g., active filter count) */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  background: var(--accent);
  color: #07120a;
  font-weight: 700;
}
.menu {
  position: relative;
}
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px;
  display: none;
  min-width: 150px;
  z-index: 1000;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.menu-panel.open {
  display: block;
}
.menu-panel.floating {
  position: fixed;
}
.menu-panel button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: var(--space-8);
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: var(--transition-colors);
  font-size: var(--text-base);
  cursor: pointer;
}
.menu-panel button:hover {
  background: var(--hover-overlay);
  color: var(--text);
}
.menu-panel button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  background: var(--hover-overlay);
}

select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  height: var(--ctrl-h);
  width: fit-content;
  padding: 0 10px;
}
/* Focus style for select: match other controls (no thick outline) */
select:focus,
select:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Cards grid */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  padding: 16px clamp(14px, (100vw - 1200px)/2, 32px);
}
.card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 12px;
  padding-bottom: 48px;
  position: relative;
  min-height: 96px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}
.card:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}
.card .title {
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
  word-break: break-word;
  white-space: pre-wrap;
}
.card .desc {
  color: var(--text-secondary);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  word-break: break-word;
  white-space: pre-wrap;
  margin-bottom: var(--space-8);
}
.card .tags {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  background: var(--chip-bg);
  color: var(--chip-text);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip .x {
  opacity: 0.7;
  cursor: pointer;
  padding: 2px;
  border-radius: var(--radius-sm);
  transition: color var(--duration-normal) var(--ease-out),
              background-color var(--duration-normal) var(--ease-out),
              opacity var(--duration-normal) var(--ease-out);
}
.chip .x:hover {
  opacity: 1;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 15%, transparent);
}
.card .more {
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
}

/* Hover actions */
.card .actions {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: none;
  gap: 8px;
}
.card .actions .icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
.card .actions .icon-btn svg {
  width: 18px;
  height: 18px;
}
.card:hover .actions {
  display: flex;
}
.card:focus-within .actions {
  display: flex;
}

/* Red hover effect for delete buttons in cards */
.card .actions .icon-btn[data-act="delete"]:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.card .actions .icon-btn[data-act="delete"]:focus-visible {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
.modal[aria-hidden="false"] {
  display: flex;
}
/* Theme-aware hover for modal close (X) and close/cancel buttons */
.modal .modal-header .icon-btn {
  transition: background-color 140ms ease, border-color 140ms ease,
    color 140ms ease, box-shadow 140ms ease;
}
.modal .modal-header .icon-btn:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.modal .modal-header .icon-btn:focus-visible {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}
/* Close/Cancel buttons (secondary and elements with data-close-modal) */
button[data-close-modal],
.modal .secondary-btn {
  transition: background-color 140ms ease, border-color 140ms ease,
    color 140ms ease, box-shadow 140ms ease;
}
button[data-close-modal]:hover,
.modal .secondary-btn:hover {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border-color: color-mix(in srgb, var(--primary) 25%, transparent);
}

/* Red hover effect for Cancel buttons specifically */
.modal .secondary-btn[data-close-modal]:hover {
  color: var(--danger) !important;
  background: color-mix(in srgb, var(--danger) 12%, transparent) !important;
  border-color: color-mix(in srgb, var(--danger) 30%, transparent) !important;
}
button[data-close-modal]:focus-visible,
.modal .secondary-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.modal-content {
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  width: min(720px, 92vw);
  max-height: 90vh;
  overflow: auto;
}
.modal-content.small {
  width: min(520px, 92vw);
}
.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.modal-footer .end-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 8px;
}
.modal-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom: none;
}
/* Center the Close button on About modal */
#aboutModal .modal-footer {
  justify-content: center;
}
.modal-body {
  padding: 12px 14px;
}
.field {
  margin-bottom: 12px;
}
.field label {
  display: block;
  font-size: var(--text-base);
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  font-weight: var(--font-medium);
}
/* Ensure toggle label uses flex layout and spacing; override block label rule */
.field label.toggle {
  display: inline-flex !important;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  margin: 6px 0 10px !important;
}

.field.with-clear {
  position: relative;
}
.clear-field {
  position: absolute;
  right: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
}

/* Tags input */
.tags-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 6px;
  background: var(--bg);
}
.tags-input .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tags-input input {
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  padding: 6px;
  min-width: 120px;
}

/* Lists */
.list button {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 8px;
  border-radius: 8px;
  text-align: left;
  margin: 6px 0;
}
/* Aligned rows for filter tag list */
.list-row {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
}
.list-row:hover {
  background: rgba(255, 255, 255, 0.06);
}
.list-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

/* Snackbar */
.snackbar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}
.snackbar.show {
  opacity: 1;
}

/* Empty state */
.empty {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
  color: var(--muted);
}
.empty h2 {
  margin: 4px 0;
  color: var(--text);
}
.empty .empty-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.empty .empty-tips {
  list-style: disc;
  text-align: left;
  opacity: 0.85;
}
/* Center the empty state within the grid area */
.cards.empty-state {
  min-height: calc(100vh - 70px);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Ensure the grid gaps don’t offset centering in empty state */
.cards.empty-state {
  grid-template-columns: 1fr;
  gap: 0;
  padding: 32px;
}

/* Generic small empty note (e.g., inside lists) */
.empty-note {
  color: var(--muted);
  text-align: center;
  padding: 8px 6px;
}

.empty .empty-card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 28px;
  width: min(720px, 92vw);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.empty h1 {
  margin: 0 0 6px;
  font-size: 28px;
  color: var(--text);
}
.empty .lead {
  margin: 0 0 16px;
  color: var(--muted);
}
.empty .divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.06);
  margin: 16px 0;
}
.empty .empty-tips {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
  justify-items: start;
}
.empty .empty-tips li {
  color: var(--muted);
}
.empty .hero-icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 6px;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.35));
}

/* Skeletons */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04),
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.04)
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
.skel-card {
  height: 96px;
  border-radius: 12px;
}
@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Search highlight */
mark {
  background: rgba(255, 230, 0, 0.35);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

@media (max-width: 720px) {
  .navbar {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
    padding: 10px;
    height: auto;
  }
  
  .navbar .left {
    grid-column: 1;
    grid-row: 1;
    justify-content: space-between;
    width: 100%;
  }
  
  .navbar .center {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    margin-bottom: 8px;
  }
  
  .navbar .center .search {
    width: 100%;
    min-width: 0;
  }
  
  .navbar .right {
    position: absolute;
    top: 10px;
    right: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 60%;
  }
  
  /* Adjust body padding for taller mobile navbar */
  body {
    padding-top: calc(var(--nav-h) + 40px);
  }
  
  /* Compact mobile buttons */
  .navbar .right .icon-btn,
  .navbar .right .icon-text-btn,
  .navbar .right .secondary-btn {
    height: var(--ctrl-h-sm);
    padding: 0 var(--space-6);
    font-size: var(--text-sm);
  }
  
  /* Hide some text on very small screens */
  .navbar .right .icon-text-btn span:not(.badge) {
    display: none;
  }
  
  .navbar .right .file-btn span {
    padding: 0 var(--space-6);
    font-size: var(--text-sm);
  }
}

/* ----- UI polish: modal + form controls ----- */
/* Inputs/Textareas - exclude main search input and ensure proper modal styling */
input[type="text"]:not(#searchInput):not(#filterTagSearch),
input[type="search"]:not(#searchInput):not(#filterTagSearch),
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-interactive);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: var(--space-10) var(--space-12);
  outline: none;
  transition: var(--transition-colors);
}
input[type="text"]::placeholder,
input[type="search"]::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}
input[type="text"]:focus,
input[type="search"]:focus,
textarea:focus {
  border-color: var(--primary);
}

/* Input wrapper to place the clear X consistently for input + textarea */
.input-wrap {
  position: relative;
}
.input-wrap > input,
.input-wrap > textarea {
  width: 100%;
}
/* Ensure clear button doesn't overlap text */
.input-wrap.with-clear > input,
.input-wrap.with-clear > textarea {
  padding-right: 36px;
}
.clear-field {
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.85;
  line-height: var(--leading-none);
  font-size: var(--text-base);
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
}
.clear-field:hover {
  opacity: 1;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
.clear-field:focus-visible {
  outline: 2px solid var(--primary);
}

/* Checkbox accent color - generic checkboxes (e.g., in lists) */
.field input[type="checkbox"] {
  accent-color: var(--primary);
}

/* Tags input focus state */
.tags-input:focus-within {
  border-color: var(--primary);
}

/* Filter modal search input - ensure proper styling and theme consistency */
#filterTagSearch {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-interactive);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: var(--space-10) var(--space-12);
  outline: none;
  transition: var(--transition-colors);
  font-size: var(--text-base);
}

#filterTagSearch::placeholder {
  color: var(--text-muted);
}

#filterTagSearch:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

/* Avoid double border/glow inside tags input */
.tags-input input,
.tags-input input:focus {
  border: none;
  box-shadow: none;
  background: transparent;
  padding: var(--space-6);
}

/* Hints */
.hint {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-6);
}

/* Modal refinements */
.modal-content {
  box-shadow: var(--shadow-xl);
}
.modal-header h3 {
  margin: 0;
  font-size: var(--text-xl);
}

/* Themed links for modals (better visibility than default blue) */
.modal-body a {
  color: var(--primary);
  text-decoration: none;
  text-underline-offset: 3px;
}
/* About modal: justify long description text for neat edges */
#aboutModal .modal-body p {
  text-align: justify;
  text-justify: inter-word;
}
.modal-body a:hover,
.modal-body a:focus-visible {
  text-decoration: underline;
}
.modal-body a:visited {
  color: var(--primary);
}
.modal-body a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* About modal layout and typography improvements */
#aboutModal .modal-content.small {
  width: min(640px, 92vw);
}
#aboutModal .modal-header h3 {
  font-size: var(--text-2xl);
  letter-spacing: 0.2px;
}
#aboutModal .modal-body {
  display: grid;
  gap: var(--space-12);
}
#aboutModal .modal-body p {
  text-align: justify;
  text-justify: inter-word;
  line-height: var(--leading-relaxed);
  font-size: var(--text-md);
}
#aboutModal .about-meta {
  text-align: center;
  opacity: 0.9;
}

/* About modal meta styling */
#aboutModal .about-meta {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-6);
  text-align: center;
}

/* Chip-style links for About modal */
#aboutModal .about-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-10);
  margin-top: var(--space-10);
  justify-content: center;
}
#aboutModal .link-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-8) var(--space-14);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: var(--bg);
  color: var(--text);
  font-weight: var(--font-medium);
  transition: var(--transition-colors), transform var(--duration-fast) var(--ease-out);
}
#aboutModal .link-chip:hover {
  border-color: var(--primary);
  background: var(--hover-overlay);
  transform: translateY(-1px);
}
#aboutModal .link-chip .icon {
  color: var(--primary);
  display: inline-flex;
}
#aboutModal .link-chip:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
#aboutModal .link-chip:visited {
  color: var(--text);
}

/* Slightly larger clickable close/clear icons on high-DPI */
.icon-btn,
.clear-field {
  -webkit-tap-highlight-color: transparent;
}

/* Toggle switch for Sensitive */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-10);
  cursor: pointer;
  user-select: none;
  position: relative;
}
/* Hide the raw checkbox but keep it accessible */
.toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  border: 0;
  padding: 0;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
/* Visual switch */
.toggle .switch {
  display: inline-block;
  width: 42px;
  height: 24px;
  background: var(--border);
  border-radius: var(--radius-full);
  position: relative;
  flex: 0 0 42px;
  transition: background var(--duration-normal) var(--ease-out);
  box-shadow: inset 0 0 0 1px var(--border-light);
  vertical-align: middle;
  margin-right: var(--space-2);
}
.toggle .switch::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  transition: left var(--duration-normal) var(--ease-out), background var(--duration-normal) var(--ease-out);
}
.toggle input:checked + .switch::after {
  background: var(--primary-contrast);
}
.toggle-text {
  color: var(--text-muted);
}
/* Light theme tweak for track tone */
html[data-theme^="light-"] .toggle .switch {
  background: var(--border);
  box-shadow: inset 0 0 0 1px var(--border-light);
}

.toggle input:checked + .switch {
  background: var(--primary);
}
.toggle input:checked + .switch::after {
  left: 21px;
  background: var(--primary-contrast);
}

/* Colored chips for tags (subtle) */
.chip {
  position: relative;
}
.chip::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-full);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0),
    rgba(255, 255, 255, 0.06)
  );
  pointer-events: none;
}
/* deterministic hue accents */
.chip[data-color] {
  background: var(--chip-bg);
}

/* Card hover effects work consistently across all themes using CSS custom properties */

/* =================================================================
   DESIGN SYSTEM IMPROVEMENTS
   ================================================================= */

/* ============= ENHANCED THEME CONSISTENCY ============= */
/* Complete missing theme variables for all themes */
html[data-theme="dark-mystic-forest"] {
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-disabled: #64748b;
  --text-inverse: #0f172a;
  --border: rgba(255, 255, 255, 0.12);
  --border-light: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.2);
  --border-interactive: rgba(255, 255, 255, 0.15);
}

html[data-theme="dark-crimson-night"] {
  --text-secondary: #fca5a5;
  --text-muted: #f87171;
  --text-disabled: #7f1d1d;
  --text-inverse: #350a0a;
  --border: rgba(248, 113, 113, 0.15);
  --border-light: rgba(248, 113, 113, 0.08);
  --border-strong: rgba(248, 113, 113, 0.25);
  --border-interactive: rgba(248, 113, 113, 0.18);
}

html[data-theme="dark-royal-elegance"] {
  --text-secondary: #d1d5db;
  --text-muted: #a78bfa;
  --text-disabled: #6b7280;
  --text-inverse: #1e1b3a;
  --border: rgba(167, 139, 250, 0.15);
  --border-light: rgba(167, 139, 250, 0.08);
  --border-strong: rgba(167, 139, 250, 0.25);
  --border-interactive: rgba(167, 139, 250, 0.18);
}

html[data-theme="light-sunrise"] {
  --text-secondary: #57534e;
  --text-muted: #78716c;
  --text-disabled: #a8a29e;
  --text-inverse: #ffffff;
  --border: rgba(0, 0, 0, 0.12);
  --border-light: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.2);
  --border-interactive: rgba(0, 0, 0, 0.15);
  --hover-overlay: rgba(0, 0, 0, 0.04);
  --active-overlay: rgba(0, 0, 0, 0.08);
}

html[data-theme="light-soft-glow"] {
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-disabled: #94a3b8;
  --text-inverse: #ffffff;
  --border: rgba(0, 0, 0, 0.12);
  --border-light: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.2);
  --border-interactive: rgba(0, 0, 0, 0.15);
  --hover-overlay: rgba(0, 0, 0, 0.04);
  --active-overlay: rgba(0, 0, 0, 0.08);
}

html[data-theme="light-floral-breeze"] {
  --text-secondary: #374151;
  --text-muted: #4b5563;
  --text-disabled: #9ca3af;
  --text-inverse: #ffffff;
  --border: rgba(0, 0, 0, 0.12);
  --border-light: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.2);
  --border-interactive: rgba(0, 0, 0, 0.15);
  --hover-overlay: rgba(0, 0, 0, 0.04);
  --active-overlay: rgba(0, 0, 0, 0.08);
}

/* ============= THEME SWITCHING ENHANCEMENTS ============= */
/* Prevent flash of unstyled content during theme transitions */
html {
  color-scheme: dark light;
}

html[data-theme^="light-"] {
  color-scheme: light;
}

html[data-theme^="dark-"] {
  color-scheme: dark;
}

/* Smooth theme transitions for all elements */
*,
*::before,
*::after {
  transition-property: background-color, border-color, color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
  transition-duration: var(--duration-normal);
  transition-timing-function: var(--ease-out);
}

/* Apply theme transition class temporarily via JS when switching themes */
html.theme-switching * {
  transition: background-color 300ms ease,
              border-color 300ms ease,
              color 300ms ease !important;
}

/* ============= ACCESSIBILITY ENHANCEMENTS ============= */
/* Enhanced contrast for better readability */
.card .desc {
  color: var(--text-secondary);
  font-size: var(--text-base);
}

/* Improved focus visibility for interactive elements */
.card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-color: var(--primary);
}

/* Better keyboard navigation for menu panels */
.menu-panel button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  background: var(--hover-overlay);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border: rgba(255, 255, 255, 0.3);
    --border-interactive: rgba(255, 255, 255, 0.4);
  }
  
  html[data-theme^="light-"] {
    --border: rgba(0, 0, 0, 0.3);
    --border-interactive: rgba(0, 0, 0, 0.4);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .skeleton {
    animation: none;
  }
}

/* ============= ENHANCED RESPONSIVENESS ============= */
/* Improved mobile-first breakpoint system */
@media (max-width: 480px) {
  /* Ultra-compact mobile layout */
  .navbar {
    padding-inline: var(--space-6);
    gap: var(--space-4);
  }
  
  .navbar .right {
    gap: var(--space-4);
  }
  
  .cards {
    grid-template-columns: 1fr;
    gap: var(--space-10);
    padding: var(--space-12) var(--space-8);
  }
  
  .modal-content {
    width: min(100vw - 16px, 92vw);
    margin: var(--space-4);
  }
  
  /* Larger touch targets on mobile */
  .icon-btn,
  .clear-field {
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Improved text sizing for readability */
  .card .title {
    font-size: var(--text-lg);
    line-height: var(--leading-tight);
  }
}

@media (max-width: 600px) {
  .cards {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-12);
    padding: var(--space-16) var(--space-10);
  }
}

/* Enhanced tablet layout */
@media (min-width: 721px) and (max-width: 1024px) {
  .cards {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-16);
  }
  
  .navbar {
    padding-inline: var(--space-16);
  }
}

/* ============= ANIMATION & TRANSITION POLISH ============= */
/* Enhanced card hover animations */
.card {
  transition: transform var(--duration-fast) var(--ease-out),
              border-color var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}

.card:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

/* Smooth modal entrance with spring animation */
.modal[aria-hidden="false"] {
  animation: modalBackdropIn var(--duration-slower) var(--ease-out);
}

.modal[aria-hidden="false"] .modal-content {
  animation: modalContentIn var(--duration-slower) var(--ease-spring);
}

@keyframes modalBackdropIn {
  from {
    background-color: transparent;
  }
  to {
    background-color: var(--modal-overlay);
  }
}

@keyframes modalContentIn {
  from {
    transform: translateY(16px) scale(0.95);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Staggered card entrance animations */
.card:nth-child(1) { animation-delay: 0ms; }
.card:nth-child(2) { animation-delay: 40ms; }
.card:nth-child(3) { animation-delay: 80ms; }
.card:nth-child(4) { animation-delay: 120ms; }
.card:nth-child(5) { animation-delay: 160ms; }
.card:nth-child(6) { animation-delay: 200ms; }

.cards:not(.empty-state) .card {
  animation: cardIn var(--duration-slower) var(--ease-out) both;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Enhanced button press feedback */
.btn-base:active,
.icon-btn:active,
.icon-text-btn:active,
.secondary-btn:active {
  transform: translateY(1px) scale(0.98);
}

.primary-btn:active {
  transform: translateY(0px) scale(0.98);
}

/* Smooth search input focus transition */
.search {
  transition: border-color var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}

.search:focus-within {
  box-shadow: 0 0 0 1px var(--primary), var(--shadow-primary);
}

/* Enhanced chip animations - subtle and responsive */
.chip {
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  border: 1px solid transparent;
}

.chip:hover {
  background: color-mix(in srgb, var(--chip-bg) 85%, var(--primary) 15%);
  border-color: color-mix(in srgb, var(--primary) 20%, transparent);
  transform: translateY(-1px);
}

/* Improved skeleton loading animation */
@keyframes shimmer {
  0% {
    background-position: 200% 0;
    opacity: 0.4;
  }
  50% {
    opacity: 0.8;
  }
  100% {
    background-position: -200% 0;
    opacity: 0.4;
  }
}

.skeleton {
  animation-duration: 1.6s;
  animation-timing-function: ease-in-out;
}

/* ============= UTILITY CLASSES ============= */
/* Screen reader only content */
.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;
}

