/* ==========================================================================
   components.css — Custom M3 Component Styles
   All colors via var(--md-sys-*) references — zero hardcoded hex
   ========================================================================== */

/* ==========================================================================
   Page Layout
   ========================================================================== */

body {
  background: var(--md-sys-color-surface-dim);
  margin: 0;
  padding: 24px 16px;
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  min-height: 100vh;
  font-family: var(--md-ref-typeface-plain), system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Glass Card Container
   ========================================================================== */

.capture-card {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: color-mix(in srgb, var(--md-sys-color-surface) 80%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-outline) 20%, transparent);
  box-shadow: var(--md-sys-elevation-level2);
  padding: 24px;
}

@supports not (backdrop-filter: blur(1px)) {
  .capture-card {
    background: var(--md-sys-color-surface-container-low);
  }
}

@media (prefers-color-scheme: dark) {
  .capture-card {
    border: 1px solid color-mix(in srgb, var(--md-sys-color-primary) 15%, transparent);
    box-shadow: var(--md-sys-elevation-level2),
                inset 0 1px 0 color-mix(in srgb, var(--md-sys-color-primary) 5%, transparent);
  }
}

/* ==========================================================================
   Navigation Bar
   ========================================================================== */

.nexus-nav {
  display: flex;
  justify-content: center;
  gap: 4px;
  max-width: 480px;
  margin: 0 auto 16px;
  padding: 4px;
  background: color-mix(in srgb, var(--md-sys-color-surface-container) 80%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--md-sys-shape-corner-full);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-outline) 15%, transparent);
}

/* On pages with wider cards (tasks, notes, lists), stretch the nav to match */
body:has(.tasks-card) .nexus-nav,
body:has(.notes-card) .nexus-nav,
body:has(.lists-card) .nexus-nav {
  max-width: 720px;
}

.nav-link {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: var(--md-sys-typescale-label-large-size);
  font-weight: var(--md-sys-typescale-label-large-weight);
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  transition: background var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.nav-link:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.nav-link.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

/* ==========================================================================
   Capture Type Toggle
   ========================================================================== */

.capture-type-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.capture-type-toggle md-filter-chip {
  flex: 1;
}

/* Note color picker */
.note-color-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.note-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: border-color 0.15s, transform 0.15s;
}

.note-swatch:hover {
  transform: scale(1.15);
}

.note-swatch.selected {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--md-sys-color-primary) 30%, transparent);
}

