/* Note to Self — Adaptive Theme PWA */

/* ── Dark mode variables ── */
:root, [data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --bg-input: rgba(255,255,255,0.04);
  --accent: #4ade80;
  --accent-hover: #6ee7a0;
  --accent-soft: rgba(74,222,128,0.12);
  --text-primary: #eaeaea;
  --text-secondary: #a0a0b0;
  --text-muted: #6a6a7a;
  --border: rgba(255,255,255,0.08);
  --border-focus: rgba(74,222,128,0.3);
  --success: #4ade80;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 16px;
  --radius-xs: 8px;
  --radius-button: 32px;
  --transition: 0.15s ease;
  --shadow-input: none;

  /* Per-screen backgrounds — dark */
  --bg-capture: #161a2e;
  --bg-search: #1a162e;
  --bg-settings: #162e2a;
  --bg-auth: #1a1a2e;
}

/* ── Light mode variables ── */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #e8ecf2;
    --bg-input: rgba(0,0,0,0.03);
    --accent: #22a855;
    --accent-hover: #1e9a4c;
    --accent-soft: rgba(34,168,85,0.10);
    --text-primary: #1a1a2e;
    --text-secondary: #555568;
    --text-muted: #8888a0;
    --border: rgba(0,0,0,0.08);
    --border-focus: rgba(34,168,85,0.3);
    --success: #22a855;
    --danger: #dc2626;
    --shadow-input: none;

    /* Per-screen backgrounds — light */
    --bg-capture: #edf2fa;
    --bg-search: #f0edfa;
    --bg-settings: #edfaf7;
    --bg-auth: #f0f2f5;
  }
}

/* Explicit light theme override */
[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-card: #e8ecf2;
  --bg-input: rgba(0,0,0,0.03);
  --accent: #22a855;
  --accent-hover: #1e9a4c;
  --accent-soft: rgba(34,168,85,0.10);
  --text-primary: #1a1a2e;
  --text-secondary: #555568;
  --text-muted: #8888a0;
  --border: rgba(0,0,0,0.08);
  --border-focus: rgba(34,168,85,0.3);
  --success: #22a855;
  --danger: #dc2626;
  --shadow-input: none;

  --bg-capture: #edf2fa;
  --bg-search: #f0edfa;
  --bg-settings: #edfaf7;
  --bg-auth: #f0f2f5;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Safe area insets for iOS */
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* App Shell */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── Screens ── */
.screen {
  flex: 1;
  overflow-y: auto;
  display: none;
  padding: 20px;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Per-screen backgrounds */
#auth-screen { background: var(--bg-auth); }
#capture-screen { background: var(--bg-capture); }
#search-screen { background: var(--bg-search); }
#settings-screen { background: var(--bg-settings); }

/* ── Screen Logo ── */
.screen-logo {
  display: block;
  width: 240px;
  max-width: 55vw;
  height: auto;
  margin: 0 auto 8px;
  opacity: 0.9;
}

/* ── Auth Screen ── */
#auth-screen {
  justify-content: center;
  align-items: center;
  gap: 24px;
}

#auth-screen h1 {
  font-size: 28px;
  font-weight: 700;
}

#auth-screen p {
  color: var(--text-secondary);
  text-align: center;
  max-width: 300px;
}

/* ── Bottom Navigation ── */
#bottom-nav {
  display: flex;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color var(--transition);
}

.nav-btn.active {
  color: var(--accent);
}

.nav-btn svg {
  width: 24px;
  height: 24px;
}

/* ── Inputs ── */
input[type="text"],
input[type="password"],
input[type="date"],
input[type="time"],
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

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

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-button);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

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

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

.btn-small {
  padding: 8px 16px;
  font-size: 14px;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}

/* ── Capture Screen ── */
#capture-screen {
  gap: 16px;
  align-items: center;
  padding: 20px 24px;
}

/* Spacer to push content down a bit */
#capture-screen::before {
  content: '';
  flex: 0 0 2vh;
}

