/**
 * ════════════════════════════════════════════════════════
 *  DARK CHAT — dc-responsive.css
 *  Pillar 5: Modern responsive architecture
 *  · CSS Grid + Flexbox shell
 *  · dvh / svh / vvh (set by dc-guard.js visualViewport)
 *  · rem scale, clamp(), container queries
 *  · Virtual keyboard safe-area compensation
 *  · Glassmorphism / neon cyberpunk aesthetic
 *
 *  Include in index.html AFTER your main styles:
 *    <link rel="stylesheet" href="dc-responsive.css">
 * ════════════════════════════════════════════════════════
 */

/* ── Token system ─────────────────────────────────────── */
:root {
  /* Palette */
  --col-bg:        #06060f;
  --col-surface:   rgba(13, 13, 30, 0.92);
  --col-glass:     rgba(18, 18, 42, 0.70);
  --col-border:    rgba(41, 121, 255, 0.18);
  --col-accent:    #2979ff;
  --col-accent2:   #7c3aed;
  --col-glow:      rgba(41, 121, 255, 0.45);
  --col-text1:     #e8eaff;
  --col-text2:     #8b90b8;
  --col-text3:     #444867;
  --col-online:    #00e676;
  --col-danger:    #ff4d6d;
  --col-warn:      #ffb300;
  --col-success:   #00c853;

  /* Typography */
  --font-body:    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-mono:    "Courier New", Courier, monospace;
  --fs-base:      clamp(13px, 3.5vw, 15px);
  --fs-sm:        0.78rem;
  --fs-xs:        0.65rem;
  --fs-lg:        1.1rem;
  --fs-xl:        1.4rem;
  --lh-body:      1.55;
  --lh-compact:   1.3;

  /* Spacing (rem-based, scales with font-size) */
  --sp-xs:   0.25rem;
  --sp-sm:   0.5rem;
  --sp-md:   1rem;
  --sp-lg:   1.5rem;
  --sp-xl:   2rem;

  /* Radius */
  --r-sm:    8px;
  --r-md:    14px;
  --r-lg:    20px;
  --r-pill:  999px;

  /* Shadows */
  --sh-card:    0 4px 24px rgba(0, 0, 0, 0.5);
  --sh-glow:    0 0 20px var(--col-glow);
  --sh-inset:   inset 0 1px 0 rgba(255, 255, 255, 0.06);

  /* Transitions */
  --tr-fast:   150ms ease-out;
  --tr-base:   250ms ease-out;
  --tr-slow:   400ms ease-out;

  /* Viewport heights — overridden by dc-guard.js visualViewport listener */
  --vvh: 100dvh;
  --vvw: 100dvw;
}

/* ── Global base ──────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

html {
  font-size: var(--fs-base);
  scroll-behavior: smooth;
  /* Prevent pull-to-refresh on mobile interfering with chat scroll */
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background-color: var(--col-bg);
  color: var(--col-text1);
  line-height: var(--lh-body);
  /* iOS safe areas */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left:   env(safe-area-inset-left,   0px);
  padding-right:  env(safe-area-inset-right,  0px);
  /* Prevent text size bump on mobile rotation */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ── App shell — CSS Grid layout ─────────────────────── */
#app {
  display: grid;
  grid-template-columns: min(280px, 32vw) 1fr;
  grid-template-rows: 1fr;
  height: var(--vvh, 100dvh);
  max-height: var(--vvh, 100dvh);
  overflow: hidden;
  position: relative;
  contain: strict;  /* isolate layout, paint, style */
}

/* ── Sidebar ──────────────────────────────────────────── */
#sidebar {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  background: var(--col-surface);
  border-right: 1px solid var(--col-border);
  overflow: hidden;
  transition: transform var(--tr-base);
  contain: layout style;
}

#users-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--col-accent) transparent;
}
#users-list::-webkit-scrollbar        { width: 3px; }
#users-list::-webkit-scrollbar-thumb  { background: var(--col-accent); border-radius: 2px; }
#users-list::-webkit-scrollbar-track  { background: transparent; }

/* ── Chat column ─────────────────────────────────────── */
#chat-col {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Message list ────────────────────────────────────── */
#msgs {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
  /* GPU acceleration */
  transform: translateZ(0);
  will-change: scroll-position;
  scrollbar-width: thin;
  scrollbar-color: rgba(41, 121, 255, 0.25) transparent;
}

/* ── Input area ──────────────────────────────────────── */
#input-area {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-md);
  padding-bottom: calc(var(--sp-sm) + env(safe-area-inset-bottom, 0px));
  background: var(--col-surface);
  border-top: 1px solid var(--col-border);
  /* transition set by dc-guard.js for keyboard slide */
  transition: transform 120ms ease-out;
  will-change: transform;
  contain: layout style;
}

