/* ============================================================================
   Goodtides Companion — app styles
   Mobile-first PWA. Reuses the brand tokens (cream/seafoam/teal/navy/gold)
   from the main shop but in a denser app-shell layout: top header, scrollable
   main view, fixed bottom tab bar, iOS-style modals.
   ========================================================================== */

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

:root {
  --ink: #0B2A3B;
  --ink-soft: #5C7080;
  --ink-faint: #8FA4B5;
  --bone: #EEE8DB;
  --bone-dark: #E6DECB;
  --seafoam: #8FB5A7;
  --gold: #D4A04C;
  --rose: #C97862;

  --serif: 'Lora', Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;

  --header-h: 60px;
  --tabbar-h: 64px;
  --radius: 14px;
}

html, body {
  height: 100%;
  background: var(--bone);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: var(--ink); }
button { font-family: inherit; cursor: pointer; }

/* ============ HEADER ============ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(238, 232, 219, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(11, 42, 59, 0.08);
  padding: max(env(safe-area-inset-top), 8px) 18px 8px;
}
.app-header-inner {
  max-width: 600px;
  margin: 0 auto;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-brand-name {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.3px;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
.app-brand-sub {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--seafoam);
  margin-top: 1px;
}
.app-header-sync {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(11, 42, 59, 0.1);
}
.app-header-sync.is-synced { color: var(--seafoam); border-color: rgba(143, 181, 167, 0.4); }

/* ============ VIEW SHELL ============ */
.view {
  flex: 1;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 18px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom));
}

.hero { margin-bottom: 24px; }
.eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 2.6px;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 10px;
}
.hero-h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(32px, 8vw, 42px);
  letter-spacing: -1.2px;
  line-height: 1.05;
  margin-bottom: 8px;
  color: var(--ink);
}
.hero-h1 em { font-style: italic; color: var(--gold); }
.hero-sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15.5px;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ============ FORM FIELDS ============ */
.calc-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
}
.field input,
.field select,
.field textarea {
  background: #fff;
  border: 1px solid rgba(11, 42, 59, 0.14);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--sans);
  font-size: 16px; /* 16px prevents iOS zoom-on-focus */
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235C7080' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  padding-right: 38px;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--seafoam);
  box-shadow: 0 0 0 3px rgba(143, 181, 167, 0.22);
}
.field textarea { resize: vertical; min-height: 60px; font-family: var(--serif); }

/* ============ BUTTONS ============ */
.btn-primary {
  background: var(--ink);
  color: var(--bone);
  border: none;
  border-radius: 999px;
  padding: 14px 24px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  width: 100%;
  margin-top: 6px;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:hover { background: #051B28; box-shadow: 0 8px 22px rgba(11, 42, 59, 0.25); }

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 12px 22px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  width: 100%;
  margin-top: 12px;
  transition: background 0.15s, color 0.15s;
}
.btn-secondary:hover { background: var(--ink); color: var(--bone); }

.btn-tertiary {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid rgba(11, 42, 59, 0.16);
  border-radius: 999px;
  padding: 10px 18px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  transition: color 0.15s, border-color 0.15s;
}
.btn-tertiary:hover { color: var(--ink); border-color: var(--ink); }

/* ============ CALC RESULT CARD ============ */
.calc-result { margin-top: 22px; }
.result-card {
  background: linear-gradient(to bottom right, #ffffff, #fbf8ef);
  border-radius: var(--radius);
  border: 1px solid rgba(11, 42, 59, 0.08);
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: 0 2px 14px rgba(11, 42, 59, 0.06);
}
.result-units {
  font-family: var(--serif);
  font-size: 64px;
  font-weight: 400;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -2px;
}
.result-unit-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 2.6px;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 4px;
}
.result-detail {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14.5px;
  color: var(--ink-soft);
  margin-top: 14px;
  line-height: 1.45;
}
.syringe-vis { margin-top: 18px; }
.syringe-vis svg { width: 100%; height: auto; display: block; }

/* ============ DISCLAIMER ============ */
.disclaimer {
  margin-top: 24px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 12.5px;
  color: var(--ink-faint);
  line-height: 1.55;
  text-align: center;
  padding: 0 8px;
}

/* ============ LOG ============ */
.log-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.log-actions .btn-secondary { margin-top: 0; flex: 1; }
.log-actions .btn-tertiary { margin-top: 0; }

.log-list { display: flex; flex-direction: column; gap: 10px; }
.log-entry {
  background: #fff;
  border-radius: 12px;
  border: 1px solid rgba(11, 42, 59, 0.07);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}
.log-entry:hover { box-shadow: 0 4px 16px rgba(11, 42, 59, 0.08); }
.log-entry:active { transform: translateY(1px); }
.log-entry-peptide {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
}
.log-entry-dose {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 1px;
  color: var(--gold);
  text-transform: uppercase;
  font-weight: 600;
  align-self: center;
  white-space: nowrap;
}
.log-entry-when {
  grid-column: 1 / -1;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.8px;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-top: 4px;
}
.log-entry-site {
  grid-column: 1 / -1;
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.log-empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--ink-soft);
}
.log-empty-icon {
  font-size: 48px;
  margin-bottom: 14px;
  opacity: 0.6;
}
.log-empty-title {
  font-family: var(--serif);
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--ink);
}
.log-empty-sub { font-size: 14px; line-height: 1.5; }

