* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #000;
  --surface: #1c1c1e;
  --surface2: #2c2c2e;
  --border: #38383a;
  --blue: #0a84ff;
  --blue-light: #0a84ff22;
  --text: #ffffff;
  --text-muted: #8e8e93;
  --bubble-out: #0a84ff;
  --bubble-in: #2c2c2e;
  --radius: 20px;
  --font: -apple-system, 'SF Pro Text', 'Helvetica Neue', sans-serif;
}

body {
  background: #111;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: var(--font);
  overflow: hidden;
}

/* ─── PANEL REŻYSERA ─────────────────────────────────── */
#director-panel {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 100;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 14px;
  overflow: hidden;
  width: 220px;
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
}

#director-toggle {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  background: #222;
  user-select: none;
  letter-spacing: .3px;
}
#director-toggle:hover { background: #2a2a2a; }

#director-content {
  padding: 12px;
  display: none;
}
#director-content.open { display: block; }

.scene-btn {
  background: #252525;
  border: 1px solid #383838;
  color: #ddd;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 6px;
  transition: background .15s;
}
.scene-btn:hover { background: #2e2e2e; color: #fff; }

.ctrl-btn {
  background: #2a2a2a;
  border: 1px solid #444;
  color: #ccc;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
  font-family: var(--font);
}
.ctrl-btn:hover { background: #333; color: #fff; }
.ctrl-btn.danger { color: #ff453a; border-color: #ff453a44; width: 100%; }
.ctrl-btn.danger:hover { background: #ff453a22; }
#active-user-label { color: #0a84ff; font-weight: 600; }

/* ─── PHONE FRAME ────────────────────────────────────── */
.phone-frame {
  width: 390px;
  height: 844px;
  background: var(--bg);
  border-radius: 48px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 2px solid #2a2a2a;
  box-shadow:
    0 0 0 8px #111,
    0 0 0 10px #1e1e1e,
    0 40px 80px rgba(0,0,0,.9);
  position: relative;
}

/* ─── NOTCH ──────────────────────────────────────────── */
.phone-notch {
  height: 44px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}
.notch-time { font-size: 15px; font-weight: 600; color: #fff; letter-spacing: -.2px; }
.notch-icons { font-size: 12px; color: #fff; letter-spacing: 2px; }

/* ─── HEADER ─────────────────────────────────────────── */
.chat-header {
  height: 60px;
  background: rgba(28,28,30,.95);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-arrow {
  font-size: 32px;
  color: var(--blue);
  cursor: pointer;
  line-height: 1;
  margin-right: 2px;
  font-weight: 300;
}

.avatar-wrap { position: relative; }
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0a84ff, #5ac8fa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.online-dot {
  width: 10px;
  height: 10px;
  background: #30d158;
  border-radius: 50%;
  border: 2px solid var(--bg);
  position: absolute;
  bottom: 0;
  right: 0;
}

.header-info { flex: 1; }
.header-name { font-size: 15px; font-weight: 600; color: #fff; }
.header-status { font-size: 11px; color: #30d158; }

.header-icons { display: flex; gap: 14px; font-size: 18px; cursor: pointer; }

/* ─── MESSAGES ───────────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }

.day-divider {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin: 8px 0 12px;
  position: relative;
}
.day-divider::before,
.day-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--border);
}
.day-divider::before { left: 0; }
.day-divider::after { right: 0; }

/* MESSAGE WRAPPER */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 100%;
  animation: msgIn .25s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-row.out { flex-direction: row-reverse; }

/* MINI AVATAR IN CHAT */
.msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0a84ff, #5ac8fa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.msg-row.out .msg-avatar {
  background: linear-gradient(135deg, #30d158, #5ac8fa);
}
.msg-avatar.hidden { visibility: hidden; }

/* BUBBLE */
.msg-bubble {
  max-width: 72%;
  padding: 9px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.45;
  color: #fff;
  position: relative;
  word-break: break-word;
}

/* incoming – left */
.msg-row.in .msg-bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 5px;
}
/* outgoing – right */
.msg-row.out .msg-bubble {
  background: var(--bubble-out);
  border-bottom-right-radius: 5px;
}

/* timestamp */
.msg-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  padding: 0 4px;
  text-align: right;
}
.msg-row.in .msg-meta { text-align: left; padding-left: 34px; }

/* group bubbles */
.msg-row.in.grouped .msg-bubble  { border-top-left-radius: 5px; border-bottom-left-radius: 5px; }
.msg-row.out.grouped .msg-bubble { border-top-right-radius: 5px; border-bottom-right-radius: 5px; }

/* typing indicator */
.typing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 4px 0;
}
.typing-bubble {
  background: var(--bubble-in);
  border-radius: var(--radius);
  border-bottom-left-radius: 5px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-dot {
  width: 7px;
  height: 7px;
  background: #888;
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%,60%,100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ─── INPUT AREA ─────────────────────────────────────── */
.input-area {
  padding: 8px 12px 20px;
  background: rgba(28,28,30,.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.input-wrap {
  flex: 1;
  background: var(--surface2);
  border-radius: 24px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  border: 1px solid var(--border);
  transition: border-color .2s;
}
.input-wrap:focus-within { border-color: var(--blue); }

.icon-btn {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  line-height: 1;
}

#msg-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 15px;
  font-family: var(--font);
  padding: 10px 4px;
  caret-color: var(--blue);
}
#msg-input::placeholder { color: #555; }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--blue);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .1s, opacity .15s;
}
.send-btn:active { transform: scale(.9); }

/* ─── RESPONSIVE ─────────────────────────────────────── */
@media (max-width: 440px) {
  body { background: #000; align-items: flex-start; }
  .phone-frame {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
  #director-panel { top: auto; bottom: 80px; left: 10px; width: 200px; }
}