/* Reset & Global CSS Variables */
:root {
  --bg-primary: #121214;
  --bg-secondary: #1c1c1e;
  --bg-tertiary: #2c2c2e;
  --bg-card-active: #2a2a2f;
  
  --accent: #a855f7;       /* Soft Purple */
  --accent-light: #c084fc;
  --accent-glow: rgba(168, 85, 247, 0.15);
  
  --text-primary: #ffffff;
  --text-secondary: #98989f;
  --text-muted: #636366;
  
  --border-color: rgba(255, 255, 255, 0.08);
  --success: #10b981;
  --danger: #ef4444;
  
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ====== Light Theme Override ====== */
[data-theme="light"] {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e8e8ed;
  --bg-card-active: #dcdce2;
  
  --accent: #7c3aed;
  --accent-light: #6d28d9;
  --accent-glow: rgba(124, 58, 237, 0.12);
  
  --text-primary: #1c1c1e;
  --text-secondary: #636366;
  --text-muted: #aeaeb2;
  
  --border-color: rgba(0, 0, 0, 0.08);
  --success: #059669;
  --danger: #dc2626;
}

/* Smooth theme transition */
body, .app-header, .app-navbar, .modal-card, .toast-card,
.search-wrapper, .template-card, .settings-item, .pill,
.mode-toggle-btn, .instruction-card, .bottom-drawer {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent; /* Remove iOS flash on tap */
}

html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: 'Prompt', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

/* Utility Buttons & Forms */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(168, 85, 247, 0.25);
}

.btn-primary:active {
  transform: scale(0.97);
  opacity: 0.9;
}

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

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

.btn-sm {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
}

.w-100 {
  width: 100%;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-area-top)) 16px 12px 16px;
  background-color: rgba(18, 18, 20, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background-color 0.2s;
}

.header-btn:active {
  background-color: rgba(255, 255, 255, 0.05);
}

.header-btn.icon-btn {
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Category Dropdown Toggle */
.category-selector-container {
  position: relative;
}

.category-dropdown-trigger {
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 20px;
  transition: background-color 0.2s;
}

.category-dropdown-trigger:active {
  background-color: var(--bg-secondary);
}

.dropdown-chevron {
  color: var(--text-secondary);
  transition: transform 0.25s ease;
}

.category-selector-container.open .dropdown-chevron {
  transform: rotate(180deg);
}

/* Dropdown Menu styling */
.category-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) scale(0.95);
  transform-origin: top center;
  background-color: rgba(28, 28, 30, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 240px;
  max-height: 350px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.category-selector-container.open .category-dropdown-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) scale(1);
}

.dropdown-header {
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.dropdown-items {
  overflow-y: auto;
  padding: 6px;
}

.dropdown-item {
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.15s;
}

.dropdown-item:active {
  background-color: var(--bg-tertiary);
}

.dropdown-item.active {
  color: var(--accent-light);
  font-weight: 500;
}

.dropdown-item.active::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  background-color: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
}

.dropdown-footer {
  padding: 6px;
  border-top: 1px solid var(--border-color);
}

.dropdown-manage-btn {
  width: 100%;
  padding: 8px;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--accent-light);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.dropdown-manage-btn:active {
  background-color: rgba(168, 85, 247, 0.1);
}

/* Search Container */
.search-container {
  padding: 8px 16px;
  background-color: var(--bg-primary);
  z-index: 90;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background-color: var(--bg-secondary);
  border-radius: 10px;
  padding: 6px 12px;
  transition: box-shadow 0.2s, background-color 0.2s;
  border: 1px solid transparent;
}

.search-wrapper:focus-within {
  background-color: var(--bg-primary);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
  color: var(--text-muted);
  margin-right: 8px;
  flex-shrink: 0;
}

#searchInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  padding: 4px 0;
}

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

.clear-search-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 50%;
  transition: color 0.15s, background-color 0.15s;
}