/* ── Note Body — auto-expanding, prominent ── */
#note-body {
  width: 100%;
  max-width: 600px;
  min-height: 48px;
  max-height: 220px;
  font-size: 20px;
  line-height: 1.5;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin: 8px 0 4px;
  flex: 0 0 auto;
  resize: none;
  overflow-y: auto;
  field-sizing: content;
}

#note-body:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ── Keywords — narrower, centered ── */
#keywords-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: 60%;
  max-width: 360px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  position: relative;
}

.keyword-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--accent-soft);
  border-radius: 20px;
  font-size: 14px;
  color: var(--text-primary);
}

.keyword-chip button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}

#keyword-input {
  flex: 1;
  min-width: 100px;
  border: none;
  background: transparent;
  padding: 6px 0;
  font-size: 15px;
  box-shadow: none;
}

#keyword-input:focus {
  box-shadow: none;
  border: none;
}

/* Keyword autocomplete dropdown */
#keyword-autocomplete {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 160px;
  overflow-y: auto;
  z-index: 20;
  display: none;
}

#keyword-autocomplete.visible {
  display: block;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

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

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--bg-card);
}

/* ── 5W Collapsible — centered ── */
#details-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 0;
  width: 100%;
  max-width: 600px;
}

#details-toggle .arrow {
  transition: transform var(--transition);
}

#details-toggle.open .arrow {
  transform: rotate(90deg);
}

#details-section {
  display: none;
  gap: 10px;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
}

#details-section.open {
  display: flex;
}

#details-section label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

/* ── Metadata buttons ── */
#metadata-pills {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 600px;
  justify-content: center;
}

.meta-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.meta-btn:hover {
  border-color: var(--border-focus);
}

.meta-btn .meta-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.meta-btn .meta-btn-label {
  font-weight: 500;
}

.meta-btn .meta-value {
  color: var(--text-primary);
  font-size: 13px;
}

/* ── Time Picker Popover ── */
#time-picker-popover {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}

#time-picker-popover.visible {
  display: flex;
}

#time-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

#time-picker-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 320px;
  width: calc(100% - 32px);
  z-index: 1;
}

#time-picker-content h3 {
  font-size: 16px;
  margin-bottom: 14px;
  color: var(--text-primary);
}

.time-picker-field {
  margin-bottom: 12px;
}

.time-picker-field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.time-picker-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.time-picker-actions .btn {
  flex: 1;
}

/* ── Save Button ── */
#save-btn {
  width: 100%;
  max-width: 600px;
  position: relative;
  overflow: hidden;
  background: transparent;
  border: 2px solid var(--success);
  color: var(--success);
  border-radius: var(--radius-button);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  z-index: 1;
  flex-shrink: 0;
}

#save-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--success);
  transform: scaleX(0);
  transform-origin: left;
  transition: none;
  z-index: -1;
}

#save-btn.saving::before {
  transform: scaleX(1);
  transition: transform 700ms cubic-bezier(0.4, 0, 0.2, 1);
}

#save-btn.saving {
  color: #fff;
  transition: color 200ms ease;
}

#save-btn.saved {
  color: #fff;
  background: var(--success);
  border-color: var(--success);
}

#save-btn.saved::before {
  transform: scaleX(1);
}

/* Fade-out exit animation */
#save-btn.resetting {
  animation: saveFadeOut 600ms ease forwards;
}

#save-btn.resetting::before {
  transform: scaleX(0);
  transition: none;
}

@keyframes saveFadeOut {
  0% {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
  100% {
    background: transparent;
    color: var(--success);
    border-color: var(--success);
    opacity: 1;
  }
}

/* ── Enrichment Toast ── */
#enrichment-toast {
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: none;
  align-items: center;
  gap: 12px;
  z-index: 50;
  animation: slideUp 0.2s ease;
}

#enrichment-toast.visible {
  display: flex;
}

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

#enrichment-toast .toast-text {
  flex: 1;
  font-size: 15px;
}

