/* mySocial — shell, design tokens and the shared component kit.
 *
 * Everything in here is fair game for every view. ready.css / admin.css /
 * stats.css should style *their* specifics and lean on these tokens and
 * classes for anything generic, so the four tabs still look like one app.
 *
 * Rules that are not negotiable on this target (iPhone standalone PWA):
 *   - min 44px tap targets
 *   - safe-area insets on every screen edge
 *   - animate transform/opacity only; never width/height/top/left
 *   - no hover-only affordance: hover does not exist on the device
 */

:root {
  color-scheme: dark;

  /* Surfaces, darkest to lightest. */
  --bg: #0c0c0f;
  --surface: #16161b;
  --surface-2: #1e1e25;
  --surface-3: #282831;
  --line: #2f2f3a;
  --line-strong: #43434f;

  /* Ink. --text-dim still clears 4.5:1 on --surface; do not darken it. */
  --text: #f4f4f6;
  --text-mid: #b9b9c4;
  --text-dim: #8b8b98;

  --accent: #7c9cff;
  --accent-ink: #0b1024;
  --like: #4ade80;
  --like-dim: #143323;
  --reject: #ff6b6b;
  --reject-dim: #3a1717;
  --warn: #ffb84d;
  --edit: #b58bff;

  --radius: 14px;
  --radius-lg: 22px;

  /* Safe areas, resolved once so the rest of the sheet can just use them. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --tabbar-h: 56px;

  /* Live viewport height in px, written by ui.js from window.visualViewport.
   * 100vh is wrong on iOS in two directions at once (it ignores the keyboard
   * and it includes the collapsed URL bar), so nothing here uses it. */
  --vvh: 100dvh;
  --kb-inset: 0px;

  --ease-out: cubic-bezier(0.22, 0.9, 0.3, 1);
}

* { box-sizing: border-box; }

/* [hidden] is a UA-origin rule, so any author rule that sets `display` beats
 * it even at lower specificity. One !important here means `el.hidden = true`
 * is reliable everywhere instead of being re-debugged per component. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  /* Rubber-band scrolling of the *document* is what makes a PWA feel like a
   * web page. The views scroll internally instead. */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  font-family: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation; /* kills the 300ms double-tap-zoom delay */
}

h1, h2, h3, p { margin: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Pairing gate ------------------------------------------------------- */

#gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background: var(--bg);
  z-index: 100;
}

.gate-box {
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.gate-box h1 { font-size: 1.4rem; margin-bottom: 6px; letter-spacing: -0.01em; }
.gate-box p { color: var(--text-dim); margin-bottom: 20px; font-size: 0.95rem; }
.gate-box form { display: flex; flex-direction: column; gap: 12px; }

.gate-box input {
  min-height: 52px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  text-align: center;
  font-size: 1.3rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.gate-icon {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  margin: 0 auto 18px;
  display: block;
}

.error-text { color: var(--reject); font-size: 0.9rem; margin-top: 10px; }

/* ---- App shell ---------------------------------------------------------- */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#views {
  flex: 1;
  position: relative;
  min-height: 0;
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* The scrollable body of a view. Other agents: wrap your list in this. */
.view-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 16px calc(20px + var(--safe-bottom));
}

.view-head {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  flex: none;
}

.view-title {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.view-head-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 4px;
}

.pill-count {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ---- Tab bar ------------------------------------------------------------ */

#tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.tab {
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-dim);
  position: relative;
  transition: color 0.15s ease;
}
.tab-icon { font-size: 1.25rem; line-height: 1; filter: saturate(0.2) brightness(1.4); }
.tab-label { font-size: 0.68rem; letter-spacing: 0.01em; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .tab-icon { filter: none; }
.tab:active { transform: scale(0.94); }

.tab-badge {
  position: absolute;
  top: 4px;
  left: 55%;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---- Connection banner -------------------------------------------------- */

#conn-banner {
  position: absolute;
  top: calc(var(--safe-top) + 4px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-mid);
  font-size: 0.8rem;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.5);
}
#conn-banner.online { color: var(--like); }
#conn-banner .conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

/* ---- Buttons ------------------------------------------------------------ */

