  :root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --bg-app: #f0f2f5;
    --bg-header: #ffffff;
    --bg-card: #ffffff;
    --text-main: #202124;
    --text-sub: #5f6368;
    --msg-me: #e8f0fe;
    --msg-peer: #ffffff;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-msg: 0 1px 2px rgba(0,0,0,0.1);
  }

  * { box-sizing: border-box; outline: none; -webkit-tap-highlight-color: transparent; }
  
  body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    margin: 0; padding: 0; height: 100dvh; width: 100vw;
    background-color: var(--bg-app); color: var(--text-main);
    display: flex; justify-content: center; overflow: hidden; 
  }

  #app {
    width: 100%; height: 100%; background: var(--bg-card);
    display: flex; flex-direction: column; position: relative;
    filter: blur(0); transition: filter 0.3s;
  }
  
  body.modal-open #app { pointer-events: none; filter: blur(5px); }

  @media (min-width: 768px) {
    body { align-items: center; }
    #app {
      max-width: 768px; height: 90vh; max-height: 900px;
      border-radius: 24px; box-shadow: 0 12px 28px rgba(0,0,0,0.12);
      border: 1px solid #dadce0; overflow: hidden; 
    }
  }

  header {
    flex-shrink: 0; padding: 12px 20px; background: var(--bg-header);
    border-bottom: 1px solid #dadce0; display: flex; justify-content: space-between;
    align-items: center; z-index: 10;
  }

  .header-info { cursor: pointer; display: flex; flex-direction: column; }
  .header-info h3 { margin: 0; font-size: 1.1rem; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 5px; word-break: break-word;}
  .status-badge { display: flex; align-items: center; font-size: 0.75rem; color: var(--text-sub); margin-top: 2px; }
  .dot { height: 8px; width: 8px; background-color: #fbbc04; border-radius: 50%; margin-right: 6px; transition: background-color 0.3s; }
  .online .dot { background-color: #34a853; }
  .menu-btn { background: none; border: none; cursor: pointer; color: var(--text-sub); font-size: 1.5rem; padding: 4px; }

  /* Message Container */
  #messages {
    flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column;
    gap: 8px; background: #eef2f6; scroll-behavior: smooth;
    padding-bottom: 20px; /* Space for overlay */
  }

  .msg-wrapper { display: flex; flex-direction: column; max-width: 85%; transition: opacity 0.3s; }
  /* Animation nur für neue Elemente via JS Klasse */
  .msg-wrapper.new-msg { animation: fadeIn 0.3s ease-out; }
  
  @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
  
  .msg-wrapper.me { align-self: flex-end; align-items: flex-end; }
  .msg-wrapper.peer { align-self: flex-start; align-items: flex-start; }
  .sender-name { font-size: 0.75rem; color: var(--text-sub); margin-bottom: 2px; margin-left: 12px; }
  .me .sender-name { display: none; }

  .msg-bubble {
    padding: 10px 14px; border-radius: 18px; font-size: 0.95rem; line-height: 1.4;
    word-break: break-word; box-shadow: var(--shadow-msg); position: relative;
    transition: background 0.3s, opacity 0.3s;
  }
  .me .msg-bubble { background: var(--msg-me); color: #1e1e1e; border-top-right-radius: 4px; }
  .peer .msg-bubble { background: var(--msg-peer); color: var(--text-main); border-top-left-radius: 4px; }

  .msg-bubble.pending { opacity: 0.7; border: 1px dashed #aaa; }
  .msg-bubble.deleted { font-style: italic; opacity: 0.6; color: #555; background: #f0f0f0 !important; }

  .meta-info { font-size: 0.65rem; margin-top: 4px; color: var(--text-sub); display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
  .del-btn { background: none; border: none; padding: 0; color: #d93025; font-size: 0.65rem; cursor: pointer; }

  .media-content { max-width: 100%; border-radius: 12px; margin-top: 4px; display: block; cursor: pointer; }
  video.media-content { max-height: 300px; background: #000; width: 100%; cursor: default; }
  audio.media-content { margin-top: 5px; width: 200px; }

  /* Controls & Offline Overlay */
  .controls-container {
      position: relative; z-index: 20;
  }

  .offline-overlay {
      position: absolute; bottom: 100%; left: 0; width: 100%;
      background: rgba(255,255,255,0.95); border-top: 1px solid #ddd;
      padding: 20px; text-align: center; color: #555;
      display: flex; flex-direction: column; gap: 10px; align-items: center;
      backdrop-filter: blur(4px);
      transition: transform 0.3s ease;
      transform: translateY(200%); /* Hidden by default */
      border-top-right-radius: 12px;
      border-top-left-radius: 12px;
  }
  .offline-overlay.visible { transform: translateY(0); }

  .controls {
    flex-shrink: 0; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: var(--bg-header); border-top: 1px solid #dadce0; display: flex; gap: 8px; align-items: flex-end;
    transition: opacity 0.3s;
  }
  .controls.disabled { opacity: 0.5; pointer-events: none; filter: grayscale(1); }

  .icon-btn { background: transparent; border: none; color: var(--text-sub); padding: 10px; border-radius: 50%; cursor: pointer; flex-shrink: 0; }
  .input-wrapper {
    flex: 1; background: #f1f3f4; border-radius: 24px; padding: 10px 16px;
    display: flex; align-items: center; min-height: 44px; border: 1px solid transparent;
  }
  .input-wrapper:focus-within { background: #ffffff; border-color: #dadce0; box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
  textarea { width: 100%; background: transparent; border: none; resize: none; font-family: inherit; font-size: 1rem; max-height: 120px; padding: 0; margin: 0; line-height: 1.4; }
  
  button#send {
    background: var(--primary); color: white; width: 44px; height: 44px; border-radius: 50%;
    border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2); flex-shrink: 0; transition: transform 0.2s;
  }
  button#send:active { transform: scale(0.95); }
  button#send.processing { background: #ccc; cursor: wait; }
  button#send svg { width: 20px; height: 20px; fill: currentColor; margin-left: 2px; }

  #menu-overlay {
      position: absolute; top: 60px; right: 10px; background: white; border: 1px solid #ddd;
      border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); display: none; flex-direction: column; z-index: 100; min-width: 200px;
  }
  #menu-overlay a, #menu-overlay button {
      padding: 12px 20px; text-decoration: none; color: #333; font-size: 0.9rem;
      border-bottom: 1px solid #eee; text-align: left; background: none; border:none; width: 100%; cursor: pointer;
  }
  
  #toast {
      position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
      background: rgba(0,0,0,0.8); color: white; padding: 10px 20px; border-radius: 20px;
      font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 200;
  }

  /* LOGIN */
  #login-overlay {
      position: fixed; top: 0; left: 0; width: 100%; height: 100%;
      /* background: rgba(189,122,218,0.5); backdrop-filter: blur(5px);*/ 
      z-index: 1000;
      display: flex; justify-content: center; align-items: center; padding: 20px;
  }
  #login-box {
      background: white; width: 100%; max-width: 400px; padding: 30px; border-radius: 16px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.3); display: flex; flex-direction: column; gap: 15px;
  }
  .login-field { display: flex; flex-direction: column; gap: 5px; }
  .login-field input[type="text"] { padding: 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 1rem; }
  button#btn-login {
      background: var(--primary); color: white; padding: 12px; border: none; border-radius: 8px;
      font-size: 1rem; font-weight: bold; cursor: pointer; margin-top: 10px;
  }
  button#btn-login:disabled { opacity: 0.5; cursor: not-allowed; background: #999; }