#enrichment-toast .toast-actions {
  display: flex;
  gap: 8px;
}

/* ── Save confirmation (hidden — replaced by button animation) ── */
#save-confirmation {
  display: none !important;
}

/* ── Search Screen ── */
#search-screen {
  gap: 16px;
  padding: 20px 24px;
}

#search-input {
  font-size: 18px;
}

/* Search query chip */
#search-query-chip {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  align-self: flex-start;
  transition: border-color var(--transition);
}

#search-query-chip:hover {
  border-color: var(--border-focus);
}

#search-query-chip.visible {
  display: inline-flex;
}

#search-query-chip .chip-icon {
  font-size: 12px;
  color: var(--text-muted);
}

#criteria-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
}

.criteria-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--accent-soft);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-primary);
}

.criteria-chip button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
}

/* ── Search Results ── */
#search-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
}

.result-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color var(--transition);
}

.result-card:hover {
  border-color: var(--border-focus);
}

.result-card .result-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.match-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}

.match-dot.match-strong { background: #4ade80; }
.match-dot.match-good { background: #facc15; }
.match-dot.match-partial { background: #fb923c; }
.match-dot.match-weak { background: #ef4444; }

.result-card .note-body {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  flex: 1;
}

.result-card .note-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.result-card .context-summary {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.result-card .match-explanation {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.match-pill {
  padding: 3px 8px;
  background: var(--accent-soft);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Token Inspector Modal ── */
#token-inspector-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: none;
  align-items: center;
  justify-content: center;
}

#token-inspector-modal.visible {
  display: flex;
}

#token-inspector-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

#token-inspector-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 420px;
  width: calc(100% - 32px);
  max-height: 70vh;
  overflow-y: auto;
  z-index: 1;
}

#token-inspector-content h3 {
  font-size: 16px;
  margin-bottom: 14px;
  color: var(--text-primary);
}

#token-inspector-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.token-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.token-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  margin-right: 8px;
}

.token-type-keyword { background: #3b82f620; color: #60a5fa; }
.token-type-location { background: #22c55e20; color: #4ade80; }
.token-type-time { background: #f59e0b20; color: #fbbf24; }
.token-type-solar { background: #f9731620; color: #fb923c; }
.token-type-season { background: #a78bfa20; color: #a78bfa; }
.token-type-entity_type { background: #ec489920; color: #f472b6; }
.token-type-entity { background: #ec489920; color: #f472b6; }
.token-type-weather { background: #06b6d420; color: #22d3ee; }

.token-value {
  font-size: 14px;
  color: var(--text-primary);
}

.token-expansions {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Location Modal ── */
#location-modal {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 200;
  display: none;
  flex-direction: column;
}

#location-modal.visible {
  display: flex;
}

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

#location-modal .modal-header h2 {
  font-size: 18px;
}

#location-map {
  flex: 1;
}

#location-search {
  margin: 12px 16px;
}

#location-search-results {
  max-height: 200px;
  overflow-y: auto;
  margin: 0 16px;
}

.location-result {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}

.location-result:hover {
  background: var(--bg-secondary);
}

#location-name-input {
  margin: 12px 16px;
}

#location-modal .modal-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

/* ── Settings Screen ── */
#settings-screen {
  gap: 24px;
  padding: 20px 24px;
}

#settings-screen h2 {
  font-size: 20px;
}

.settings-section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 16px;
}

.settings-section h3 {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ── Theme Toggle ── */
.theme-toggle {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  overflow: hidden;
}

.theme-toggle button {
  flex: 1;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border-radius: var(--radius-button);
}

.theme-toggle button.active {
  background: var(--accent);
  color: #fff;
}

/* ── Offline Banner ── */
#offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: white;
  text-align: center;
  padding: 4px;
  font-size: 12px;
  display: none;
  z-index: 300;
}

#offline-banner.visible {
  display: block;
}

/* ── Loading spinner ── */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Leaflet overrides ── */
.leaflet-control-zoom a {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
}
