/* ═══════════════════════════════════════════════════════
   FAMILIA FORMULARIO — Estilos (Vanilla, sin framework)
   Color scheme: teal-700 primary, amber accents, clean whites
   FULLY MOBILE-OPTIMIZED
   ═══════════════════════════════════════════════════════ */

:root {
  --bg: #f6f7f9; --surface: #ffffff; --border: #e5e7eb;
  --text: #111827; --muted: #6b7280; --primary: #0f766e;
  --primary-dark: #0d5d57; --accent: #b45309; --danger: #b91c1c;
  --teal-50: #f0fdfa; --amber-50: #fffbeb; --red-50: #fef2f2;
  --gray-50: #f9fafb; --gray-100: #f3f4f6; --gray-200: #e5e7eb;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg); color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Pretendard', 'Noto Sans KR', sans-serif;
  -webkit-font-smoothing: antialiased; line-height: 1.5;
  /* Prevent iOS bounce */
  overscroll-behavior-y: contain;
}

/* iPhone safe-area (notch/bottom bar) */
html {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ═══ MOBILE-ONLY BASE RULES (everything below is optimized for phone first) ═══ */

/* ── Header ── */
.app-header {
  position: sticky; top: 0; z-index: 30;
  border-bottom: 1px solid var(--border); background: rgba(255,255,255,0.95);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.header-inner { max-width: 56rem; margin: 0 auto; padding: 0.75rem 0.875rem; }
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.header-title h1 { font-size: 1.125rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.header-title p { font-size: 0.75rem; color: var(--muted); margin-top: 0; }

/* Language toggle - bigger tap target for mobile */
.lang-toggle { display: flex; border: 1px solid #d1d5db; border-radius: 0.5rem; overflow: hidden; }
.lang-btn {
  min-width: 48px; min-height: 36px;
  border-radius: 0.375rem; padding: 0.375rem 0.75rem; font-size: 0.8125rem;
  font-weight: 600; transition: all 0.15s; cursor: pointer; background: none; border: none;
  display: flex; align-items: center; justify-content: center;
}
.lang-btn.active { background: var(--primary); color: #fff; }
.lang-btn:not(.active) { background: #fff; color: var(--muted); }
.lang-btn:not(.active):hover { background: var(--gray-100); }

/* View tabs - scrollable on mobile */
.view-tabs { display: flex; gap: 0.25rem; margin-top: 0.625rem; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; padding-bottom: 0.125rem; }
.view-tabs::-webkit-scrollbar { display: none; }
.view-tab {
  flex-shrink: 0;
  border-radius: 0.5rem; padding: 0.5rem 1rem; font-size: 0.875rem;
  font-weight: 500; transition: all 0.15s; cursor: pointer; background: none; border: none; color: var(--muted);
  min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.view-tab.active { background: var(--primary); color: #fff; }
.view-tab:not(.active):hover { background: var(--gray-100); }

/* ── Member tabs - horizontal scrollable on mobile ── */
.member-tabs {
  display: flex; gap: 0.375rem; margin-bottom: 1rem;
  overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none;
  padding: 0.25rem 0.125rem 0.5rem; /* space for scrollbar */
}
.member-tabs::-webkit-scrollbar { display: none; }
.member-tab {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 0.375rem;
  border-radius: 9999px; padding: 0.625rem 1.125rem; font-size: 0.875rem;
  font-weight: 500; cursor: pointer; transition: all 0.15s; border: 1px solid var(--border); background: #fff; color: var(--text);
  min-height: 44px; /* iOS touch target */
}
.member-tab .emoji { font-size: 1rem; }
.member-tab.active-household { border-color: var(--accent); background: var(--accent); color: #fff; }
.member-tab.active-member { border-color: var(--primary); background: var(--primary); color: #fff; }
.member-tab:not(.active):hover { background: var(--gray-50); }

/* ── Card ── */
.card {
  border-radius: 0.75rem; border: 1px solid var(--border); background: var(--surface);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04); padding: 1rem;
}

/* ── Section title ── */
.section-title { font-size: 1.125rem; font-weight: 600; color: var(--text); }

/* ── Category section ── */
.cat-section { border-radius: 0.75rem; border: 1px solid var(--border); background: var(--surface); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.cat-header { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 1rem; text-align: left; cursor: pointer; border: none; background: none; transition: background 0.15s; }
.cat-header:hover { background: var(--gray-50); }
.cat-header-left { display: flex; align-items: center; gap: 0.75rem; }
.cat-icon { width: 2.25rem; height: 2.25rem; border-radius: 0.5rem; background: var(--teal-50); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }
.cat-title h3 { font-size: 1rem; font-weight: 600; color: var(--text); }
.cat-title p { font-size: 0.75rem; color: var(--muted); margin-top: 0; }
.cat-chevron { color: var(--muted); font-size: 1.25rem; transition: transform 0.2s; }

/* ── Fields grid - full width on mobile ── */
.fields-grid {
  border-top: 1px solid var(--gray-100);
  padding: 0.875rem;
  display: grid;
  gap: 0.875rem;
  animation: fadein 0.18s ease-out;
}
.field-col { min-width: 0; }

/* ── Field label ── */
.field-label { font-size: 0.875rem; font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 0.5rem; }
.badge-dynamic {
  display: inline-flex; align-items: center; gap: 0.25rem; border-radius: 9999px;
  padding: 0.125rem 0.625rem; font-size: 0.75rem; font-weight: 500;
  background: var(--amber-50); color: var(--accent); border: 1px solid #fde68a;
}
.badge-required {
  display: inline-flex; align-items: center; gap: 0.25rem; border-radius: 9999px;
  padding: 0.125rem 0.625rem; font-size: 0.75rem; font-weight: 500;
  background: var(--red-50); color: var(--danger); border: 1px solid #fecaca;
}

/* ── Field input - bigger tap targets, font-size 16px prevents iOS zoom ── */
.field-input {
  width: 100%; border-radius: 0.5rem; border: 1px solid var(--border); background: #fff;
  padding: 0.75rem 0.875rem; font-size: 16px; /* prevents iOS auto-zoom */
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04); transition: border-color 0.15s, box-shadow 0.15s;
}
.field-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,0.12); }
.field-input::placeholder { color: #9ca3af; }
textarea.field-input { min-height: 96px; resize: vertical; }

/* ── Multiselect chips ── */
.multi-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.multi-chip {
  border-radius: 0.375rem; padding: 0.375rem 0.75rem; font-size: 0.875rem;
  cursor: pointer; transition: all 0.15s; border: 1px solid var(--border); background: #fff; color: var(--text);
}
.multi-chip.active { border-color: var(--primary-dark, #0d5d57); background: var(--teal-50); color: var(--primary-dark, #0d5d57); }

/* ── Buttons - bigger tap targets for mobile ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.375rem; border-radius: 0.625rem;
  padding: 0.75rem 1rem; font-size: 0.9375rem; font-weight: 500;
  transition: all 0.15s; cursor: pointer; min-height: 48px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark, #0d5d57); }
.btn-primary:active { transform: scale(0.97); }
.btn-ghost { background: none; color: var(--text); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-outline { border: 1px solid var(--border); background: #fff; color: var(--text); }
.btn-outline:hover { background: var(--gray-50); }
.btn-outline:active { transform: scale(0.97); }
.btn-danger { border: 1px solid #fecaca; background: #fff; color: var(--danger); }
.btn-danger:hover { background: var(--red-50); }
.btn-danger:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.5rem 0.625rem; font-size: 0.8125rem; min-height: 36px; }

/* ── Attachments panel - stacked on mobile ── */
.attach-panel {
  margin-top: 0.75rem; border-radius: 0.625rem;
  border: 1px dashed var(--border); background: rgba(249,250,251,0.6);
  padding: 0.875rem;
}
.attach-panel .attach-actions {
  display: flex; gap: 0.375rem; margin-top: 0.5rem;
  flex-wrap: wrap; /* allow wrap on small screens */
}
.attach-row {
  display: flex; align-items: center; gap: 0.625rem;
  margin-top: 0.5rem; padding: 0.625rem;
  border-radius: 0.5rem; border: 1px solid var(--border); background: #fff;
}
.attach-thumb {
  width: 48px; height: 48px; border-radius: 0.5rem;
  object-fit: cover; border: 1px solid var(--border);
}
.attach-info { min-width: 0; flex: 1; }
.attach-name { font-size: 0.875rem; font-weight: 500; color: var(--text); word-break: break-all; }
.attach-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.125rem; }
audio.attach-audio { width: 100%; max-width: 12rem; height: 2rem; margin-top: 0.375rem; }

/* ── Reminder card ── */
.reminder-card { border-radius: 0.75rem; padding: 0.75rem; border: 1px solid var(--border); background: #fff; }
.reminder-card.overdue { border-color: #fecaca; background: var(--red-50); }
.remider-title { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.remider-meta { display: flex; flex-wrap: gap: 0.375rem; margin-top: 0.25rem; font-size: 0.75rem; color: var(--muted); align-items: center; }

/* ── Modal - full screen on mobile ── */
.modal-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,0.4); }
.modal-box {
  width: 100%; max-width: 28rem;
  border-radius: 1rem 1rem 0 0;
  background: #fff;
  padding: 1.5rem 1.25rem;
  animation: slideup 0.25s ease-out;
}
@keyframes slideup {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@media (min-width: 641px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: 0.75rem; animation: fadein 0.18s ease-out; }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }

/* ── Export panel ── */
.export-pre { margin-top: 0.75rem; max-height: 18rem; overflow: auto; border-radius: 0.5rem; background: #111827; padding: 0.75rem; font-size: 0.75rem; line-height: 1.6; color: #f9fafb; white-space: pre-wrap; word-break: break-word; }

/* ── Summary card - single column on mobile ── */
.summary-card { display: grid; gap: 0.5rem; grid-template-columns: 1fr; }
.summary-item {
  display: flex; align-items: center; gap: 0.625rem;
  border-radius: 0.5rem; padding: 0.75rem; border: 1px solid var(--border); background: var(--gray-50);
}
.summary-label { font-size: 0.75rem; color: var(--muted); }
.summary-value { font-size: 0.875rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Group header ── */
.group-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0; margin-bottom: 0.75rem; }
.group-title { font-size: 0.875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.group-line { flex: 1; height: 1px; background: var(--gray-200); }

/* ── Loading & error ── */
.loading-wrap { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.spinner { width: 2rem; height: 2rem; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
.error-banner { margin-bottom: 1rem; border-radius: 0.375rem; border: 1px solid #fecaca; background: var(--red-50); padding: 0.75rem; font-size: 0.875rem; color: var(--danger); }

/* ── Main content area ── */
#main-content {
  max-width: 56rem;
  margin: 0 auto;
  padding: 1rem 0.875rem;
}

/* ═══ DESKTOP LAYOUT (from 641px up) ═══ */
@media (min-width: 641px) {
  #main-content { padding: 1.25rem 1rem; }
  .fields-grid { grid-template-columns: repeat(2, 1fr); }
}
.chip { display: inline-flex; align-items: center; gap: 0.25rem; border-radius: 9999px; padding: 0.125rem 0.625rem; font-size: 0.75rem; font-weight: 500; }
.chip-teal { background: var(--teal-50); color: var(--primary); border: 1px solid #99f6e4; }
.chip-amber { background: var(--amber-50); color: var(--accent); border: 1px solid #fde68a; }
.chip-gray { background: var(--gray-100); color: var(--muted); }

@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
.animate-fadein { animation: fadein 0.18s ease-out; }

/* ═══ RESPONSIVE BREAKPOINTS ═══ */
/* Tablet and up: two-column fields */
@media (min-width: 641px) {
  .fields-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .summary-card { grid-template-columns: repeat(2, 1fr); }
}

/* Desktop: three-column fields for wide screens */
@media (min-width: 900px) {
  .fields-grid { grid-template-columns: repeat(3, 1fr) !important; }
}

/* ── Export buttons - stack on mobile, side by side on desktop ── */
.export-btns {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
}
@media (max-width: 640px) {
  .export-btns { flex-direction: column; }
  .export-btns .btn { width: 100%; } /* full-width buttons on mobile */
}

/* ── Sticky action bar at bottom of modal on mobile ── */
.modal-actions {
  margin-top: 1rem;
  display: flex; gap: 0.5rem; justify-content: flex-end;
}
@media (max-width: 640px) {
  .modal-actions { position: sticky; bottom: 0; background: #fff; padding: 0.75rem 0; margin: 0.75rem -1.25rem 0; border-radius: 0; }
}

/* ── Dark mode support (optional, prefers-dark) ── */
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f172a; --surface: #1e293b; --text: #f1f5f9; --muted: #94a3b8; --border: #334155; }
  body { background: var(--bg); color: var(--text); }
  .field-input, .card { border-color: var(--border); background: var(--surface); color: var(--text); }
  .view-tab, .lang-btn:not(.active) { color: var(--muted); }
  .lang-btn:not(.active):hover, .view-tab:not(.active):hover { background: var(--border); }
}
