/* backend>static>chat>css>chat.css */
:root{
  /* DARK default */
  --bg: #07070a;
  --text: rgba(255,255,255,.94);
  --muted: rgba(255,255,255,.70);

  --card: rgba(255,255,255,.06);
  --border: rgba(255,255,255,.14);

  --primary: #2563eb;
  --danger: #b91c1c;

  --r: 14px;
  --shadow: 0 18px 40px rgba(0,0,0,.55);

  --gap: 0.5cm;
  --pad: 0.25cm;

  /* safe-area (iOS notch) */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

/* LIGHT override solo quando html.light */
html.light{
  --bg: #f3f4f6;
  --text: #111827;
  --muted: #6b7280;

  --card: #ffffff;
  --border: #e5e7eb;

  --shadow: 0 1px 0 rgba(0,0,0,.02);
}


body.chat{
  background: var(--bg);
  color: var(--text);
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  height: 100dvh;
  overflow: hidden; /* desktop: scroll solo nel feed */
}

.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

/* =========================
   LAYOUT DESKTOP
   ========================= */
.chat-layout{
  display: grid;
  grid-template-columns: 5cm 9cm 11cm;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header header"
    "left   center  right";
  gap: var(--gap);
  max-width: calc(5cm + 9cm + 11cm + var(--gap));
  margin: 0 auto;
  padding: var(--pad);
  height: 100dvh;
  box-sizing: border-box;
}

/* =========================
   HEADER
   ========================= */
.site-header{
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
}

.brand-left{ display:flex; align-items:center; gap:10px; }
.brand-logo{ width:90px; height:33px; border-radius: 0px; }
.brand-name{ font-weight:800; letter-spacing:.02em; font-size:1.05rem; }

.header-center{ display:flex; align-items:center; justify-content:center; }
.date-chip{
  padding: 6px 10px;
  border-radius: 999px;
  background: transparent;
  color: #374151;
  font-weight: 600;
}

.account{ display:flex; align-items:center; gap:10px; }

.pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:18px;
  height:18px;
  padding:0 6px;
  background:#ef4444;
  color:#fff;
  font-weight:700;
  font-size:12px;
  border-radius:999px;
}

#accNotify{ text-decoration:none; }

.acc-avatar{
  width:40px;
  height:40px;
  border-radius:50%;
  object-fit:cover;
  border:1px solid var(--border);
  background:#fff;
  cursor: default;
}

.acc-flag{ width:18px; height:18px; }

/* =========================
   LEFT SIDEBAR
   ========================= */
.col-left{
  grid-area: left;
  display:flex;
  flex-direction:column;
  height: 100%;
  overflow: hidden;
}

.side-nav{
  display:flex;
  flex-direction:column;
  gap: 12px;
  padding: 12px;
  width: 100%;
  box-sizing: border-box;
}