.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s var(--ease-out), opacity 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-like { background: var(--like); color: #04160c; }
.btn-danger { background: var(--reject-dim); color: var(--reject); }
.btn-ghost { background: transparent; border: 1px solid var(--line-strong); color: var(--text-mid); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.85rem; border-radius: 10px; }

/* ---- Chips -------------------------------------------------------------- */

.chip-row {
  flex: none;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 10px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-mid);
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip[aria-selected="true"] {
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 22%, var(--surface-2));
  border-color: var(--chip-color, var(--accent));
  color: var(--text);
}

.badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-mid);
}
.badge-linkedin { background: #0a2f4d; color: #7cc4ff; }
.badge-x { background: #23232a; color: #e8e8ee; }

/* ---- Forms -------------------------------------------------------------- */

input[type="text"], input[type="number"], input[type="url"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  /* 16px minimum, or iOS Safari zooms the whole page on focus. */
  font-size: 16px;
}
textarea { resize: none; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; }

.section-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 20px 0 8px;
}
.section-hint { font-size: 0.82rem; color: var(--text-dim); margin-bottom: 10px; }

/* ---- Empty / loading states --------------------------------------------- */

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}
.empty-emoji { font-size: 2.6rem; }
.empty-state h2 { font-size: 1.25rem; font-weight: 700; }
.empty-state p { color: var(--text-dim); max-width: 34ch; }

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toasts ------------------------------------------------------------- */

#toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--kb-inset) + 12px);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}

.toast {
  max-width: 100%;
  pointer-events: auto;
  background: var(--surface-3);
  color: var(--text);
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.55);
  border-left: 3px solid var(--line-strong);
  animation: toast-in 0.22s var(--ease-out);
}
.toast.out { animation: toast-out 0.18s ease forwards; }
.toast-ok { border-left-color: var(--like); }
.toast-error { border-left-color: var(--reject); }
.toast-warn { border-left-color: var(--warn); }
.toast-info { border-left-color: var(--accent); }

@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ---- Scrim + sheets ----------------------------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 60;
  animation: fade-in 0.2s ease;
}
@keyframes fade-in { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  /* Sits on top of the keyboard, not under it — see syncViewport() in ui.js. */
  bottom: var(--kb-inset);
  z-index: 70;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -12px 44px rgb(0 0 0 / 0.6);
  display: flex;
  flex-direction: column;
  max-height: var(--vvh);
  animation: sheet-in 0.26s var(--ease-out);
}
@keyframes sheet-in { from { transform: translateY(100%); } }

/* Full-height variant (the editor). Bound to --vvh, not 100%, so the iOS
 * keyboard shrinks the sheet instead of pushing its top off the screen. */
.sheet-full {
  top: auto;
  /* The 12px alone was not enough clearance: on a notched iPhone (13 and up)
   * --vvh includes the status bar, so a sheet this tall put its own header —
   * Close and Save — underneath the clock, where they cannot be tapped.
   * Subtracting --safe-top anchors the sheet's top edge just below the status
   * bar instead, which is also where iOS puts its own sheets. */
  height: calc(var(--vvh) - 12px - var(--safe-top));
}

/* Belt and braces for any sheet that still reaches the top of the screen (a
 * future variant, or a browser where dvh and the inset disagree). Harmless at
 * 0px, which is what every non-notched device reports. */
.sheet-full > .sheet-head {
  padding-top: max(8px, calc(var(--safe-top) / 3));
}

.sheet-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  min-height: 52px;
}
.sheet-head-title {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-head-btn {
  min-height: 44px;
  min-width: 64px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--text-mid);
  font-size: 0.95rem;
}
.sheet-head-btn.primary { color: var(--accent); font-weight: 700; }
.sheet-head-btn[disabled] { opacity: 0.35; pointer-events: none; }

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* No --kb-inset here: the sheet itself already sits above the keyboard, so
     adding it again would leave a keyboard-sized hole at the bottom. */
  padding: 4px 16px calc(24px + var(--safe-bottom));
}

/* Confirm sheet, from ui.confirmSheet(). */
.confirm-sheet { padding: 20px 16px calc(20px + var(--safe-bottom)); gap: 10px; }
.confirm-sheet h2 { font-size: 1.15rem; font-weight: 700; }
.confirm-sheet p { color: var(--text-mid); font-size: 0.95rem; margin-bottom: 6px; }
.confirm-actions { display: flex; flex-direction: column; gap: 8px; }
.confirm-actions .btn { min-height: 50px; }

/* ---- Small shared bits -------------------------------------------------- */

.surface-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--text-dim); }
.tnum { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
