/* ===== CSS RESET & VARIABLES ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Light theme (default) */
:root,
[data-theme="light"] {
  /* System Colors (iOS-like) */
  --accent: #007AFF;
  /* Apple Blue */
  --accent-dark: #0056B3;
  --accent-light: #E5F1FF;

  --bg: #F2F2F7;
  /* iOS System Grouped Background */
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;

  --text: #000000;
  --text-secondary: #8E8E93;
  --text-muted: #C7C7CC;

  --border: #E5E5EA;
  /* iOS Separator */

  --success: #34C759;
  --success-light: #D4F7DC;
  --warning: #FF9500;
  --warning-light: #FFF0D6;
  --danger: #FF3B30;
  --danger-light: #FFE5E5;

  --radius: 20px;
  /* More rounded */
  --radius-sm: 12px;

  --shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);

  --nav-height: 84px;
  --header-height: 60px;
  /* Taller header */
  --safe-bottom: env(safe-area-inset-bottom, 20px);
  --safe-top: env(safe-area-inset-top, 0px);

  --overlay: rgba(0, 0, 0, 0.4);
  --input-bg: #E3E3E8;
  /* iOS Search/Input fill */
  --mic-glow: rgba(0, 122, 255, 0.4);

  /* Tone colors */
  --tone-quick: #AF52DE;
  /* Purple */
  --tone-quick-bg: #Fbf4fe;
  --tone-friendly: #FF9500;
  --tone-friendly-bg: #FFF8E6;
  --tone-professional: #007AFF;
  --tone-professional-bg: #E5F1FF;
  --tone-flirty: #FF2D55;
  --tone-flirty-bg: #FFF0F3;
  --tone-bold: #FF9F0A;
  --tone-bold-bg: #FFF5E0;
  --tone-spicy: #FF6B6B;
  --tone-spicy-bg: #FFF0F0;
  --tone-literal: #8E8E93;
  --tone-literal-bg: #F2F2F7;

  /* Translucency */
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(0, 0, 0, 0.05);
}

/* Dark theme */
[data-theme="dark"] {
  --accent: #0A84FF;
  --accent-dark: #007AFF;
  --accent-light: #1C2C4E;

  --bg: #000000;
  --surface: #1C1C1E;
  /* iOS Dark System Gray 6 */
  --surface-raised: #2C2C2E;

  --text: #FFFFFF;
  --text-secondary: #8E8E93;
  --text-muted: #636366;

  --border: #38383A;

  --success: #30D158;
  --success-light: #0B3315;
  --warning: #FF9F0A;
  --warning-light: #4D2F00;
  --danger: #FF453A;
  --danger-light: #4D0F0D;

  --shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.4);

  --overlay: rgba(0, 0, 0, 0.7);
  --input-bg: #2C2C2E;
  --mic-glow: rgba(10, 132, 255, 0.5);

  --tone-quick: #BF5AF2;
  --tone-quick-bg: #2D183D;
  --tone-friendly: #FFD60A;
  --tone-friendly-bg: #3D3200;
  --tone-professional: #0A84FF;
  --tone-professional-bg: #0F2648;
  --tone-flirty: #FF375F;
  --tone-flirty-bg: #3D0F1A;
  --tone-bold: #FFD60A;
  --tone-bold-bg: #3D3200;
  --tone-spicy: #FF7B7B;
  --tone-spicy-bg: #3D1515;
  --tone-literal: #8E8E93;
  --tone-literal-bg: #2C2C2E;

  --glass-bg: rgba(28, 28, 30, 0.85);
  --glass-border: rgba(255, 255, 255, 0.1);
}

