/* ==========================================================================
   HOUSE OF MYSTIC (HoM) - THE ULTIMATE SHOPPING APP STYLESHEET
   Extracted from HoM Theme and Style Reference Card v2.2
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Touch accessibility */
  --min-touch-target: 44px;
  --primary-touch-target: 48px;
}

/* Dark Theme Default */
[data-theme="dark"] {
  --gold: #C9A84C;
  --gold-contrast: #11182D;
  --primary-ink: #E8E0D0;
  --muted-ink: #B0A898;
  --soft-ink: #9A8F7E;
  --line: rgba(201, 168, 76, 0.34);
  --strong-line: rgba(201, 168, 76, 0.72);
  --card-glass: rgba(22, 33, 62, 0.76);
  --card-glass-hover: rgba(26, 40, 75, 0.85);
  --selected-surface: rgba(201, 168, 76, 0.96);
  --selected-ink: #11182D;
  --selected-border: #FFE49A;
  --child-surface: rgba(22, 125, 116, 0.96);
  --child-ink: #FFFFFF;
  --child-border: #7EF2DD;
  --dim-red: #A85A5A;
  --danger-surface: rgba(168, 90, 90, 0.2);
  --overlay-tint: rgba(8, 10, 24, 0.64);
  --solid-bg: #1A1A2E;
  --toggle-bg: rgba(9, 16, 34, 0.65);
  --cyan: #2DD4BF;
  --emerald: #34D399;
  --amber: #FBBF24;
  --modal-backdrop: rgba(4, 6, 15, 0.75);
}

/* Light Theme */
[data-theme="light"] {
  --gold: #9B7218;
  --gold-contrast: #FFFFFF;
  --primary-ink: #1A1D2E;
  --muted-ink: #545B73;
  --soft-ink: #767D96;
  --line: rgba(155, 114, 24, 0.38);
  --strong-line: rgba(155, 114, 24, 0.78);
  --card-glass: rgba(255, 255, 255, 0.84);
  --card-glass-hover: rgba(255, 255, 255, 0.95);
  --selected-surface: rgba(216, 184, 93, 0.96);
  --selected-ink: #11182D;
  --selected-border: #805B0D;
  --child-surface: rgba(167, 227, 216, 0.96);
  --child-ink: #102D2A;
  --child-border: #24786E;
  --dim-red: #8C4848;
  --danger-surface: rgba(140, 72, 72, 0.15);
  --overlay-tint: rgba(247, 245, 240, 0.82);
  --solid-bg: #F2EFE9;
  --toggle-bg: rgba(232, 228, 220, 0.85);
  --cyan: #0D9488;
  --emerald: #059669;
  --amber: #D97706;
  --modal-backdrop: rgba(40, 40, 50, 0.45);
}

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

html, body {
  min-height: 100%;
  font-family: var(--font-sans);
  background-color: var(--solid-bg);
  color: var(--primary-ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 16px;
  line-height: 1.45;
}

/* Atmospheric Layered Background */
.wallpaper-bg {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 20%, rgba(201, 168, 76, 0.08) 0%, transparent 60%),
              radial-gradient(circle at 80% 80%, rgba(45, 212, 191, 0.05) 0%, transparent 50%),
              var(--solid-bg);
  z-index: -2;
  pointer-events: none;
}

.overlay-tint {
  position: fixed;
  inset: 0;
  background-color: var(--overlay-tint);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: -1;
  pointer-events: none;
}

/* Responsive One-Column Viewport */
.app-viewport {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  padding: env(safe-area-inset-top, 16px) 16px env(safe-area-inset-bottom, 24px) 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header & Appearance Toggle */
.app-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.app-title {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: -0.01em;
  line-height: 1.15;
}

/* Top-Right Theme Toggle Pill */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  background: var(--toggle-bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  gap: 2px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  height: 32px;
  padding: 0 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted-ink);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease-out;
}

.theme-btn svg {
  flex-shrink: 0;
}

.theme-btn:hover {
  color: var(--gold);
}

.theme-btn.active {
  background: var(--gold);
  color: var(--gold-contrast);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

/* Sticky Top Undo / Redo Toolbar */
.undo-redo-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: env(safe-area-inset-top, 8px);
  z-index: 10;
  background: var(--card-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--min-touch-target);
  padding: 0 16px;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-out;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.action-pill {
  background: var(--card-glass);
  border-color: var(--line);
  color: var(--primary-ink);
}

.action-pill:hover:not(:disabled) {
  border-color: var(--strong-line);
  color: var(--gold);
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.25);
}

.action-pill:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.secondary-pill {
  background: transparent;
  border-color: var(--line);
  color: var(--muted-ink);
  margin-left: auto;
}

.secondary-pill:hover {
  color: var(--primary-ink);
  border-color: var(--strong-line);
}

.danger-pill {
  background: var(--danger-surface);
  border-color: var(--dim-red);
  color: var(--dim-red);
}

.danger-pill:hover:not(:disabled) {
  background: var(--dim-red);
  color: #FFFFFF;
}

.danger-pill:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.micro-pill {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-color: var(--line);
  background: var(--card-glass);
  color: var(--primary-ink);
}

/* Connection & Sync Status Banner */
.sync-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--card-glass);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-synced .status-indicator { background-color: var(--emerald); box-shadow: 0 0 8px var(--emerald); }
.status-syncing .status-indicator { background-color: var(--cyan); animation: pulse 1s infinite alternate; }
.status-offline .status-indicator { background-color: var(--amber); }
.status-attention .status-indicator { background-color: var(--dim-red); }