.clear-search-btn:active {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Quick Mode Toggle Bar */
.mode-toggle-container {
  display: flex;
  padding: 0 16px 10px 16px;
  background-color: var(--bg-primary);
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
}

.mode-toggle-btn {
  flex: 1;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  padding: 10px 6px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mode-toggle-btn svg {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.mode-toggle-btn:active {
  transform: scale(0.97);
}

.mode-toggle-btn.active {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
  border-color: var(--accent);
  color: var(--accent-light);
  font-weight: 600;
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.1);
}

.mode-toggle-btn.active svg {
  transform: scale(1.1);
}

/* Main Content Area */
.app-main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* Momentum scrolling */
  padding: 8px 16px calc(85px + var(--safe-area-bottom)) 16px;
  min-height: 0; /* Allow flex child to shrink and enable scrolling */
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.25s ease-out;
}

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

/* Grid & Template Cards */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

@media (max-width: 380px) {
  .templates-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.template-card {
  background-color: var(--bg-secondary);
  border-radius: 12px;
  padding: 8px 6px;
  height: 84px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-color);
  transition: transform 0.1s cubic-bezier(0.25, 0.46, 0.45, 0.94), background-color 0.15s;
  user-select: none;
}

.template-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  transition: background-color 0.2s;
}

/* Custom left accent strip based on keyword */
.template-card[data-type="positive"]::before { background-color: var(--success); }
.template-card[data-type="info"]::before { background-color: var(--accent); }
.template-card[data-type="warning"]::before { background-color: #f59e0b; }

.template-card:active {
  transform: scale(0.94);
  background-color: var(--bg-card-active);
}

.template-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.template-preview {
  font-size: 10px;
  color: var(--text-secondary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
  flex: 1;
  margin-top: 4px;
}

/* Edit Mode Overlay on Cards */
body.edit-mode .template-card {
  border-color: rgba(245, 158, 11, 0.5);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.15);
  animation: wiggle 0.25s infinite alternate;
}

body.edit-mode .template-card::after {
  content: "✏️";
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 9px;
  background-color: #f59e0b;
  border: 1.5px solid var(--bg-secondary);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

@keyframes wiggle {
  from { transform: rotate(-0.5deg); }
  to { transform: rotate(0.5deg); }
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}

.empty-state p {
  font-size: 14px;
}

/* Scratchpad */
.scratchpad-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.section-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

#scratchpadTextarea {
  flex: 1;
  width: 100%;
  min-height: 250px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#scratchpadTextarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.scratchpad-actions {
  display: flex;
  gap: 12px;
  margin-top: 14px;
}

.scratchpad-actions .btn {
  flex: 1;
  padding: 12px;
}

/* Settings Container */
.settings-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-group h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-left: 8px;
  letter-spacing: 0.5px;
}

.settings-item {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  cursor: pointer;
  color: var(--text-primary);
  transition: background-color 0.15s, transform 0.1s;
}

.settings-item:active {
  background-color: var(--bg-card-active);
  transform: scale(0.99);
}

.settings-item-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
}

.settings-item-label svg {
  color: var(--accent);
}

.chevron-right {
  color: var(--text-muted);
}

.danger-action {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.2);
}

.danger-action .settings-item-label svg {
  color: var(--danger);
}

.danger-action:active {
  background-color: rgba(239, 68, 68, 0.08);
}

.instruction-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
}

.instruction-card h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent-light);
}

.instruction-card ol {
  font-size: 12px;
  color: var(--text-secondary);
  padding-left: 20px;
  line-height: 1.6;
}

.instruction-card ol li {
  margin-bottom: 6px;
}

.app-version {
  text-align: center;
  padding: 10px 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.app-credits {
  font-size: 11px;
}

/* Floating Add Button */
.floating-add-btn {
  position: fixed;
  bottom: calc(75px + var(--safe-area-bottom));
  right: 18px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(168, 85, 247, 0.4);
  z-index: 80;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.floating-add-btn:active {
  transform: scale(0.9) rotate(45deg);
}

/* Navigation Navbar */
.app-navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + var(--safe-area-bottom));
  background-color: rgba(28, 28, 30, 0.85);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  padding-bottom: var(--safe-area-bottom);
  z-index: 100;
}