/* Auto dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --accent: #0A84FF;
    --accent-dark: #007AFF;
    --accent-light: #1C2C4E;

    --bg: #000000;
    --surface: #1C1C1E;
    --surface-raised: #2C2C2E;

    --text: #FFFFFF;
    --text-secondary: #8E8E93;
    --text-muted: #636366;

    --border: #38383A;

    --success: #30D158;
    --success-light: #0B3315;
    --warning: #FF9F0A;
    --warning-light: #4D2F00;
    --danger: #FF453A;
    --danger-light: #4D0F0D;

    --shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.4);

    --overlay: rgba(0, 0, 0, 0.7);
    --input-bg: #2C2C2E;
    --mic-glow: rgba(10, 132, 255, 0.5);

    --tone-quick: #BF5AF2;
    --tone-quick-bg: #2D183D;
    --tone-friendly: #FFD60A;
    --tone-friendly-bg: #3D3200;
    --tone-professional: #0A84FF;
    --tone-professional-bg: #0F2648;
    --tone-flirty: #FF375F;
    --tone-flirty-bg: #3D0F1A;
    --tone-bold: #FFD60A;
    --tone-bold-bg: #3D3200;
    --tone-spicy: #FF7B7B;
    --tone-spicy-bg: #3D1515;
    --tone-literal: #8E8E93;
    --tone-literal-bg: #2C2C2E;

    --glass-bg: rgba(28, 28, 30, 0.85);
    --glass-border: rgba(255, 255, 255, 0.1);
  }
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== VIEWS ===== */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.view.active {
  display: flex;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  padding-top: var(--safe-top);
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  min-height: var(--header-height);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.view-header h1 {
  font-size: 2.125rem;
  /* Large Title size */
  font-weight: 700;
  letter-spacing: -0.022em;
}

.header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.view-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

/* ===== BOTTOM NAV ===== */
#bottom-nav {
  display: flex;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--glass-border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.625rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
  position: relative;
  min-height: 56px;
}

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

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

.badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 20px);
  background: var(--danger);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 40px;
  /* Pill shape */
  padding: 16px 24px;
  font-size: 1.0625rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, opacity 0.2s;
  width: 100%;
  touch-action: manipulation;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

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

.btn-primary:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

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

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-danger:active {
  opacity: 0.8;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  min-width: 40px;
  min-height: 40px;
  font-size: 1.25rem;
}

.btn-icon:active {
  background: var(--bg);
}

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

.btn-large {
  padding: 16px 24px;
  font-size: 1.0625rem;
}

/* ===== FORM ELEMENTS ===== */
.field-group {
  margin-bottom: 16px;
}

.field-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap input {
  padding-right: 40px;
}

.input-action {
  position: absolute;
  right: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 16px;
  font-size: 1.0625rem;
  border: none;
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  transition: background 0.2s;
}

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

select {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ===== COMPOSE VIEW ===== */
.compose-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Hero Mic Button */
.mic-btn-hero {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 16px var(--mic-glow);
  margin: 24px 0 8px;
  flex-shrink: 0;
}

.mic-btn-hero:active {
  transform: scale(0.95);
}

.mic-btn-hero.listening {
  background: var(--danger);
  box-shadow: 0 0 0 8px var(--danger-light), 0 4px 16px rgba(220, 38, 38, 0.3);
  animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {

  0%,
  100% {
    box-shadow: 0 0 0 8px var(--danger-light), 0 4px 16px rgba(220, 38, 38, 0.3);
  }

  50% {
    box-shadow: 0 0 0 14px transparent, 0 4px 16px rgba(220, 38, 38, 0.1);
  }
}

#mic-status {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  text-align: center;
}

/* Compose text area wrapper */
.compose-text-wrap {
  width: 100%;
  position: relative;
}

.compose-text-wrap textarea {
  padding-right: 52px;
  resize: none;
  min-height: 56px;
}

.compose-submit-btn {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, opacity 0.15s;
}

.compose-submit-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.compose-submit-btn:active:not(:disabled) {
  background: var(--accent-dark);
}

/* Contact Picker (disambiguation) */
.contact-picker {
  width: 100%;
  margin-top: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.contact-picker-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 16px 8px;
}

.picker-option {
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
  min-height: 52px;
  transition: background 0.1s;
}

.picker-option:active {
  background: var(--accent-light);
}

.picker-option-name {
  font-weight: 500;
}

.picker-option-phone {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.contact-picker-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

.contact-picker-search input {
  flex: 1;
  padding: 10px 12px;
  font-size: 0.9375rem;
  border-radius: 8px;
}

.picker-mic-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--input-bg);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.picker-mic-btn:active {
  background: var(--accent-light);
  color: var(--accent);
}

.picker-mic-btn.listening {
  background: var(--danger);
  color: white;
}

/* Results Header */
.results-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  margin-bottom: 12px;
}

.results-header-to {
  font-size: 1rem;
  font-weight: 600;
}

.results-contact-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: inherit;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.results-contact-btn:active {
  background: var(--accent-light);
}

.results-header-reset {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
}

.results-header-reset:active {
  color: var(--text-secondary);
}

