/* ==========================================================================
   H — DESIGN SYSTEM v2
   Tipografia: Space Grotesk (headings) + Montserrat (corpo)
   Referência: Instagram + Facebook — Visual fluido, clean, premium
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&family=Space+Grotesk:wght@400;500;600;700;800&display=swap');

/* --------------------------------------------------------------------------
   RESET
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* --------------------------------------------------------------------------
   DESIGN TOKENS — LIGHT MODE (default)
   -------------------------------------------------------------------------- */
:root {
  --font-body: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-ui: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Cores — Light */
  --bg:          #FAFAFA;
  --surface:     #FFFFFF;
  --surface-2:   #F5F5F5;
  --border:      #EFEFEF;
  --border-mid:  #DBDBDB;

  --text-1:      #050505;
  --text-2:      #606060;
  --text-3:      #A8A8A8;

  --accent:      #0095F6;      /* azul IG */
  --accent-red:  #ED4956;      /* curtir/erro */
  --accent-green:#00C170;      /* sucesso */

  --btn-bg:      #050505;
  --btn-text:    #FFFFFF;

  /* Espaçamentos (8pt grid) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 64px;

  /* Bordas */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;
  --r-pill: 9999px;

  /* Sombras */
  --shadow-1: 0 1px 3px rgba(0,0,0,0.07);
  --shadow-2: 0 4px 16px rgba(0,0,0,0.10);

  /* Layout */
  --nav-h: 56px;
  --header-h: 54px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --max-w: 600px;
}

/* --------------------------------------------------------------------------
   DARK MODE — ativado automaticamente pelo sistema
   -------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #000000;
    --surface:     #121212;
    --surface-2:   #1C1C1C;
    --border:      #262626;
    --border-mid:  #363636;

    --text-1:      #F5F5F5;
    --text-2:      #A8A8A8;
    --text-3:      #585858;

    --btn-bg:      #FFFFFF;
    --btn-text:    #000000;

    --shadow-1: 0 1px 0 rgba(255,255,255,0.04);
    --shadow-2: 0 4px 24px rgba(0,0,0,0.6);
  }
}

/* --------------------------------------------------------------------------
   BASE
   -------------------------------------------------------------------------- */
html {
  height: 100%;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* --------------------------------------------------------------------------
   APP SHELL
   -------------------------------------------------------------------------- */
#root {
  display: flex;
  flex-direction: column;
  min-height: 100svh;  /* svh = small viewport height (more reliable on mobile) */
  max-width: var(--max-w);
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

#app {
  flex: 1;
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* --------------------------------------------------------------------------
   BOTTOM NAVIGATION — IG/TikTok style
   -------------------------------------------------------------------------- */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-w);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 200;
}

.nav-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-decoration: none;
  color: var(--text-2);
  transition: color 0.15s ease, transform 0.1s ease;
}

.nav-item.active { color: var(--text-1); }

.nav-item:active { transform: scale(0.88); }

.nav-create {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-decoration: none;
}

.nav-create-circle {
  width: 40px;
  height: 40px;
  border-radius: var(--r-sm);
  background: var(--btn-bg);
  color: var(--btn-text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.nav-create:active .nav-create-circle {
  transform: scale(0.88);
  opacity: 0.8;
}

/* --------------------------------------------------------------------------
   GLASS HEADER (sticky top)
   -------------------------------------------------------------------------- */
.glass-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  padding-top: var(--safe-t);
  display: flex;
  align-items: center;
  padding-left: var(--s4);
  padding-right: var(--s4);
  gap: var(--s3);
  background: rgba(var(--surface-rgb, 255,255,255), 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

@media (prefers-color-scheme: dark) {
  .glass-header { background: rgba(18,18,18,0.85); }
}

.header-logo {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -1.5px;
  color: var(--text-1);
  flex: 1;
}

.header-title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 16px;
  color: var(--text-1);
  flex: 1;
  text-align: center;
}

.header-back {
  color: var(--text-1);
  text-decoration: none;
  display: flex;
  align-items: center;
  padding: var(--s2);
  margin-left: -var(--s2);
}

/* --------------------------------------------------------------------------
   FORMS — Inputs and Buttons
   -------------------------------------------------------------------------- */
.input-field {
  width: 100%;
  background: var(--surface-2);
  border: 1.5px solid var(--border-mid);
  color: var(--text-1);
  border-radius: var(--r-md);
  padding: 14px var(--s4);
  font-size: 15px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
  -webkit-appearance: none;
}

.input-field:focus {
  border-color: var(--text-1);
  background: var(--surface);
}

.input-field::placeholder { color: var(--text-3); }

button { font-family: var(--font-body); border: none; background: none; cursor: pointer; }

.btn-primary {
  width: 100%;
  background: var(--btn-bg);
  color: var(--btn-text);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15px;
  padding: 14px var(--s5);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  transition: opacity 0.2s ease, transform 0.1s ease;
}

.btn-primary:active { transform: scale(0.98); opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  width: 100%;
  background: transparent;
  color: var(--text-1);
  border: 1.5px solid var(--border-mid);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 15px;
  padding: 13px var(--s5);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  transition: background 0.15s ease;
}

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

/* --------------------------------------------------------------------------
   AUTHENTICATION PAGES
   -------------------------------------------------------------------------- */
.auth-page {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s6) var(--s4);
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s6) var(--s5);
  box-shadow: var(--shadow-2);
}