#msg-input {
  flex: 1;
  background: rgba(41, 121, 255, 0.07);
  border: 1px solid var(--col-border);
  border-radius: var(--r-lg);
  color: var(--col-text1);
  font-size: var(--fs-base);
  font-family: var(--font-body);
  padding: 0.55rem 1rem;
  resize: none;
  outline: none;
  line-height: var(--lh-body);
  min-height: 2.4rem;
  max-height: 6.5rem;
  overflow-y: auto;
  transition: border-color var(--tr-fast), box-shadow var(--tr-fast);
}
#msg-input:focus {
  border-color: var(--col-accent);
  box-shadow: 0 0 0 2px rgba(41, 121, 255, 0.18);
}

/* ── Chat header ─────────────────────────────────────── */
#chat-hdr {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) var(--sp-md);
  background: var(--col-surface);
  border-bottom: 1px solid var(--col-border);
  min-height: 3.5rem;
  contain: layout style;
}

/* ── Glassmorphism card utility ──────────────────────── */
.glass-card {
  background: var(--col-glass);
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  border: 1px solid var(--col-border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-card), var(--sh-inset);
}

/* ── Toast container ─────────────────────────────────── */
#toast-cont {
  position: fixed;
  bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  z-index: 10000;
  pointer-events: none;
  width: min(320px, 90vw);
}

.toast {
  padding: 0.65rem 1.1rem;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: #fff;
  text-align: center;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  transition: opacity var(--tr-fast);
}
.toast.s { background: rgba(0,200,83,.85);  border: 1px solid rgba(0,200,83,.4);   }
.toast.e { background: rgba(255,77,109,.85); border: 1px solid rgba(255,77,109,.4); }
.toast.i { background: rgba(41,121,255,.85); border: 1px solid rgba(41,121,255,.4); }
.toast.w { background: rgba(255,179,0,.85);  border: 1px solid rgba(255,179,0,.4);  }

/* ── Unread badge ────────────────────────────────────── */
.unread-bdg {
  background: var(--col-accent);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 700;
  border-radius: var(--r-pill);
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 0 8px var(--col-glow);
  /* Smooth transition to 0 */
  transition: opacity var(--tr-fast), transform var(--tr-fast);
}
.unread-bdg[data-count="0"],
.unread-bdg:empty {
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
}

/* ── User list item ──────────────────────────────────── */
.uitem {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 0.65rem var(--sp-md);
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.04);
  transition: background var(--tr-fast);
  /* needed for ripple positioning */
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.uitem:hover,
.uitem:focus-visible { background: rgba(41,121,255,.08); outline: none; }
.uitem.active         { background: rgba(41,121,255,.14); }

/* ── Modal overlay ───────────────────────────────────── */
.mo {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-md);
}
.mo.open { display: flex; }
.mo-inner {
  width: 100%;
  max-width: min(480px, 96vw);
  max-height: calc(var(--vvh, 100dvh) - 2rem);
  overflow-y: auto;
}

/* ── Network status bar ──────────────────────────────── */
#conn-bar {
  height: 0;
  overflow: hidden;
  transition: height var(--tr-fast), background var(--tr-fast);
  font-size: var(--fs-xs);
  text-align: center;
  font-family: var(--font-mono);
  letter-spacing: .06em;
}
#conn-bar.conn-ok  { height: 1.5rem; line-height: 1.5rem; background: rgba(0,200,83,.85);  color:#fff; }
#conn-bar.conn-off { height: 1.5rem; line-height: 1.5rem; background: rgba(255,77,109,.85); color:#fff; }

/* ════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ════════════════════════════════════════════════════════ */

/* ── Mobile portrait (≤ 600px) ───────────────────────── */
@media (max-width: 600px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  #sidebar {
    position: fixed;
    inset: 0;
    z-index: 500;
    width: 100%;
    transform: translateX(0);
    transition: transform var(--tr-base);
  }

  /* Hide sidebar when chat is open (.hm class added by app.js) */
  #sidebar.hm {
    transform: translateX(-100%);
    pointer-events: none;
  }

  #chat-col {
    grid-column: 1;
    position: fixed;
    inset: 0;
  }

  #msgs {
    padding: var(--sp-sm);
  }

  #input-area {
    gap: var(--sp-xs);
    padding: var(--sp-xs) var(--sp-sm);
    padding-bottom: calc(var(--sp-xs) + env(safe-area-inset-bottom, 0px));
  }

  /* Larger touch targets on mobile */
  .uitem             { padding: 0.75rem var(--sp-md); }
  #send-btn          { min-width: 2.8rem; min-height: 2.8rem; }
}

/* ── Tablet landscape (601–900px) ────────────────────── */
@media (min-width: 601px) and (max-width: 900px) {
  #app {
    grid-template-columns: min(240px, 38vw) 1fr;
  }
}

/* ── Desktop (> 900px) ───────────────────────────────── */
@media (min-width: 901px) {
  #app {
    grid-template-columns: min(300px, 28vw) 1fr;
  }
  #msgs {
    padding: var(--sp-md) var(--sp-lg);
  }
}

/* ── Tall screens (> 900px height) ───────────────────── */
@media (min-height: 900px) {
  .uitem { padding: 0.8rem var(--sp-md); }
}

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

/* ── Print: hide everything sensitive ───────────────────── */
@media print {
  body { display: none !important; }
}
