:root{
  --bg:#0f1115;
  --panel:#161a22;
  --muted:#8b928f;
  --text:#e7ebea;
  --olive:#6b8f00;
  --olive-2:#516a00;
  --danger:#b84a4a;
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--text);font:14px/1.45 Inter,system-ui,Segoe UI,Arial,'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif;border:none;color:#fff;padding:.6rem .9rem;border-radius:12px;cursor:pointer;transition:.2s;box-shadow:0 6px 18px rgba(107,143,0,.25)}
.btn:hover{transform:translateY(-1px)}
.btn.primary{background:var(--olive)}
.btn.outline{background:transparent;border:1px solid var(--olive);color:var(--text)}
.btn.subtle{background:transparent;color:var(--muted)}
.btn.danger{background:var(--danger)}
.btn.small{padding:.3rem .5rem;border-radius:10px;font-size:.85rem}
input,select{background:#0b0d10;color:var(--text);border:1px solid #222;padding:.6rem;border-radius:12px;outline:none}
label{display:block;margin:0 0 .3rem;color:var(--muted)}
.form .row{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.card{background:var(--panel);border:1px solid #1f2530;border-radius:16px;padding:16px;margin:16px 0;box-shadow:0 8px 24px rgba(0,0,0,.25)}

#app{display:grid;grid-template-columns:280px 1fr;height:100vh}
.sidebar{background:linear-gradient(180deg,#10141b,#0d1016);border-right:1px solid #1f2530;padding:16px;display:flex;flex-direction:column;gap:12px}
.brand{font-weight:700;color:#dfe7d3;font-size:1.1rem}
.section-title{margin-top:8px;color:var(--muted);font-size:.85rem}
#rooms li,#users li{list-style:none;padding:8px 10px;border-radius:12px;cursor:pointer;margin:6px 0}
#rooms li:hover,#users li:hover{background:#151a21}
#rooms li.active,#users li.active{background:#121812;border:1px solid var(--olive-2)}
.chat{display:flex;flex-direction:column}
.chat-header{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid #1f2530;background:rgba(12,14,18,.6);backdrop-filter: blur(6px);position:sticky;top:0}
.history{padding:16px;overflow:auto;flex:1;display:flex;flex-direction:column;gap:10px}
.msg{display:flex;gap:10px;align-items:flex-start}
.msg .bubble{background:#151a21;border:1px solid #212938;padding:10px 12px;border-radius:16px;max-width:70%}
.msg.me{justify-content:flex-end}
.msg.me .bubble{background:#18210f;border:1px solid #22310f}
.meta{font-size:.75rem;color:var(--muted);margin-bottom:4px}
.composer{display:flex;gap:8px;padding:12px;border-top:1px solid #1f2530;background:rgba(12,14,18,.6)}
.emoji-picker{position:relative}
.emoji-grid{position:absolute;bottom:42px;left:0;background:#0b0d10;border:1px solid #20262f;border-radius:12px;padding:8px;display:grid;grid-template-columns:repeat(8, 28px);gap:6px;max-width:260px}
.emoji-grid button{background:transparent;border:none;font-size:20px;cursor:pointer}
.msg img{max-width:280px;border-radius:8px;border:1px solid #2a343d}
.login-card{max-width:380px;margin:12vh auto;background:var(--panel);padding:24px;border-radius:16px;border:1px solid #20252f;box-shadow:0 16px 40px rgba(0,0,0,.35)}
.login-card h1{margin-top:0}
.hint{color:var(--muted)}
.error{background:#3a1a1a;border:1px solid #5a2a2a;padding:10px;border-radius:10px;margin-bottom:10px}
.admin{max-width:900px;margin:6vh auto;padding:0 16px}
table{width:100%;border-collapse:collapse}
th,td{border-bottom:1px solid #1f2530;padding:10px;text-align:left}

.typing{color:var(--muted);font-size:.85rem;padding:6px 12px}


/* === Mobile improvements === */
:root{ --safe-bottom: env(safe-area-inset-bottom); }

/* Base tap targets */
button, .btn { min-height: 40px; }

/* Make composer sticky and accommodate safe area on iOS */
.composer{
  position: sticky;
  bottom: 0;
  padding-bottom: calc(12px + var(--safe-bottom));
}

/* Dynamic viewport height helper */
html, body { height: auto; min-height: 100vh; }
#app { height: calc(var(--vh, 1vh) * 100); }

/* Sidebar becomes overlay on small screens */
@media (max-width: 900px){
  #app{ grid-template-columns: 1fr; }
  .sidebar{
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 78%;
    max-width: 340px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 30;
  }
  .sidebar.open{ transform: translateX(0); }
  .chat-header{ gap: 8px; }
  .chat-header #roomTitle{ font-size: 1rem; }
  .btn.icon{ background: transparent; border:1px solid #2a3420; padding:.4rem .6rem; border-radius:10px }
  .history{ padding: 12px; }
  /* Emoji grid tighter on mobile */
  .emoji-grid{ grid-template-columns: repeat(7, 30px); gap: 6px; }
}

/* Very small screens */
@media (max-width: 420px){
  .emoji-grid{ grid-template-columns: repeat(6, 30px); }
  #messageInput{ font-size: 16px; } /* avoid zoom on iOS */
  .btn{ padding:.55rem .8rem }
}

@media (min-width: 900px){ #menuBtn{ display:none !important; } }

/* === Composer redesign === */
.composer{
  display:flex;
  gap:10px;
  padding:12px;
  border-top:1px solid #1f2530;
  background:rgba(12,14,18,.6);
}
/* capsule container */
#messageInput{
  flex:1;
  background:#0b0d10;
  border:1px solid #2a3420;
  border-radius:16px;
  padding:12px 14px;
  color:var(--text);
  min-height:64px;
  max-height:200px;
  line-height:1.5;
  font-size:16px; /* avoids iOS zoom */
  resize:none;
}
.btn{min-height:44px}
#sendBtn{padding:.65rem 1rem;border-radius:14px}
#imageBtn{padding:.65rem .8rem;border-radius:14px}
.emoji-picker summary{
  display:inline-flex;align-items:center;justify-content:center;
  width:38px;height:38px;border:1px solid #2a3420;border-radius:14px;background:transparent;cursor:pointer;
}
.emoji-grid{background:#0b0d10}
/* Mobile tighter */
@media (max-width: 900px){
  #messageInput{min-height:56px}
}
