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

:root {
  --bg:        #0d0f14;
  --sidebar:   #13161e;
  --surface:   #1a1e2a;
  --surface2:  #222639;
  --border:    #2a2f45;
  --accent:    #5b7fff;
  --accent-h:  #7b97ff;
  --green:     #34d399;
  --red:       #f87171;
  --yellow:    #fbbf24;
  --text:      #f0f2fc;
  --text-2:    #c4cbe8;
  --text-3:    #8891b0;
  --radius:    14px;
  --sidebar-w: 240px;
}

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  height: 100dvh;   /* dynamic viewport — poprawka dla mobile */
  overflow: hidden;
}

/* ─── SIDEBAR ─────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 0 16px;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.logo-icon { font-size: 1.4rem; }
.logo-text  { font-size: 1rem; font-weight: 700; letter-spacing: -0.02em; }

.sidebar-section { padding: 0 10px 8px; }
.sidebar-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a0aac8;
  padding: 0 8px 6px;
}

.lang-list, .mode-list, .pdf-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lang-btn, .mode-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  color: #c8d0ea;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}
.lang-btn:hover, .mode-btn:hover { background: var(--surface); color: #fff; }
.lang-btn.active, .mode-btn.active {
  background: rgba(91,127,255,0.18);
  color: #a8bfff;
  font-weight: 600;
}
.flag { font-size: 1.1rem; }

.sidebar-bottom { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }

.pdf-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 1px solid #3a4160;
  color: #c8d0ea;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all 0.15s;
  margin-bottom: 3px;
  text-align: left;
}
.pdf-btn:hover { background: var(--surface); border-color: var(--accent); color: #fff; }

/* ─── MAIN ────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* topbar mobile — ukryty na desktop */
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
}
.menu-btn {
  background: none; border: none; color: var(--text); font-size: 1.3rem; cursor: pointer; padding: 4px;
}
.topbar-title { font-weight: 700; font-size: 1rem; flex: 1; }
.topbar-lang  { font-size: 0.85rem; color: var(--text-2); }

/* ─── CHAT ────────────────────────────────────── */
.chat-wrap {
  flex: 1;
  min-height: 0;        /* pozwala flex-item się skurczyć */
  overflow-y: auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-wrap::-webkit-scrollbar { width: 4px; }
.chat-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* welcome */
.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-2);
}
.welcome-icon  { font-size: 3rem; opacity: 0.4; }
.welcome-title { font-size: 1.2rem; font-weight: 600; color: var(--text); }
.welcome-sub   { font-size: 0.9rem; max-width: 340px; line-height: 1.6; }

/* messages */
.message {
  display: flex;
  gap: 10px;
  max-width: 720px;
  animation: msgIn 0.2s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.message.user { flex-direction: row-reverse; align-self: flex-end; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  margin-top: 2px;
}
.message.user .msg-avatar  { background: var(--accent); }
.message.ai   .msg-avatar  { background: var(--surface2); }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.93rem;
  line-height: 1.6;
  max-width: calc(100% - 44px);
  word-break: break-word;
}
.message.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.ai .msg-bubble {
  background: var(--surface);
  border-bottom-left-radius: 4px;
}
.message.system .msg-bubble {
  background: transparent;
  color: var(--text-3);
  font-size: 0.8rem;
  font-style: italic;
  padding: 4px 0;
}
.message.system { align-self: center; }
.message.system .msg-avatar { display: none; }

/* thinking */
.thinking .msg-bubble { color: var(--text-2); font-style: italic; }
.dots { display: inline-flex; gap: 3px; margin-left: 4px; }
.dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-3);
  animation: dot 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot { 0%,80%,100% { transform: scale(0.7); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

/* ─── KOREKTY ─────────────────────────────────── */
.corrections-panel {
  background: rgba(52,211,153,0.07);
  border: 1px solid rgba(52,211,153,0.25);
  border-radius: 10px;
  padding: 12px 14px;
  max-width: 720px;
  align-self: flex-start;
}
.corrections-header {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.correction-item { margin-bottom: 8px; }
.correction-error { font-size: 0.85rem; color: var(--red); }
.correction-fix   { font-size: 0.85rem; color: var(--green); }
.correction-explain { font-size: 0.8rem; color: var(--text-3); }
.hidden { display: none !important; }

/* ─── INPUT BAR ───────────────────────────────── */
.input-bar {
  flex-shrink: 0;       /* nigdy nie znikaj */
  padding: 10px 20px 18px;
  padding-bottom: max(18px, env(safe-area-inset-bottom)); /* iPhone notch */
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-msg {
  font-size: 0.78rem;
  color: var(--text-3);
  text-align: center;
  min-height: 16px;
}
.status-msg.active { color: var(--yellow); }

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 8px;
  transition: border-color 0.2s;
}
.input-row:focus-within { border-color: var(--accent); }

#text-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.93rem;
  font-family: inherit;
  padding: 6px 4px;
  outline: none;
}
#text-input::placeholder { color: var(--text-3); }

.mic-btn {
  width: 38px; height: 38px;
  border-radius: 9px;
  border: none;
  background: var(--surface2);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.mic-btn svg { width: 17px; height: 17px; }
.mic-btn:hover { background: var(--border); color: var(--text); }
.mic-btn.recording {
  background: rgba(248,113,113,0.2);
  color: var(--red);
  animation: pulse-rec 1s infinite;
}
@keyframes pulse-rec {
  0%,100% { box-shadow: 0 0 0 0 rgba(248,113,113,0.3); }
  50%      { box-shadow: 0 0 0 6px rgba(248,113,113,0); }
}

.send-btn {
  width: 38px; height: 38px;
  border-radius: 9px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.send-btn svg { width: 16px; height: 16px; }
.send-btn:hover  { background: var(--accent-h); }
.send-btn:active { transform: scale(0.93); }

/* ─── KOSZTY ──────────────────────────────────── */
.cost-box {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 4px;
}
.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 8px;
}
.cost-label { font-size: 0.8rem; color: #a0aac8; }
.cost-val   { font-size: 0.83rem; font-weight: 600; color: #d0d8f0; font-variant-numeric: tabular-nums; }
.cost-val.nonzero { color: var(--yellow); }
.cost-details {
  padding: 4px 8px 2px;
  font-size: 0.76rem;
  color: #9099b8;
  line-height: 1.7;
  white-space: pre;
}
.cost-links {
  display: flex;
  gap: 6px;
  padding: 6px 8px 2px;
  flex-wrap: wrap;
}
.cost-link {
  font-size: 0.72rem;
  color: var(--accent);
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.cost-link:hover { opacity: 1; text-decoration: underline; }

/* ─── MOBILE ──────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}

@media (max-width: 680px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .topbar { display: flex; }

  .main {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .chat-wrap {
    padding: 12px 12px 8px;
  }

  .input-bar {
    padding: 8px 12px max(14px, env(safe-area-inset-bottom));
  }

  .message { max-width: 100%; }

  /* topbar nie skraca czatu */
  .topbar { flex-shrink: 0; }
}
