/* ============================================================
   Jarvis Web-App — Dark, reduziert, Mobile First
   ============================================================ */
:root {
  --bg: #0b0b0f;
  --bg-elev: #141419;
  --bg-elev-2: #1c1c24;
  --line: #26262f;
  --text: #f2f2f5;
  --text-dim: #a0a0ad;
  --text-faint: #6b6b78;
  --accent: #6d8bff;
  --accent-soft: rgba(109, 139, 255, 0.14);
  --user-bubble: #2a3350;
  --jarvis-bubble: #17171e;
  --danger: #ffb454;
  --danger-soft: rgba(255, 180, 84, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  --header-h: 56px;
  --nav-h: 64px;
  --composer-h: 68px;
  --maxw: 820px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
}

body { overflow: hidden; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 100%;
  position: relative;
}

/* ---------- Header ---------- */
.app-header {
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  padding-left: 18px;
  padding-right: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 11, 15, 0.85);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; width: 100%; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: conic-gradient(from 130deg, #6d8bff, #a06dff, #6dd6ff, #6d8bff);
  box-shadow: 0 0 14px rgba(109,139,255,0.5);
  flex: 0 0 auto;
}
.brand-name {
  font-size: 17px; font-weight: 700; letter-spacing: 0.18em;
}
.status {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-dim);
  background: var(--bg-elev); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #46d17f;
  box-shadow: 0 0 8px #46d17f;
}
.status.thinking .status-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1s ease-in-out infinite; }
.status.thinking { color: var(--accent); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Main / Views ---------- */
.app-main { flex: 1 1 auto; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }

/* ---------- Chat ---------- */
.chat-scroll {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--composer-h) + var(--nav-h) + var(--safe-bottom) + 8px);
}
.chat-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome {
  text-align: center;
  padding: 42px 16px 26px;
  color: var(--text-dim);
}
.welcome-mark {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 18px;
  background: conic-gradient(from 130deg, #6d8bff, #a06dff, #6dd6ff, #6d8bff);
  box-shadow: 0 8px 30px rgba(109,139,255,0.35);
}
.welcome h2 { color: var(--text); font-size: 22px; font-weight: 650; margin-bottom: 8px; }
.welcome p { font-size: 14.5px; max-width: 340px; margin: 0 auto 20px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text-dim);
  padding: 9px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover, .chip:active { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }

/* Message rows */
.msg { display: flex; width: 100%; animation: rise .25s ease; }
.msg.user { justify-content: flex-end; }
.msg.jarvis { justify-content: flex-start; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.bubble {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: #eef1ff;
  border-bottom-right-radius: 6px;
}
.msg.jarvis .bubble {
  background: var(--jarvis-bubble);
  border: 1px solid var(--line);
  color: var(--text);
  border-bottom-left-radius: 6px;
}
.msg.jarvis.confirm .bubble {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger-soft);
}

/* Typing indicator */
.typing { display: inline-flex; align-items: center; gap: 5px; padding: 4px 2px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2){ animation-delay: .2s; }
.typing span:nth-child(3){ animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity:.25; transform: translateY(0);} 40% { opacity:1; transform: translateY(-3px);} }

/* ---------- Placeholder views ---------- */
.view-placeholder { overflow-y: auto; }
.placeholder {
  max-width: 420px; margin: 0 auto; text-align: center;
  padding: 64px 24px; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  min-height: 100%; justify-content: center;
}
.ph-icon { font-size: 44px; }
.placeholder h2 { color: var(--text); font-size: 22px; }
.placeholder p { font-size: 14.5px; max-width: 320px; }
.ph-tag {
  margin-top: 6px; font-size: 12px; color: var(--accent);
  background: var(--accent-soft); border: 1px solid var(--accent);
  padding: 4px 12px; border-radius: 999px;
}

/* ---------- Composer ---------- */
.composer {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-bottom));
  z-index: 15;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  padding: 8px 12px 10px;
}
.confirm-banner {
  max-width: var(--maxw); margin: 0 auto 8px;
  display: flex; align-items: center; gap: 8px;
  background: var(--danger-soft); border: 1px solid var(--danger);
  color: var(--danger); font-size: 13px;
  padding: 8px 12px; border-radius: var(--radius-sm);
}
.confirm-icon {
  width: 18px; height: 18px; border-radius: 50%; flex: 0 0 auto;
  background: var(--danger); color: #1a1205; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px;
}
.composer-row {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 6px 6px 6px 8px;
}
.composer-input {
  flex: 1 1 auto;
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 16px; line-height: 1.4;
  resize: none; max-height: 132px; padding: 8px 4px;
  font-family: inherit;
}
.composer-input::placeholder { color: var(--text-faint); }
.icon-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 50%;
  border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-dim); background: transparent;
  transition: background .15s, color .15s, transform .1s;
}
.mic-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.send-btn { background: var(--accent); color: #fff; }
.send-btn:disabled { background: var(--bg-elev-2); color: var(--text-faint); cursor: default; }
.send-btn:not(:disabled):active { transform: scale(0.92); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  border-top: 1px solid var(--line);
  background: rgba(11,11,15,0.9);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  z-index: 18;
}
.nav-item {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-faint); font-size: 10.5px; padding: 8px 0 4px;
  transition: color .15s;
}
.nav-item .nav-ic { font-size: 19px; filter: grayscale(0.4) opacity(0.7); transition: filter .15s; }
.nav-item.active { color: var(--accent); }
.nav-item.active .nav-ic { filter: none; }