.nav-btn{
  display:block;
  text-decoration:none;
  border-radius: 10px;
  background: #fff;
  color: #000;
  font-weight: 700;
  font-size: 1rem; 
  border: 1px solid transparent;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-btn:hover{ background:#d0cfcf; }

.side-nav .spacer{ flex: 1 1 auto; }

.btn-support{
  background: var(--primary);
  color:#fff;
}
.btn-support:hover{ filter: brightness(.95); }

.legal-links{
  font-size: 12px;
  color: var(--muted);
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.legal-link{
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.legal-link:hover{ opacity: .85; }

/* =========================
   RIGHT COLUMN
   ========================= */
.col-right{
  grid-area: right;
  display:flex;
  flex-direction:column;
  height: 100%;
  overflow:hidden;
}

.media-wrap{ display:flex; flex-direction:column; height:100%; }
.media-title{ margin: 14px 14px 8px; font-size:1.05rem; font-weight:700; }

#dogsOfDay{
  padding: 8px 12px 14px;
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

#dogsOfDay .dogc{
  position:relative;
  border-radius: 10px;
  overflow:hidden;
  border: 1px solid var(--border);
  background: #fafafa;
  aspect-ratio: 1/1;
}

#dogsOfDay .thumb{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
}

.vbadge{ display:none; } /* niente badge play */

#dogsOfDay .dogc .trash{
  position:absolute;
  top:6px;
  right:6px;
  border:0;
  background:#fff;
  border-radius:10px;
  padding:2px 6px;
  box-shadow:0 1px 4px rgba(0,0,0,.2);
  cursor:pointer;
  opacity:.9;
}
#dogsOfDay .dogc .trash:hover{ opacity:1; }

/* Admin bans */
.admin-bans{
  margin-top: 14px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.admin-bans .admin-title{ margin: 6px 0 2px; font-size: 14px; font-weight: 700; }
.admin-bans .admin-sub{ font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.admin-bans .empty{ font-size: 12px; color: #64748b; padding: 8px 4px; font-style: italic; }
.admin-bans table{ width:100%; border-collapse: collapse; font-size: 12px; }
.admin-bans th, .admin-bans td{ padding: 6px 4px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.admin-bans th{ text-align:left; color:#475569; font-weight: 700; }
.admin-bans td.right{ text-align:right; }
.admin-bans .muted{ color:#94a3b8; font-size: 11px; }

.btn-small{
  border: 0;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
  background: #f8fafc;
}
.btn-small:hover{ filter: brightness(.97); }
.btn-small.danger{ background: #fee2e2; }
.btn-small.danger:hover{ background: #fecaca; filter:none; }

/* =========================
   CENTER (COMPOSER + FEED)
   ========================= */
.col-center{
  grid-area: center;
  display:flex;
  flex-direction:column;
  height: 100%;
  overflow:hidden;
  gap: 10px; /* aria tra le card (niente patch in fondo) */
}

/* Composer */
.chat-compose{
  flex: 0 0 auto;
  padding: 12px 14px;
}

.chat-compose textarea{
  width:100%;
  border:0;
  outline:none;
  background: transparent;
  color: var(--text);
  padding: 10px 0;
  min-height: 84px;
  resize: vertical;
  border-bottom: 1px solid var(--border);
}

.chat-compose .row{
  display:flex;
  gap:10px;
  align-items:center;
  margin-top:10px;
  flex-wrap:wrap;
}

.tbtn{
  padding: 6px 10px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  cursor:pointer;
}

.btn-primary{
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color:#fff;
  font-weight: 800;
  cursor:pointer;
}
.btn-primary:hover{ filter: brightness(.95); }

/* Preview allegato */
#imgPreviewWrap{ margin-top: 8px; display:none; }
#msgPreview, #vidPreview{
  display:none;
  width:114px;
  height:114px;
  object-fit:cover;
  border-radius:10px;
  border:1px solid var(--border);
}

/* Feed (unica area scroll desktop) */
.chat-feed{
  flex: 1 1 auto;
  min-height: 0;
  display:flex;
  flex-direction:column;
}

.feed-list{
  flex: 1 1 auto;
  min-height: 0;
  list-style:none;
  margin:0;
  padding:12px;
  display:flex;
  flex-direction:column;
  gap: 12px;
  overflow:auto;
  scrollbar-width: none;
}
.feed-list::-webkit-scrollbar{ display:none; }

.hint{ color: var(--muted); margin: 0; padding: 0 12px 12px; }

/* Messaggi */
.msg{
  display:grid;
  grid-template-columns: 40px 1fr;
  gap:10px;
  padding: 8px;
  border: 1px solid #f3f4f6;
  border-radius: 10px;
  background: #fff;
}

.msg .avatar{
  width:40px;
  height:40px;
  border-radius:50%;
  object-fit:cover;
  border:1px solid var(--border);
}

.msg .meta{
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap: 6px;
  font-weight: 800;
  margin-bottom: 2px;
}

.msg .meta .name{ font-weight: 700; }
.msg .meta img.flag{ width:16px; height:16px; }

.msg .text{ line-height: 1.35; }

/* Media dentro messaggio */
.msg .img .thumb,
.msg .vid .thumb{
  width:114px;
  height:114px;
  object-fit:cover;
  border-radius:10px;
  border:1px solid var(--border);
  display:block;
}
.msg .vid .thumb{ background:#000; }

/* Azioni */
.actions-row{
  display:flex;
  align-items:center;
  gap: 14px;
  margin-top: 8px;
}
.actions-row .act{
  border:0;
  background:transparent;
  cursor:pointer;
  font-weight: 800;
  color: var(--primary);
  display:inline-flex;
  gap:6px;
  align-items:center;
}
.actions-row .btn-heart .ico{ color:#ef4444; }
.actions-row .btn-del{ color: var(--danger); }

/* =========================
   MOBILE BAR (default hidden on desktop)
   ========================= */
#mobileBar,
#mobileDate{
  display:none;
}

/* =========================
   MOBILE ≤ 800px
   ========================= */
@media (max-width: 800px){
  body.chat{
    height: auto;
    min-height: 100dvh;
    overflow: auto; /* scroll di pagina */
  }

  .col-center{
    height:auto;
    overflow: visible;
  }

  .chat-feed{
    height:auto;
    overflow: visible;
  }

  /* IMPORTANTISSIMO: la lista non deve essere un box scrollabile su mobile */
  .feed-list{
    overflow: visible;
    max-height: none;
  }

  .chat-layout{
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "header"
      "mobilebar"
      "mobiledate"
      "center";
    max-width: 100vw;
    padding:
      calc(10px + var(--sat))
      calc(10px + var(--sar))
      calc(10px + var(--sab))
      calc(10px + var(--sal));
    gap: 10px;
    height: auto;
  }

  .col-left{ display:none; }
  .col-right{ display:none; } /* come avevi scelto nelle patch finali */

  /* Toolbar mobile: FIX “mangiata” sopra/sotto
     - touch target vero (padding)
     - line-height stabile
     - safe-area bottom considerata
  */
  @media (max-width: 800px){

  /* toolbar centrata quando ci sta, scrollabile quando non ci sta */
  #mobileBar{
    display:flex;
    align-items:center;
    justify-content:center;   /* <-- centra */
    gap: 10px;
    overflow-x:auto;
    -webkit-overflow-scrolling: touch;

    /* padding anche safe-area, evita “tagli” ai bordi */
    padding: 6px calc(8px + var(--sar)) 6px calc(8px + var(--sal));

    scrollbar-width:none;
  }
  #mobileBar::-webkit-scrollbar{ display:none; }

   /* ogni bottone: touch target pulito */
  #mobileBar .mbtn{
    flex: 0 0 auto;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    padding: 10px 12px;
    font-size: 22px;
    line-height: 1.2;
    border-radius: 12px;
  }
}

  #mobileBar .mbtn:active{
    transform: scale(0.98);
  }

  #mobileDate{
    display:flex;
    justify-content:center;
    align-items:center;
    padding: 0;
  }

  #feedDate{
    font-weight: 700;
    color: #374151;
  }

  /* Centro */
  .col-center{ gap: 10px; }
}

/* =========================
   DARK MODE (html.dark)
   ========================= */
html.dark body.chat{
  --bg: #07070a;
  --text: rgba(255,255,255,.94);
  --muted: rgba(255,255,255,.70);

  --card: rgba(255,255,255,.06);
  --border: rgba(255,255,255,.14);

  --shadow: 0 18px 40px rgba(0,0,0,.55);
}

html.dark body.chat .date-chip{ color: rgba(255,255,255,.82); }

html.dark body.chat .acc-avatar,
html.dark body.chat .msg .avatar{
  border-color: var(--border);
  background: rgba(0,0,0,.35);
}

html.dark body.chat .nav-btn{
  background: transparent;
  color: rgba(255,255,255,.92);
  border: 1px solid var(--border);
}
html.dark body.chat .nav-btn:hover{
  background: rgba(255,255,255,.06);
}
html.dark body.chat .btn-support{
  background: var(--primary);
  color:#fff;
  border-color: var(--primary);
}

html.dark body.chat .chat-compose textarea{
  color: rgba(255,255,255,.92);
  border-bottom-color: var(--border);
}
html.dark body.chat .chat-compose textarea::placeholder{
  color: rgba(255,255,255,.55);
}

html.dark body.chat .tbtn{
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.18);
  color: rgba(255,255,255,.92);
}

html.dark body.chat .msg{
  background: rgba(255,255,255,.05);
  border-color: rgba(255,255,255,.10);
}
html.dark body.chat .msg .text{
  color: rgba(255,255,255,.92);
}

html.dark body.chat .actions-row .act{
  color: rgba(255,255,255,.82);
}
html.dark body.chat .actions-row .btn-del{
  color: rgba(251,113,133,.95);
}

@media (max-width:800px){
  html.dark body.chat #feedDate{
    color: rgba(255,255,255,.78);
  }
}

/* MOBILE: nel header non vogliamo la data (resta solo #mobileDate sotto) */
@media (max-width: 800px){
  body.chat .site-header .header-center{
    display: none;
  }
}

/* ===============================
   MOBILE FIX: stop "shake" + composer sticky
   =============================== */
@media (max-width: 800px){

  /* blocca lo scroll orizzontale (shake) */
  html, body{
    overflow-x: hidden;
  }
  body.chat{
    overflow-x: hidden;
  }

  /* evita overflow da 100vw + padding */
  .chat-layout{
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
  }

  /* se qualche elemento spinge oltre (emoji bar ecc.) */
  #mobileBar{
    max-width: 100%;
    box-sizing: border-box;
  }

  /* --- FEED che scorre sotto al composer --- */
  .col-center{
    overflow: visible; /* pagina scorre */
  }

  /* il composer resta visibile mentre scorri i messaggi */
  .chat-compose{
    position: sticky;
    top: 0;
    z-index: 60;
    background: var(--card);
  }

  /* un filo di separazione quando passa il feed sotto */
  .chat-compose{
    box-shadow: 0 8px 18px rgba(0,0,0,.08);
  }
  html.dark body.chat .chat-compose{
    box-shadow: 0 18px 40px rgba(0,0,0,.45);
  }
}
@media (max-width: 800px){
  #mobileBar{
    justify-content: center;
    padding-left: calc(8px + var(--sal));
    padding-right: calc(8px + var(--sar));
  }
}
/* ===============================
   TOOLTIP (data-tooltip) - Light/Dark
   =============================== */