@keyframes pulse {
  0% { opacity: 0.4; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1.1); }
}

.pending-chip {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--amber);
  color: #11182D;
}

/* Glass Card Container */
.glass-card {
  background: var(--card-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* Search and Add Input */
.search-add-section {
  position: relative;
  display: flex;
  flex-direction: column;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  position: relative;
  width: 100%;
}

.search-input {
  width: 100%;
  min-height: var(--primary-touch-target);
  padding: 12px 78px 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.15);
  color: var(--primary-ink);
  font-family: var(--font-sans);
  font-size: 16px;
  outline: none;
  transition: all 0.15s ease-out;
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.search-input:focus {
  border-color: var(--strong-line);
  box-shadow: 0 0 14px rgba(201, 168, 76, 0.25);
}

.search-input-actions {
  position: absolute;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.spellcheck-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted-ink);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.15s ease-out;
  user-select: none;
}

.spellcheck-toggle-btn.active {
  border-color: var(--accent-gold);
  background: rgba(201, 168, 76, 0.18);
  color: var(--accent-gold);
  box-shadow: 0 0 8px rgba(201, 168, 76, 0.2);
}

.spellcheck-toggle-btn:not(.active) {
  opacity: 0.45;
  text-decoration: line-through;
}

.spellcheck-toggle-btn:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 1px;
}

.clear-input-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted-ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Search Dropdown Results */
.search-results {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.08);
  border: 1px solid transparent;
  cursor: pointer;
  min-height: var(--min-touch-target);
  transition: all 0.12s ease-out;
}

.search-result-item:hover {
  border-color: var(--line);
  background: rgba(201, 168, 76, 0.1);
}

.result-name-col {
  display: flex;
  flex-direction: column;
}

.result-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--primary-ink);
}

.result-status-tag {
  font-size: 11px;
  color: var(--muted-ink);
}

/* Store Filter Bar */
.store-filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.store-pill {
  white-space: nowrap;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--card-glass);
  color: var(--muted-ink);
  cursor: pointer;
  transition: all 0.15s ease-out;
  flex-shrink: 0;
}

.store-pill.active {
  background: var(--gold);
  color: var(--gold-contrast);
  border-color: var(--selected-border);
}

/* Shopping List Sections & Departments */
.departments-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.department-card {
  border-radius: 20px;
  padding: 14px;
}

.department-header {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

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

/* Grocery Item Row */
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--primary-touch-target);
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid transparent;
  transition: all 0.15s ease-out;
}

.item-row:hover {
  border-color: var(--line);
}

.item-row.pending-row {
  border-style: dashed;
  border-color: var(--amber);
}

/* Checkbox Touch Target */
.item-checkbox-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--min-touch-target);
  height: var(--min-touch-target);
  cursor: pointer;
  flex-shrink: 0;
}

.item-checkbox {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid var(--line);
  background: transparent;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-content: center;
  transition: all 0.15s ease-out;
}

.item-checkbox:checked {
  background: var(--gold);
  border-color: var(--gold);
}

.item-checkbox:checked::before {
  content: "";
  width: 12px;
  height: 6px;
  border-left: 2.5px solid var(--gold-contrast);
  border-bottom: 2.5px solid var(--gold-contrast);
  transform: rotate(-45deg) translate(1px, -1px);
}

.item-info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.item-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary-ink);
}

.item-location-label {
  font-size: 12px;
  color: var(--muted-ink);
}

.item-edit-btn {
  min-width: 38px;
  min-height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted-ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease-out;
  flex-shrink: 0;
}

.item-edit-btn:hover {
  color: var(--gold);
}

/* Purchased Section at Bottom */
.purchased-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.purchased-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.purchased-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
}

.count-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card-glass);
  border: 1px solid var(--line);
  color: var(--primary-ink);
}

.purchased-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.purchased-row {
  opacity: 0.85;
}

.purchased-row .item-name {
  text-decoration: line-through;
  color: var(--muted-ink);
}

.empty-state {
  padding: 16px;
  text-align: center;
  color: var(--soft-ink);
  font-style: italic;
  font-size: 14px;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 16px 0;
  text-align: center;
}

.footer-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--soft-ink);
  font-family: var(--font-mono);
}

/* Modals & Dialogs */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 16px)) 20px;
  border-bottom: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 101;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto;
}

.sheet-title {
  font-family: var(--font-serif);
  font-size: 24px;
  color: var(--gold);
}

.sheet-message {
  font-size: 15px;
  color: var(--primary-ink);
  line-height: 1.4;
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 101;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 24px;
  color: var(--gold);
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--muted-ink);
  cursor: pointer;
  padding: 4px 8px;
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted-ink);
}

.text-input, .select-input {
  min-height: var(--min-touch-target);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.15);
  color: var(--primary-ink);
  font-family: var(--font-sans);
  font-size: 15px;
  outline: none;
}

.text-input:focus, .select-input:focus {
  border-color: var(--strong-line);
}

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

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

/* Management Tabs & Lists */
.manage-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  overflow-x: auto;
}

.tab-btn {
  padding: 6px 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted-ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--gold);
  color: var(--gold-contrast);
}

.tab-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 8px;
}

.add-inline-form {
  display: flex;
  gap: 8px;
}

.simple-list, .registry-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.feedback-text {
  font-size: 13px;
  color: var(--emerald);
  margin-left: 8px;
}

.hidden {
  display: none !important;
}

/* High Contrast & Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