.auth-wordmark {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 48px;
  letter-spacing: -3px;
  color: var(--text-1);
  text-align: center;
  margin-bottom: var(--s2);
  display: block;
}

.auth-tagline {
  color: var(--text-2);
  font-size: 14px;
  text-align: center;
  margin-bottom: var(--s7);
}

.input-group { margin-bottom: var(--s3); }

.input-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: var(--s1);
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin: var(--s5) 0;
}

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

.auth-divider span {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-3);
  font-family: var(--font-ui);
  letter-spacing: 0.05em;
}

.auth-footer-text {
  text-align: center;
  margin-top: var(--s5);
  font-size: 14px;
  color: var(--text-2);
}

.auth-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  font-family: var(--font-ui);
}

.error-msg {
  background: rgba(237,73,86,0.10);
  color: var(--accent-red);
  border: 1px solid rgba(237,73,86,0.20);
  border-radius: var(--r-sm);
  padding: var(--s3) var(--s4);
  font-size: 13px;
  text-align: center;
  font-weight: 500;
  margin-top: var(--s3);
}

/* --------------------------------------------------------------------------
   FEED & POST CARDS — Instagram style
   -------------------------------------------------------------------------- */
.feed-wrap { background: var(--bg); }

.post-card {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0;
}

/* No desktop: cards flutuam com borda */
@media (min-width: 601px) {
  .feed-wrap { padding: var(--s4) 0; }
  .post-card {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: var(--s3);
    overflow: hidden;
  }
}

.post-header {
  display: flex;
  align-items: center;
  padding: var(--s3) var(--s4);
  gap: var(--s3);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--border-mid);
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-fallback {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #666, #333);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.post-meta { flex: 1; min-width: 0; }

.post-username {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-1);
  text-decoration: none;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-time {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 1px;
}

.post-menu-btn {
  color: var(--text-2);
  padding: var(--s2);
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.post-menu-btn:hover { color: var(--text-1); }

.post-media {
  width: 100%;
  display: block;
  background: var(--surface-2);
  max-height: 700px;
  object-fit: contain;
}

.post-actions {
  display: flex;
  align-items: center;
  padding: var(--s3) var(--s4);
  gap: var(--s4);
}

.action-icon-btn {
  background: none;
  border: none;
  color: var(--text-1);
  padding: 4px;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.action-icon-btn:active { transform: scale(0.85); }

.post-likes-count {
  padding: 0 var(--s4) var(--s2);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-1);
}

.post-text {
  padding: 0 var(--s4) var(--s3);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-1);
}

.post-text-user {
  font-family: var(--font-ui);
  font-weight: 700;
  margin-right: 4px;
}

.comments-link {
  display: block;
  padding: 0 var(--s4) var(--s4);
  color: var(--text-3);
  font-size: 14px;
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   LOADING & PLACEHOLDERS
   -------------------------------------------------------------------------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--text-1);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.page-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: var(--s7) var(--s5);
  text-align: center;
  gap: var(--s3);
}

.placeholder-icon { font-size: 48px; }

.page-placeholder h2 {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 20px;
}

.page-placeholder p {
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.5;
}

.feed-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s8) var(--s5);
  text-align: center;
  gap: var(--s3);
}

.feed-empty h2 {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 22px;
}

.feed-empty p { color: var(--text-2); }

/* --------------------------------------------------------------------------
   PROFILE PAGE
   -------------------------------------------------------------------------- */
.profile-header-block {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s5) var(--s4);
}