.nav-item {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: color 0.15s;
}

.nav-item:active {
  opacity: 0.7;
}

.nav-item.active {
  color: var(--text-primary);
}

.nav-icon {
  transition: transform 0.2s ease;
}

.nav-item.active .nav-icon {
  color: var(--accent-light);
  transform: translateY(-1px);
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
}

/* Modal Overlay & Card styling */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 16px;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  width: 100%;
  max-width: 450px;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  transform: translateY(20px) scale(0.96);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.modal-overlay.open .modal-card {
  transform: translateY(0) scale(1);
}

/* Bottom Sheet layout for options menu */
.modal-card.bottom-sheet {
  align-self: flex-end;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-bottom: -16px;
  width: calc(100% + 32px);
  max-width: none;
  transform: translateY(100%);
}

.modal-overlay.open .modal-card.bottom-sheet {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 50%;
  transition: color 0.15s, background-color 0.15s;
}

.modal-close-btn:active {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* Form Styles */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  margin-left: 4px;
}

.form-group input[type="text"],
.form-group select,
.form-group textarea {
  width: 100%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input[type="text"]:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.form-actions .btn {
  flex: 1;
}

/* Inline Category Form */
.add-category-inline {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.add-category-inline input {
  flex: 1;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

/* Categories List inside modal */
.categories-list-container {
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.categories-list-header {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  background-color: var(--bg-tertiary);
  color: var(--text-muted);
  text-transform: uppercase;
}

.categories-list {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
}

.category-list-item {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
}

.category-list-item:last-child {
  border-bottom: none;
}

.delete-category-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.delete-category-btn:active {
  background-color: rgba(239, 68, 68, 0.08);
}

/* Sheet Options (Bottom sheet actions) */
.options-sheet-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 100%;
  cursor: pointer;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  transition: background-color 0.15s;
}

.sheet-item:active {
  background-color: var(--bg-card-active);
}

.sheet-item svg {
  color: var(--accent);
}

/* Custom Floating Toast Notification */
.toast-container {
  position: fixed;
  top: calc(20px + var(--safe-area-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 400;
}

.toast-card {
  background-color: rgba(28, 28, 30, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  padding: 10px 18px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateY(-50px);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
}

.toast-container.show .toast-card {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  background-color: var(--success);
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-text {
  font-size: 13px;
  font-weight: 500;
}

/* Image-enabled Card styling */
.template-card.has-image {
  background-color: #0c0c0e;
  overflow: hidden;
  padding: 0;
  display: block;
}

.template-card-image-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.35;
  filter: blur(1.5px);
  z-index: 1;
  transition: transform 0.3s ease, opacity 0.2s;
}

.template-card:active .template-card-image-bg {
  transform: scale(1.1);
  opacity: 0.25;
}

.template-card-content {
  position: relative;
  z-index: 2;
  height: 100%;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(20, 20, 22, 0.4) 0%, rgba(20, 20, 22, 0.85) 60%, rgba(20, 20, 22, 0.95) 100%);
}

.template-card.has-image .template-title {
  display: flex;
  align-items: center;
  gap: 3px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.template-card.has-image .template-title::before {
  content: "🖼️";
  font-size: 10px;
  text-shadow: none;
}

.template-card.has-image .template-preview {
  color: #d1d1d6;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Image input & preview inside forms */
.image-preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: var(--bg-secondary);
  border: 1.5px dashed var(--border-color);
  border-radius: 12px;
  padding: 12px;
  position: relative;
  transition: border-color 0.2s;
}

.image-preview-container:hover {
  border-color: var(--accent);
}

.image-preview-container img {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  object-fit: contain;
}

.form-group input[type="file"] {
  border: 1px solid var(--border-color);
  background-color: var(--bg-tertiary);
  padding: 10px;
  border-radius: 10px;
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.form-group input[type="file"]::file-selector-button {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 8px;
  margin-right: 8px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.15s;
}

.form-group input[type="file"]::file-selector-button:active {
  background-color: var(--bg-card-active);
}

/* Multi-Image Thumbnail Previews */
.image-previews-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}

.preview-thumbnail-wrapper {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-tertiary);
  padding: 2px;
}

.preview-thumbnail-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: none !important;
}

.delete-thumbnail-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 9px;
  background-color: var(--danger);
  color: white;
  border: 1.5px solid var(--bg-secondary);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  transition: transform 0.15s;
  user-select: none;
}

.delete-thumbnail-badge:active {
  transform: scale(0.85);
}

/* Edit Toggle button premium styling */
#editModeToggleBtn {
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 20px;
  transition: all 0.2s ease;
}

#editModeToggleBtn:active {
  background-color: rgba(255, 255, 255, 0.1);
  transform: scale(0.95);
}

body.edit-mode #editModeToggleBtn {
  background-color: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.3);
}