/* ---------- Desktop / Tablet ---------- */
@media (min-width: 860px) {
  :root { --nav-h: 0px; }
  .app {
    flex-direction: row;
    height: 100dvh;
  }
  /* Sidebar from bottom-nav */
  .bottom-nav {
    height: auto;
    width: 232px;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--line);
    padding: calc(var(--safe-top) + 74px) 12px 20px;
    gap: 4px;
    order: -1;
    background: var(--bg-elev);
  }
  .nav-item {
    flex: 0 0 auto;
    flex-direction: row; justify-content: flex-start; gap: 12px;
    font-size: 14.5px; padding: 12px 14px; border-radius: 12px;
  }
  .nav-item .nav-ic { font-size: 18px; }
  .nav-item.active { background: var(--accent-soft); }

  /* Sidebar brand */
  .bottom-nav::before {
    content: "JARVIS";
    position: absolute; top: calc(var(--safe-top) + 26px); left: 26px;
    font-size: 15px; font-weight: 700; letter-spacing: 0.18em; color: var(--text);
  }
  .bottom-nav::after {
    content: ""; position: absolute; top: calc(var(--safe-top) + 27px); left: 0; margin-left: -0px;
  }

  /* Main column */
  .app-main { order: 0; }
  .app-header { display: none; } /* brand shown in sidebar on desktop */

  .composer {
    left: 232px;
    bottom: 0;
    padding: 12px 24px 20px;
  }
  .chat-scroll { padding-bottom: calc(var(--composer-h) + 40px); }
  .chat-inner { padding-top: 32px; }

  /* Floating desktop status */
  .app::before {
    content: "";
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============================================================
   Boot / Login (Phase 3 – Schritt 1, Mock-Auth)
   ============================================================ */
.boot {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.boot-mark {
  width: 46px; height: 46px; border-radius: 14px;
  background: conic-gradient(from 130deg, #6d8bff, #a06dff, #6dd6ff, #6d8bff);
  box-shadow: 0 8px 30px rgba(109,139,255,0.35);
  animation: bootpulse 1.1s ease-in-out infinite;
}
@keyframes bootpulse { 0%,100%{ opacity:1; transform:scale(1);} 50%{ opacity:.5; transform:scale(.9);} }

.login {
  position: fixed; inset: 0; z-index: 55;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(109,139,255,0.10), transparent 60%),
    var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 20px) 20px calc(var(--safe-bottom) + 20px);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 34px 26px 22px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.45);
}
.login-mark {
  width: 48px; height: 48px; border-radius: 15px; margin: 0 auto 16px;
  background: conic-gradient(from 130deg, #6d8bff, #a06dff, #6dd6ff, #6d8bff);
  box-shadow: 0 8px 30px rgba(109,139,255,0.35);
}
.login-brand { font-size: 17px; font-weight: 700; letter-spacing: 0.2em; margin-bottom: 4px; }
.login-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 22px; }
.login-form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.login-label { font-size: 12.5px; color: var(--text-dim); padding-left: 2px; }
.login-input {
  width: 100%;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-error {
  color: var(--danger); font-size: 13px; padding: 2px;
  animation: rise .2s ease;
}
.login-btn {
  margin-top: 10px;
  position: relative;
  width: 100%; border: none; cursor: pointer;
  background: var(--accent); color: #fff;
  border-radius: 12px; padding: 13px 16px; font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity .15s, transform .1s;
}
.login-btn:disabled { opacity: .6; cursor: default; }
.login-btn:not(:disabled):active { transform: scale(0.98); }
.login-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  display: none; animation: spin .7s linear infinite;
}
.login-btn.loading .login-spinner { display: inline-block; }
.login-btn.loading .login-btn-text { opacity: .85; }
@keyframes spin { to { transform: rotate(360deg); } }
.login-hint { margin-top: 16px; font-size: 11.5px; color: var(--text-faint); }
.login-hint code { background: var(--bg-elev-2); padding: 1px 6px; border-radius: 5px; color: var(--text-dim); }

/* Logout button in header */
.logout-btn {
  margin-left: 8px; flex: 0 0 auto;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text-dim);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.logout-btn:hover { color: var(--text); border-color: var(--accent); }
@media (min-width: 860px) {
  /* Header ist auf Desktop ausgeblendet; Logout in Sidebar-Fuss */
  .logout-btn { position: fixed; top: calc(var(--safe-top) + 20px); right: 20px; z-index: 30; }
}

/* [hidden] muss zuverlaessig ausblenden – schlaegt Layout-Klassenregeln
   (.boot/.login/.app etc. setzen display:flex/block und wuerden [hidden] sonst
   ueberschreiben). */
[hidden] { display: none !important; }