/* ===== MESSAGE RESULTS ===== */
.message-results {
  width: 100%;
  margin-top: 4px;
}

.results-heading {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.message-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, box-shadow 0.15s;
  border-left: 4px solid transparent;
  text-decoration: none;
  display: block;
  color: inherit;
}

.message-card:active {
  transform: scale(0.985);
  box-shadow: var(--shadow-md);
}

.message-card.tone-quick {
  border-left-color: var(--tone-quick);
}

.message-card.tone-friendly {
  border-left-color: var(--tone-friendly);
}

.message-card.tone-professional {
  border-left-color: var(--tone-professional);
}

.message-card.tone-flirty {
  border-left-color: var(--tone-flirty);
}

.message-card.tone-bold {
  border-left-color: var(--tone-bold);
}

.message-card.tone-spicy {
  border-left-color: var(--tone-spicy);
}

.message-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.message-card-tone {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
}

.tone-quick .message-card-tone {
  color: var(--tone-quick);
  background: var(--tone-quick-bg);
}

.tone-friendly .message-card-tone {
  color: var(--tone-friendly);
  background: var(--tone-friendly-bg);
}

.tone-professional .message-card-tone {
  color: var(--tone-professional);
  background: var(--tone-professional-bg);
}

.tone-flirty .message-card-tone {
  color: var(--tone-flirty);
  background: var(--tone-flirty-bg);
}

.tone-bold .message-card-tone {
  color: var(--tone-bold);
  background: var(--tone-bold-bg);
}

.tone-spicy .message-card-tone {
  color: var(--tone-spicy);
  background: var(--tone-spicy-bg);
}

.message-card.tone-literal {
  border-left-color: var(--tone-literal);
}

.tone-literal .message-card-tone {
  color: var(--tone-literal);
  background: var(--tone-literal-bg);
}

.message-card-send {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
}

.message-card-body {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text);
}

/* ===== LOADING ===== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 12px;
  width: 100%;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-state p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

/* ===== CONTACTS LIST ===== */
.search-bar {
  padding: 12px 16px 0;
}

.contacts-list {
  padding: 12px 16px;
}

.contact-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s;
  min-height: 56px;
}

.contact-item:active {
  transform: scale(0.985);
}

.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.contact-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.tag {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--accent-light);
  color: var(--accent);
  white-space: nowrap;
}

.contact-arrow {
  color: var(--text-muted);
  margin-left: 8px;
  flex-shrink: 0;
}

/* ===== NURTURE VIEW ===== */
.nurture-list {
  padding: 12px 16px;
}

.nurture-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.nurture-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.nurture-name {
  font-weight: 600;
  font-size: 1rem;
}

.nurture-urgency {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 100px;
}

.urgency-overdue {
  background: var(--danger-light);
  color: var(--danger);
}

.urgency-due-soon {
  background: var(--warning-light);
  color: var(--warning);
}

.urgency-upcoming {
  background: var(--accent-light);
  color: var(--accent);
}