/* Visual touch indication for long-press */
.template-card:active {
  transform: scale(0.94);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* Cloud Sync styling additions */
.sync-status-box {
  transition: border-color 0.25s, box-shadow 0.25s;
}

.sync-status-box:focus-within {
  border-color: var(--accent) !important;
  box-shadow: 0 0 12px var(--accent-glow);
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.badge-inactive {
  background-color: var(--text-muted) !important;
  color: #fff !important;
}

.badge-active {
  background-color: var(--success) !important;
  color: #fff !important;
  animation: pulse-success 2s infinite;
}

@keyframes pulse-success {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Quick Delete Button styling for Edit Mode */
.quick-delete-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: var(--danger);
  color: white;
  border: 1.5px solid var(--bg-secondary);
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s, background-color 0.15s;
  padding: 0;
}

body.edit-mode .quick-delete-btn {
  display: flex; /* Show in Edit Mode */
}

.quick-delete-btn:active {
  transform: scale(0.85);
  background-color: rgb(220, 38, 38);
}

.template-card {
  position: relative; /* Ensure quick-delete-btn is positioned relative to the card */
}

/* Redesigned Header title style */
.header-title-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title-text {
  font-weight: 700;
  font-size: 17px;
  background: linear-gradient(135deg, #ffffff 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.5px;
}

/* Category Pills styles */
.category-pills-container {
  padding: 10px 16px;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  z-index: 95;
}

.category-pills-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.category-pills::-webkit-scrollbar {
  display: none; /* Hide scrollbar for clean app interface */
}

.pill {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background-color: rgba(28, 28, 30, 0.6);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 4px;
  user-select: none;
}

.pill:active {
  transform: scale(0.95);
}

.pill.active {
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 10px rgba(168, 85, 247, 0.25);
  font-weight: 600;
}

.pill-action-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.pill-action-btn:active {
  background-color: var(--bg-tertiary);
  transform: scale(0.92);
}

/* Pencil Edit Button styling */
.pencil-edit-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: rgba(245, 158, 11, 0.9); /* Warm Amber/Yellow */
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 15;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s, background-color 0.15s;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.pencil-edit-btn svg {
  stroke: #000;
  stroke-width: 2.5;
}

.pencil-edit-btn:active {
  transform: scale(0.85);
  background-color: #d97706;
}

/* Hide pencil button in body.edit-mode so it doesn't overlap with red quick-delete-btn */
body.edit-mode .pencil-edit-btn {
  display: none;
}

/* Bottom Drawer Scratchpad styling */
.bottom-drawer {
  position: fixed;
  bottom: calc(56px + var(--safe-area-bottom)); /* Sits just above bottom navigation */
  left: 0;
  right: 0;
  background-color: rgba(28, 28, 30, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
  z-index: 150;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform: translateY(calc(100% - 46px)); /* Default collapsed state, showing only header */
}

.bottom-drawer.expanded {
  transform: translateY(0);
}

.drawer-header {
  height: 46px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  background-color: rgba(255, 255, 255, 0.02);
}

.drawer-title-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer-icon {
  color: var(--accent);
}

.drawer-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.drawer-badge {
  font-size: 10px;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 2px 6px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  margin-left: 4px;
}

.drawer-toggle-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.bottom-drawer .chevron-up-down {
  transition: transform 0.3s ease;
}

.bottom-drawer.expanded .chevron-up-down {
  transform: rotate(180deg);
}

.drawer-content {
  padding: 12px 16px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 240px; /* Expands to this height */
}

#drawerScratchpadTextarea {
  flex: 1;
  width: 100%;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

#drawerScratchpadTextarea:focus {
  border-color: var(--accent);
}

.drawer-actions {
  display: flex;
  gap: 10px;
}

.drawer-actions .btn {
  flex: 1;
  padding: 10px;
}

/* ====== Light Theme Specific Overrides ====== */
/* Elements with hardcoded rgba() dark backgrounds need explicit light overrides */

[data-theme="light"] .app-header {
  background-color: rgba(245, 245, 247, 0.88);
}

[data-theme="light"] .header-btn:active {
  background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .app-navbar {
  background-color: rgba(255, 255, 255, 0.88);
}

[data-theme="light"] .category-dropdown-menu {
  background-color: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .toast-card {
  background-color: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .modal-overlay {
  background-color: rgba(0, 0, 0, 0.35);
}

[data-theme="light"] .pill {
  background-color: rgba(255, 255, 255, 0.7);
}

[data-theme="light"] .pill.active {
  color: #fff;
}

[data-theme="light"] .mode-toggle-btn.active {
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.12) 0%, rgba(109, 40, 217, 0.12) 100%);
}

[data-theme="light"] .bottom-drawer {
  background-color: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .drawer-header {
  background-color: rgba(0, 0, 0, 0.01);
}

[data-theme="light"] .template-card.has-image {
  background-color: #f0f0f3;
}

[data-theme="light"] .template-card-content {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.85) 60%, rgba(255, 255, 255, 0.95) 100%);
}

[data-theme="light"] .template-card.has-image .template-title {
  color: var(--text-primary);
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .template-card.has-image .template-preview {
  color: var(--text-secondary);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .app-title-text {
  background: linear-gradient(135deg, #1c1c1e 0%, #636366 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] #editModeToggleBtn {
  background-color: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] #editModeToggleBtn:active {
  background-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] body.edit-mode #editModeToggleBtn {
  background-color: rgba(245, 158, 11, 0.08);
}

[data-theme="light"] ::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #c7c7cc;
}

/* ====== Theme Toggle Switch Styling ====== */
.theme-toggle-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: default;
}

.theme-toggle-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: var(--text-primary);
}

.theme-toggle-label svg {
  color: var(--accent);
}

.theme-toggle-label-text {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.theme-toggle-label-title {
  font-size: 14px;
  font-weight: 500;
}

.theme-toggle-label-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* Premium Toggle Switch */
.theme-switch {
  position: relative;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #3a3a3c 0%, #48484a 100%);
  border-radius: 28px;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.theme-switch-slider::before {
  content: "🌙";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.theme-switch input:checked + .theme-switch-slider {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  border-color: rgba(251, 191, 36, 0.3);
}

.theme-switch input:checked + .theme-switch-slider::before {
  transform: translateX(24px);
  content: "☀️";
  box-shadow: 0 2px 8px rgba(251, 191, 36, 0.3);
}

/* Scratchpad Toggle Switch Styling */
#scratchpadToggleCheckbox + .theme-switch-slider::before {
  content: "❌";
  font-size: 10px;
}

#scratchpadToggleCheckbox:checked + .theme-switch-slider {
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  border-color: var(--accent-glow);
}

#scratchpadToggleCheckbox:checked + .theme-switch-slider::before {
  transform: translateX(24px);
  content: "📝";
  font-size: 11px;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Hide Bottom Scratchpad Drawer */
body.scratchpad-hidden .app-main-content {
  padding-bottom: calc(65px + var(--safe-area-bottom));
}

body.scratchpad-hidden #bottomDrawer {
  display: none !important;
}

/* Hover style for hide btn */
.drawer-action-btn:hover {
  color: var(--accent) !important;
}