/* ============ MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
/* Honor the HTML `hidden` attribute — explicit `display: flex` above would
   otherwise override the browser's built-in `[hidden] { display: none }`
   rule. Without this, both modals were always visible from page load, so
   the X close button SET hidden=true but the modal stayed on screen. */
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 42, 59, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.18s ease-out;
}
.modal-sheet {
  position: relative;
  background: var(--bone);
  width: 100%;
  max-width: 600px;
  border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(28px + env(safe-area-inset-bottom));
  max-height: 92vh;
  overflow-y: auto;
  animation: slideUp 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}
@media (min-width: 640px) {
  .modal { align-items: center; padding: 0 18px; }
  .modal-sheet { border-radius: 22px; max-height: 80vh; }
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(11, 42, 59, 0.06);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 16px;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.modal-close:hover { background: rgba(11, 42, 59, 0.12); }
.modal-h {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 500;
  letter-spacing: -0.5px;
  margin-bottom: 18px;
  color: var(--ink);
}
#logEntryForm { display: flex; flex-direction: column; gap: 14px; }

.detail-dl { display: grid; grid-template-columns: 90px 1fr; row-gap: 10px; column-gap: 16px; margin-bottom: 20px; }
.detail-dl dt {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding-top: 2px;
}
.detail-dl dd {
  font-family: var(--serif);
  font-size: 16px;
  color: var(--ink);
}
.detail-actions { display: flex; justify-content: center; }
#deleteEntryBtn {
  color: var(--rose);
  border-color: rgba(201, 120, 98, 0.4);
}
#deleteEntryBtn:hover { color: #fff; background: var(--rose); border-color: var(--rose); }

/* ============ ABOUT ============ */
.about-content { color: var(--ink); }
.about-content p { font-family: var(--serif); font-size: 15.5px; line-height: 1.65; margin-bottom: 18px; }
.about-content h2 {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.3px;
  margin: 26px 0 10px;
  color: var(--ink);
}
.about-content ul { padding-left: 22px; margin-bottom: 18px; }
.about-content li { font-family: var(--serif); font-size: 15px; line-height: 1.6; margin-bottom: 8px; }
.about-content a { color: var(--gold); text-decoration: none; border-bottom: 1px solid rgba(212, 160, 76, 0.4); }
.about-meta {
  margin-top: 32px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: center;
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bone);
  padding: 12px 22px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 10px 32px rgba(11, 42, 59, 0.4);
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============ TAB BAR ============ */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: rgba(238, 232, 219, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(11, 42, 59, 0.08);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px 8px;
  background: transparent;
  border: none;
  color: var(--ink-faint);
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  height: var(--tabbar-h);
  transition: color 0.15s;
}
.tab-btn[aria-selected="true"] { color: var(--ink); }
.tab-btn[aria-selected="true"] svg { stroke: var(--gold); }

/* ============ ANIMATIONS ============ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .modal-backdrop, .modal-sheet, .toast, .btn-primary, .log-entry { animation: none !important; transition: none !important; }
}