.note-swatch[data-color="none"] { background: var(--md-sys-color-outline); }
.note-swatch[data-color="red"] { background: #c62828; }
.note-swatch[data-color="orange"] { background: #e65100; }
.note-swatch[data-color="yellow"] { background: #f9a825; }
.note-swatch[data-color="green"] { background: #2e7d32; }
.note-swatch[data-color="teal"] { background: #00695c; }
.note-swatch[data-color="blue"] { background: #1565c0; }
.note-swatch[data-color="gray"] { background: #616161; }

/* Pin label */
.pin-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--md-sys-typescale-body-medium-size);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
}

/* ==========================================================================
   Capture Header
   ========================================================================== */

.capture-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.capture-title {
  font-size: var(--md-sys-typescale-headline-small-size);
  font-weight: var(--md-sys-typescale-headline-small-weight);
  line-height: var(--md-sys-typescale-headline-small-line-height);
  color: var(--md-sys-color-on-surface);
  margin: 0;
}

/* ==========================================================================
   Form Field Spacing
   ========================================================================== */

.form-field {
  margin-bottom: 16px;
}

md-outlined-text-field,
md-outlined-select {
  width: 100%;
}

/* ==========================================================================
   Section Labels
   ========================================================================== */

.section-label {
  font-size: var(--md-sys-typescale-label-large-size);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  line-height: var(--md-sys-typescale-label-large-line-height);
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 8px;
  margin-top: 0;
}

@media (prefers-color-scheme: dark) {
  .section-label {
    color: var(--md-sys-color-primary);
  }
}

/* ==========================================================================
   Form Section
   ========================================================================== */

.form-section {
  margin-bottom: 16px;
}

/* ==========================================================================
   Custom Tag Row
   ========================================================================== */

.custom-tag-row {
  margin-top: 8px;
}

/* ==========================================================================
   Schedule Toggle
   ========================================================================== */

.schedule-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--md-sys-typescale-body-large-size);
  transition: background var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
              border-radius var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.schedule-toggle[aria-expanded="true"] {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

/* ==========================================================================
   Toggle Arrow
   ========================================================================== */

.toggle-arrow {
  transition: transform var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
  margin-left: auto;
}

.schedule-toggle[aria-expanded="true"] .toggle-arrow {
  transform: rotate(90deg);
}

/* ==========================================================================
   Schedule Fields Panel
   ========================================================================== */

.schedule-fields {
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-top: none;
  border-radius: 0 0 var(--md-sys-shape-corner-medium) var(--md-sys-shape-corner-medium);
  padding: 16px;
}

.schedule-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

@media (max-width: 379px) {
  .schedule-row {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Toast Notification
   ========================================================================== */

.toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  left: max(16px, env(safe-area-inset-left, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  max-width: 440px;
  margin: 0 auto;
  padding: 12px 20px;
  border-radius: var(--md-sys-shape-corner-medium);
  font-size: var(--md-sys-typescale-body-medium-size);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s, transform 0.3s, bottom 0.3s;
  z-index: 100;
  text-align: center;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.toast.success {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  border: 1px solid var(--md-sys-color-tertiary);
}

@media (prefers-color-scheme: dark) {
  .toast.success {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border: 1px solid var(--md-sys-color-primary);
  }
}

.toast.error {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  border: 1px solid var(--md-sys-color-error);
}

/* ==========================================================================
   Keyboard Hint
   ========================================================================== */

.kbd-hint {
  text-align: center;
  margin-top: 12px;
  font-size: var(--md-sys-typescale-body-small-size);
  color: var(--md-sys-color-on-surface-variant);
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-small);
  font-size: var(--md-sys-typescale-label-small-size);
  font-family: monospace;
}

/* ==========================================================================
   Batch Mode Row
   ========================================================================== */

.batch-row {
  padding: 4px 0;
}

.batch-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: var(--md-sys-typescale-body-medium-size);
  color: var(--md-sys-color-on-surface);
}

/* ==========================================================================
   Mic Button Hidden
   ========================================================================== */

.mic-btn-hidden {
  display: none !important;
}

/* ==========================================================================
   Mic Button Active State
   ========================================================================== */

.mic-active {
  --md-icon-button-icon-color: var(--md-sys-color-error);
}

/* ==========================================================================
   Form Actions
   ========================================================================== */

.form-actions {
  margin-top: 8px;
}

.form-actions md-filled-button {
  width: 100%;
}

/* ==========================================================================
   Visually Hidden (Screen Reader Only)
   ========================================================================== */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ==========================================================================
   M3 Responsive Breakpoints
   Compact: 0-599px (default), Medium: 600-839px, Expanded: 840px+
   ========================================================================== */

/* --- Very small screens (< 380px) --- */
@media (max-width: 379px) {
  .capture-card {
    padding: 16px 12px;
  }
  .chip-grid {
    gap: 6px;
  }
  .capture-title {
    font-size: var(--md-sys-typescale-title-large-size);
  }
}

/* --- Medium (600-839px) --- */
@media (min-width: 600px) {
  body {
    padding: 32px 24px;
  }
  .capture-card {
    padding: 28px;
    max-width: 560px;
  }
  .schedule-row {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

/* --- Expanded (840px+) --- */
@media (min-width: 840px) {
  body {
    padding: 40px 32px;
  }
  .capture-card {
    max-width: 600px;
  }
}

/* ==========================================================================
   M3 Touch Target — 48px minimum for accessibility
   ========================================================================== */

md-filter-chip,
md-assist-chip {
  min-height: 48px;
}

md-filled-button,
md-outlined-button,
md-text-button {
  min-height: 48px;
}

.schedule-toggle {
  min-height: 48px;
}

/* ==========================================================================
   Keyboard Focus Outlines — M3 primary color ring
   ========================================================================== */

:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
  border-radius: var(--md-sys-shape-corner-small);
}

md-outlined-text-field:focus-within,
md-outlined-select:focus-within {
  --md-outlined-text-field-focus-outline-color: var(--md-sys-color-primary);
}

/* ==========================================================================
   Batch Counter Badge
   ========================================================================== */

.batch-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--md-sys-shape-corner-full, 9999px);
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  font-size: var(--md-sys-typescale-label-small-size);
  font-weight: var(--md-sys-typescale-label-small-weight);
  margin-left: auto;
}

/* ==========================================================================
   Offline Pending Badge
   ========================================================================== */

.offline-badge {
  padding: 8px 16px;
  border-radius: var(--md-sys-shape-corner-small);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-size: var(--md-sys-typescale-body-small-size);
  text-align: center;
  margin-bottom: 12px;
}

/* ==========================================================================
   SW Update Banner
   ========================================================================== */

.sw-update-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  font-size: var(--md-sys-typescale-body-medium-size);
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Shift toast above the SW update banner when both are visible */
body:has(.sw-update-banner:not([hidden])) .toast {
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

.sw-update-btn {
  padding: 6px 16px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full, 9999px);
  background: var(--md-sys-color-inverse-primary);
  color: var(--md-sys-color-on-primary);
  font-size: var(--md-sys-typescale-label-large-size);
  font-weight: var(--md-sys-typescale-label-large-weight);
  cursor: pointer;
  min-height: 48px;
}

.sw-update-dismiss {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-inverse-on-surface);
  font-size: var(--md-sys-typescale-title-large-size);
  cursor: pointer;
  line-height: 1;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   Suggested Tag Indicator — subtle primary outline for server-suggested tags
   ========================================================================== */

md-filter-chip[data-suggested="true"]:not([selected]) {
  --md-filter-chip-outline-color: var(--md-sys-color-primary);
  opacity: 1;
}

/* ==========================================================================
   Syncthing Status Dot
   ========================================================================== */

.sync-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}

.sync-dot-indicator {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--md-sys-color-outline);
  transition: background 0.3s;
}

.sync-dot[data-status="idle"] .sync-dot-indicator {
  background: #4CAF50;
}

.sync-dot[data-status="syncing"] .sync-dot-indicator {
  background: #FFB300;
}

.sync-dot[data-status="error"] .sync-dot-indicator {
  background: #E53935;
}

/* ==========================================================================
   Syncthing Status Overlay
   ========================================================================== */

.sync-overlay {
  position: absolute;
  top: 56px;
  right: 0;
  width: 280px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: var(--md-sys-elevation-level2);
  z-index: 50;
  overflow: hidden;
}

.sync-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: var(--md-sys-typescale-title-small-size);
  font-weight: var(--md-sys-typescale-title-small-weight);
  color: var(--md-sys-color-on-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.sync-overlay-close {
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.sync-overlay-body {
  padding: 12px 16px;
  font-size: var(--md-sys-typescale-body-small-size);
  color: var(--md-sys-color-on-surface-variant);
  max-height: 240px;
  overflow-y: auto;
}

.sync-overlay-body .sync-device,
.sync-overlay-body .sync-folder {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.sync-overlay-body .sync-device-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sync-overlay-body .sync-folder-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--md-sys-color-surface-container-high);
  overflow: hidden;
}

.sync-overlay-body .sync-folder-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--md-sys-color-primary);
  transition: width 0.3s;
}

/* ==========================================================================
   Smooth Scroll for Long Forms
   ========================================================================== */

html {
  scroll-behavior: smooth;
}

/* ==========================================================================
   Attachment Row (1B-09)
   ========================================================================== */

.attachment-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full, 9999px);
  color: var(--md-sys-color-primary);
  font-size: var(--md-sys-typescale-label-large-size);
  font-family: inherit;
  cursor: pointer;
  min-height: 36px;
}

.attach-btn:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
  border-color: var(--md-sys-color-primary);
}

.attach-btn-icon {
  font-size: 16px;
}

.attachment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--md-sys-color-secondary-container);
  border-radius: var(--md-sys-shape-corner-full, 9999px);
  font-size: var(--md-sys-typescale-label-small-size);
  color: var(--md-sys-color-on-secondary-container);
  max-width: 220px;
}

.attachment-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip-remove {
  background: none;
  border: none;
  color: var(--md-sys-color-on-secondary-container);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  opacity: 0.7;
}

.attachment-chip-remove:hover {
  opacity: 1;
}