.nurture-detail {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.nurture-detail span {
  display: inline-block;
  margin-right: 12px;
}

.nurture-action {
  display: flex;
  gap: 8px;
}

.nurture-action .btn-primary {
  width: auto;
  flex: 1;
  padding: 10px 16px;
  font-size: 0.9375rem;
}

/* ===== SETTINGS ===== */
.settings-content {
  padding: 16px;
}

.settings-group {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.settings-group h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.settings-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.toggle-row-label {
  font-size: 0.9375rem;
  font-weight: 500;
}

.toggle-switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-track {
  background: var(--accent);
}

.toggle-switch input:checked+.toggle-track::after {
  transform: translateX(20px);
}

.tags-manager {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tag-managed {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 6px 8px 6px 10px;
  border-radius: 100px;
}

.tag-managed .tag-days {
  font-size: 0.6875rem;
  opacity: 0.7;
}

.tag-managed button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
  opacity: 0.6;
  line-height: 1;
}

.add-tag-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-tag-row input {
  flex: 1;
}

.data-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== TAG PICKER (in modal) ===== */
.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-option {
  display: flex;
}

.tag-option input {
  display: none;
}

.tag-option label {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 100px;
  border: 1.5px solid var(--border);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}

.tag-option input:checked+label {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 16px;
  padding-bottom: calc(20px + var(--safe-bottom));
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

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

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.modal-actions .btn-primary {
  flex: 1;
}

/* ===== FILE DROP ===== */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text-secondary);
}

.file-drop:active,
.file-drop.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.file-drop svg {
  margin-bottom: 8px;
  opacity: 0.5;
}

.file-drop p {
  font-size: 0.9375rem;
}

.import-preview {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.import-preview .preview-count {
  font-weight: 600;
  color: var(--accent);
}

.import-help {
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.import-help summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
}

.import-help ol {
  margin-top: 8px;
  padding-left: 20px;
  line-height: 1.6;
}

/* ===== EMPTY STATES ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 32px;
  text-align: center;
}

.empty-icon {
  color: var(--text-muted);
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  max-width: 280px;
  line-height: 1.5;
}

.empty-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.empty-actions .btn-primary,
.empty-actions .btn-secondary {
  width: auto;
  padding: 12px 20px;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  left: 16px;
  right: 16px;
  background: var(--text);
  color: var(--bg);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: center;
  z-index: 200;
  animation: toastIn 0.25s ease-out;
  box-shadow: var(--shadow-lg);
}

.toast.hidden {
  display: none;
}

@keyframes toastIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ===== UTILITIES ===== */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ===== PHONETIC DISAMBIGUATION ===== */
.picker-option-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.picker-option-pronunciation {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--text-muted);
}

.label-hint {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.phonetic-alt-hint {
  width: 100%;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 4px;
  margin-bottom: 4px;
}

.phonetic-switch-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.phonetic-switch-link:active {
  opacity: 0.7;
}

.pick-contact-hint {
  width: 100%;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 4px;
  margin-bottom: 4px;
}

/* ===== RESULTS OPTIONS (name/sign-off toggles) ===== */
.results-options {
  width: 100%;
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.option-chip {
  padding: 6px 14px;
  border-radius: 100px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}

.option-chip:active {
  transform: scale(0.97);
}

.option-chip.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== QUICK TAG ASSIGNMENT ===== */
.results-quick-tags {
  width: 100%;
  margin-top: 24px;
}

.results-quick-tags-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.results-tag-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-tag-chip {
  padding: 6px 14px;
  border-radius: 100px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}

.quick-tag-chip:active {
  transform: scale(0.97);
}

.quick-tag-chip.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== STYLE SAMPLES ===== */
.style-samples-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.style-sample {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.style-sample-content {
  flex: 1;
  min-width: 0;
}

.style-sample-type {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 2px;
}

.style-sample-preview {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.style-sample-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.125rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

.style-sample-remove:active {
  color: var(--danger);
}

.style-add-methods {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.style-add-methods .btn-small {
  flex: 1;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  font-size: 0.8125rem;
  padding: 8px 10px;
}

.style-input-area {
  margin-top: 12px;
}

.style-input-area textarea {
  margin-bottom: 8px;
}

.style-input-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.style-input-actions .btn-small {
  width: auto;
  padding: 8px 16px;
}

.style-input-actions .btn-primary {
  width: auto;
  padding: 8px 16px;
  box-shadow: none;
}

.style-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.style-loading .spinner {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

.style-loading span {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ===== AUTH VIEW ===== */
.auth-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  background: var(--bg);
}

.auth-view.hidden {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px 24px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
}

.auth-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--accent);
  color: white;
  font-size: 2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.022em;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.auth-form {
  text-align: left;
}

.auth-tabs {
  display: flex;
  background: var(--input-bg);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.auth-form .btn-primary {
  margin-top: 8px;
}

.auth-forgot-link {
  display: block;
  text-align: center;
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--accent);
  text-decoration: none;
}

.auth-forgot-link:active {
  opacity: 0.7;
}

.auth-divider {
  display: flex;
  align-items: center;
  margin: 20px 0;
  gap: 12px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-divider span {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.auth-google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-radius: 40px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  font-family: inherit;
}

.auth-google-btn:active {
  background: var(--bg);
}

.auth-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  text-align: center;
}

.auth-loading {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

/* App loading overlay (shown during SyncStore init) */
.app-loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 9999;
}

.app-loading-overlay .spinner {
  width: 40px;
  height: 40px;
}

.app-loading-overlay p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

/* ===== DESKTOP ENHANCEMENT ===== */
@media (min-width: 640px) {
  #app {
    max-width: 480px;
    margin: 0 auto;
    box-shadow: var(--shadow-lg);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  body {
    background: var(--bg);
  }
}