[data-tooltip]{
  position: relative;
}

/* Flag tooltip wrapper: rende stabile l'hover e l'allineamento */
.flag-tip[data-tooltip]{
  display: inline-flex;
  align-items: center;
}


/* tooltip solo su dispositivi hover (desktop) */
@media (hover: hover){
  [data-tooltip]::after{
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px); /* un po' più basso */
    transform: translateX(-50%);
    white-space: nowrap;

    font-size: 12px;
    font-weight: 700;
    padding: 7px 10px;
    border-radius: 10px;

    /* LIGHT: bianco + testo nero */
    background: #fff;
    color: #111827;
    border: 1px solid rgba(17,24,39,.18);
    box-shadow: 0 10px 24px rgba(0,0,0,.12);

    opacity: 0;
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease;
    z-index: 300;
  }

  [data-tooltip]:hover::after,
  [data-tooltip]:focus-visible::after{
    opacity: 1;
    transform: translateX(-50%) translateY(-2px);
  }
}

/* DARK: nero + testo bianco */
html.dark [data-tooltip]::after{
  background: rgba(17,24,39,.94);
  color: rgba(255,255,255,.92);
  border-color: rgba(255,255,255,.16);
  box-shadow: 0 18px 40px rgba(0,0,0,.55);
}

/* Fix tooltip pallino rosso: area hover cliccabile e stabile */
#accNotify{
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* PC: legal-links più su e centrati nella sidebar */
@media (min-width: 801px){
  body.chat .side-nav{
    width: 100%;
    box-sizing: border-box;
    height: 100%;              /* importante per gestire bene lo spazio */
    padding-bottom: 10px;      /* aria in fondo */
  }

  body.chat .legal-links{
    margin-top: 10px;          /* li stacca dai bottoni */
    display: flex;
    justify-content: center;   /* centra orizzontalmente */
    text-align: center;
  }
}
@media (max-width: 800px){
  #mobileBar .mbtn{
    text-decoration: none;
  }
  #mobileBar .mbtn:visited{
    text-decoration: none;
  }
}

