/* True Flow Field App — styles
 * Mobile-first. Brand palette from True Flow brand guidelines.
 * Organized: tokens → reset → layout → sync bar → login → app shell → utilities.
 */

/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --tf-ocean:    #1a9fc4;
  --tf-cerulean: #0b4f6c;
  --tf-navy:     #062840;
  --tf-aqua:     #7dd4ea;
  --tf-sand:     #f5ead8;
  --cta-bg:      #c9a96e;
  --cta-text:    #ffffff;
  --bg-page:     #fffdf9;
  --text-primary: #062840;
  --text-muted:   #6b7280;
  --border:       #e5e7eb;
  --danger:       #dc2626;
  --success:      #16a34a;
  --warning:      #d97706;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100dvh;
  /* Safe area insets for iOS notch / home indicator */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--tf-ocean); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; }

/* ── Sync status bar ────────────────────────────────────────────────────── */
.sync-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--tf-navy);
  color: #fff;
  min-height: 36px;
}

.sync-bar[hidden] { display: none; }

.sync-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
  transition: background 0.3s;
}
.sync-bar.online  .sync-icon { background: var(--success); }
.sync-bar.offline .sync-icon { background: var(--danger); }
.sync-bar.pending .sync-icon { background: var(--warning); animation: pulse 1.2s infinite; }
.sync-bar.failed  .sync-icon { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

#sync-text { flex: 1; }

.sync-btn-manual {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 4px;
  color: #fff;
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
}
.sync-btn-manual[hidden] { display: none; }
.sync-btn-manual:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--cta-bg);
  color: var(--cta-text);
}
.btn-primary:hover { opacity: 0.92; }

.btn-secondary {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-primary);
}

.btn-block { width: 100%; }

.btn-link {
  background: none;
  border: none;
  color: var(--tf-ocean);
  font-size: 0.88rem;
  padding: 0;
  text-decoration: underline;
}

/* ── Login view ─────────────────────────────────────────────────────────── */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem;
  background: var(--tf-navy);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(6,40,64,0.25);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.brand-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--tf-cerulean);
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.login-card label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: -0.5rem;
}

.login-card input[type="email"],
.login-card input[type="password"] {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  color: var(--text-primary);
  background: #fafafa;
  transition: border-color 0.15s;
}
.login-card input:focus {
  outline: none;
  border-color: var(--tf-ocean);
  background: #fff;
}

.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.pw-wrap input { padding-right: 2.75rem; }
.pw-eye {
  position: absolute;
  right: 0.6rem;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: 0.25rem;
}
.eye-icon { display: block; }

.login-error {
  font-size: 0.85rem;
  color: var(--danger);
  min-height: 1.2em;
}

.forgot-wrap { text-align: center; }

.forgot-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.forgot-panel[hidden] { display: none; }

.forgot-msg {
  font-size: 0.85rem;
  color: var(--success);
}
.forgot-msg[hidden] { display: none; }

.config-warning {
  font-size: 0.8rem;
  color: var(--warning);
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
}
.config-warning[hidden] { display: none; }

/* ── App shell (authenticated views) ────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 36px); /* minus sync bar */
}
#app[hidden] { display: none; }

.app-header {
  background: var(--tf-cerulean);
  color: #fff;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: 1;
}

.app-header .header-actions {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  background: rgba(255,255,255,0.12);
  border: none;
  border-radius: 8px;
  color: #fff;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen {
  flex: 1;
  padding: 1.25rem;
}
.screen[hidden] { display: none; }

/* ── Loading / spinner ───────────────────────────────────────────────────── */
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100dvh - 36px);
  flex-direction: column;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--tf-ocean);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Settings screen (sign out) ─────────────────────────────────────────── */
.settings-section {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 1rem;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.settings-row:last-child { border-bottom: none; }

.settings-label { font-weight: 500; }
.settings-value { color: var(--text-muted); font-size: 0.85rem; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 0.875rem; }
.mt-1        { margin-top: 0.5rem; }
.mt-2        { margin-top: 1rem; }