.profile-avatar-large {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
}

.profile-avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #666, #333);
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 28px;
  color: #fff;
  flex-shrink: 0;
}

.profile-display-name {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 18px;
  margin-bottom: var(--s1);
}

.profile-email {
  color: var(--text-2);
  font-size: 14px;
}

/* --------------------------------------------------------------------------
   HELPERS
   -------------------------------------------------------------------------- */
.hidden { display: none !important; }
a { color: inherit; }

/* --------------------------------------------------------------------------
   POST TYPE SELECTOR (Create page)
   -------------------------------------------------------------------------- */
.post-type-btn {
  background: var(--surface-2);
  border: 1.5px solid var(--border-mid);
  border-radius: var(--r-pill);
  padding: 8px 16px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.post-type-btn.active {
  background: var(--btn-bg);
  color: var(--btn-text);
  border-color: var(--btn-bg);
}

.post-type-btn:hover:not(.active) {
  border-color: var(--text-2);
  color: var(--text-1);
}

/* --------------------------------------------------------------------------
   TOAST NOTIFICATIONS
   -------------------------------------------------------------------------- */
#toast > div {
  animation: toastIn 0.3s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   LIKE ANIMATION
   -------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------
   POST CARDS (feed, post detail)
   -------------------------------------------------------------------------- */
.post-card {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--s4);
  overflow: visible;
  position: relative;
}

.post-header {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s3);
  position: relative; /* CRITICAL: anchor for context menu */
}

.post-text {
  padding: 0 var(--s1);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: var(--s3);
}

.post-text-user {
  font-weight: 700;
  margin-right: 4px;
}

.post-actions {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s2) 0 0 0;
}

.post-media {
  width: 100%;
  border-radius: var(--r-xs);
  margin-bottom: var(--s3);
}

/* --------------------------------------------------------------------------
   ACTION BUTTON (like, comment, share, menu, eye)
   -------------------------------------------------------------------------- */
.action-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--text-2);
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, color 0.15s ease;
  position: relative;
  z-index: 2;
}

.action-icon-btn:hover {
  color: var(--text-1);
}

.action-icon-btn:active {
  transform: scale(0.9);
}

/* Make the 3-dot menu button stand above sibling elements */
.feed-menu-btn,
.post-menu-btn {
  z-index: 5;
  padding: 8px;
  margin: -4px;
  border-radius: 50%;
}

.feed-menu-btn:hover,
.post-menu-btn:hover {
  background: var(--surface-2);
}

.feed-like-btn[data-liked="true"] svg {
  animation: heartPop 0.3s ease;
}

@keyframes heartPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   SHARE BUTTON
   -------------------------------------------------------------------------- */
.feed-share-btn:active {
  transform: scale(0.85);
}

/* --------------------------------------------------------------------------
   ACTION COUNTERS (feed buttons)
   -------------------------------------------------------------------------- */
.action-count {
  font-size: 13px;
  font-family: var(--font-ui);
  font-weight: 600;
  margin-left: 4px;
  color: var(--text-2);
}

/* --------------------------------------------------------------------------
   PROFILE TABS (Instagram style)
   -------------------------------------------------------------------------- */
.profile-tabs {
  display: flex;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.profile-tab {
  flex: 1;
  padding: 12px 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-3);
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.profile-tab.active {
  color: var(--text-1);
  border-bottom-color: var(--text-1);
}

.profile-tab:hover:not(.active) {
  color: var(--text-2);
}

/* --------------------------------------------------------------------------
   PROFILE PHOTO GRID
   -------------------------------------------------------------------------- */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.profile-grid-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  display: block;
}

.profile-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.2s ease;
}

.profile-grid-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-family: var(--font-ui);
  font-weight: 700;
  color: #fff;
  opacity: 0;
  transition: opacity 0.2s ease;
  gap: 12px;
}

.profile-grid-item:hover .profile-grid-overlay {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   CONTEXT MENU (3 dots)
   -------------------------------------------------------------------------- */
.post-context-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  min-width: 180px;
  z-index: 9999;
  overflow: hidden;
  animation: menuFadeIn 0.15s ease;
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ctx-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  font-size: 14px;
  font-family: var(--font-ui);
  font-weight: 500;
  color: var(--text-1);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.ctx-item:last-child {
  border-bottom: none;
}

.ctx-item:hover {
  background: var(--surface-2);
}

.ctx-item.ctx-delete {
  color: var(--accent-red);
}