/* ===============================
   FLAG tooltip: sotto (come dogs)
   =============================== */
.flag-tip[data-tooltip]{
  display: inline-flex;
  align-items: center;
  position: relative; /* sicurezza */
}

@media (hover: hover){
  .flag-tip[data-tooltip]::after{
    top: calc(100% + 6px);
    bottom: auto;
    transform: translateX(-50%);
  }

  .flag-tip[data-tooltip]:hover::after,
  .flag-tip[data-tooltip]:focus-visible::after{
    opacity: 1;
    transform: translateX(-50%) translateY(1px);
  }
}

/* ==========================================
   MOBILE: composer fisso + feed scrollabile sotto
   (soluzione definitiva, indipendente dallo scroll pagina)
   ========================================== */
@media (max-width: 800px){

  /* 1) Su mobile la pagina NON deve scrollare: scrolla solo il feed */
  body.chat{
    height: 100dvh !important;
    overflow: hidden !important;
  }

  /* 2) Il contenitore deve occupare tutto lo schermo */
  body.chat .chat-layout{
    height: 100dvh !important;
    max-height: 100dvh !important;
  }

  /* 3) La colonna centrale deve poter "collassare" e dare spazio al feed */
  body.chat .col-center{
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: hidden !important; /* impedisce scroll esterni */
  }

  /* 4) Composer: sempre visibile */
  body.chat .chat-compose{
    flex: 0 0 auto !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 60 !important;
    background: var(--card) !important;
  }

  /* 5) Feed: prende tutto lo spazio rimanente */
  body.chat .chat-feed{
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  /* 6) La lista è l’unico scroll vero */
  body.chat .feed-list{
    height: 100% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }
}
.brand-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-name {
  color: #111;
}

html.dark .brand-name {
  color: #fff;
}

html.dark .brand-logo {
  filter: brightness(0) invert(1);
}
