:root {
  --navy: #0b1f3a;
  --teal: #0f6c7d;
  --gold: #d8b46a;
  --white: #ffffff;
  --shadow: 0 24px 60px rgba(11, 31, 58, 0.15);
  --chat-width: 33vw;
  --chat-width-expanded: 50vw;
  /* Typography scale */
  --fs-base: 0.9rem;    /* message text */
  --fs-small: 0.78rem;  /* labels, disclaimers, badges, feedback */
  --fs-xs: 0.7rem;      /* mobile buttons */
}

.chat-bubble {
  position: fixed;
  right: 28px;
  bottom: 28px;
  background: var(--navy);
  color: var(--white);
  border: none;
  padding: 18px 24px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  box-shadow: 0 20px 50px rgba(11, 31, 58, 0.25);
  z-index: 10001;
}

body.chat-open .chat-bubble {
  display: none;
}

.chat-bubble .pulse {
  width: 15px;
  height: 15px;
  background: var(--gold);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

/* #2 — explicit font stack for consistent rendering */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: var(--chat-width);
  min-width: 320px;
  max-width: 800px;
  background: var(--white);
  box-shadow: -12px 0 40px rgba(11, 31, 58, 0.18);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease, width 0.2s ease;
  z-index: 10000;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

body.chat-open .chat-panel {
  transform: translateX(0);
}

body.chat-expanded .chat-panel {
  width: var(--chat-width-expanded);
}

.chat-panel header {
  position: sticky;
  top: 0;
  z-index: 10003;
  background: var(--navy);
  color: var(--white);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 10002;
}

.chat-panel header h3 {
  margin: 0;
  font-size: 1rem;
}

.app-version {
  font-size: 0.65em;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.55);
  margin-left: 0.5em;
  vertical-align: middle;
}

.chat-panel header p {
  margin: 4px 0 0;
  font-size: 0.75rem;
  opacity: 0.8;
}

.chat-panel header button {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: var(--white);
  font-size: 1rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}

/* Provider toggle */
.provider-toggle {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 2px;
}

.provider-btn {
  background: transparent !important;
  border: none !important;
  color: rgba(255, 255, 255, 0.6) !important;
  font-size: 0.72rem !important;
  padding: 4px 10px !important;
  border-radius: 999px !important;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.provider-btn.active {
  background: var(--gold) !important;
  color: var(--navy) !important;
  font-weight: 600;
}

.provider-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.18) !important;
  color: var(--white) !important;
}

.chat-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.message {
  padding: 12px 14px;
  border-radius: 12px;
  max-width: 90%;
  line-height: 1.5;
  font-size: var(--fs-base);
}

.message.user {
  align-self: flex-end;
  background: var(--navy);
  color: var(--white);
}

/* #6 — teal left accent for bot messages */
.message.bot {
  align-self: flex-start;
  background: var(--white);
  border: 1px solid rgba(11, 31, 58, 0.12);
  border-left: 3px solid var(--teal);
}

.feedback-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid rgba(11, 31, 58, 0.1);
}

.feedback-label {
  width: 100%;
  font-size: 0.7rem;
  color: #888;
  margin-bottom: 1px;
}

.feedback-btn {
  position: relative;
  background: transparent;
  border: 1px solid rgba(11, 31, 58, 0.12);
  border-radius: 6px;
  padding: 4px 5px;
  min-width: 34px;
  min-height: 34px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.15s;
  line-height: 0;
}

.feedback-btn:hover:not(:disabled) {
  background: rgba(11, 31, 58, 0.06);
  border-color: rgba(11, 31, 58, 0.25);
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(11, 31, 58, 0.12);
}

.feedback-btn.active {
  border-color: var(--teal);
  background: rgba(15, 108, 125, 0.10);
}

.feedback-btn:disabled {
  cursor: default;
}

.feedback-btn:not(.active):disabled {
  opacity: 0.35;
}

.feedback-icon {
  width: 22px;
  height: 22px;
  display: block;
}

/* Green confirmation label */
.feedback-label-done {
  color: #2E7D32;
  font-weight: 600;
}

.feedback-dialog-inline {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
  padding: 8px;
  background: rgba(11, 31, 58, 0.03);
  border: 1px solid rgba(11, 31, 58, 0.1);
  border-radius: 8px;
}


.feedback-dialog-textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(11, 31, 58, 0.2);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--navy);
  resize: vertical;
  outline: none;
}

.feedback-dialog-textarea:focus {
  border-color: var(--teal);
}

.feedback-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.feedback-dialog-send {
  background: var(--teal);
  color: var(--white);
  border: none;
  border-radius: 5px;
  padding: 3px 10px;
  font-size: var(--fs-small);
  cursor: pointer;
}

.feedback-dialog-send:hover {
  opacity: 0.88;
}

.feedback-dialog-cancel {
  background: transparent;
  color: var(--navy);
  border: 1px solid rgba(11, 31, 58, 0.2);
  border-radius: 5px;
  padding: 3px 10px;
  font-size: var(--fs-small);
  cursor: pointer;
}

.feedback-dialog-cancel:hover {
  background: rgba(11, 31, 58, 0.05);
}

.message.bot h1,
.message.bot h2,
.message.bot h3 {
  font-family: inherit;
  color: var(--navy);
  margin: 0.2em 0 0.4em;
  font-size: 1rem;
}

.message.bot p {
  margin: 0.4em 0;
}

/* #7 — better list spacing */
.message.bot ul,
.message.bot ol {
  margin: 0.6em 0 0.8em 1.4em;
  padding: 0;
}

.message.bot li {
  margin: 0.4em 0;
}

.message.bot a {
  color: var(--teal);
  text-decoration: underline;
}

.message.bot strong {
  color: var(--navy);
}

/* #1 — amber warning tone instead of alarm-red */
.test-mode-badge {
  display: block;
  background: #fff3e0;
  color: #e65100;
  border-left: 3px solid #e65100;
  font-weight: 400;
  font-size: var(--fs-small);
  padding: 5px 10px;
  margin-bottom: 6px;
  border-radius: 4px;
  line-height: 1.4;
}

/* #3 — more breathing room for disclaimer */
.chat-disclaimer {
  display: block;
  color: #666;
  font-size: var(--fs-small);
  line-height: 1.4;
  padding: 6px 12px 2px;
  text-align: center;
}

.message.bot code {
  background: rgba(11, 31, 58, 0.06);
  padding: 0.1em 0.3em;
  border-radius: 6px;
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85em;
}

.message.bot pre {
  background: rgba(11, 31, 58, 0.06);
  padding: 0.6em;
  border-radius: 10px;
  overflow-x: auto;
}

.message.typing {
  font-style: italic;
  color: var(--navy) !important;
  align-self: flex-start;
  background: #eef2f7 !important;
  border: 1px solid rgba(11, 31, 58, 0.12) !important;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: var(--fs-base);
}


.typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.typing-dots .dot {
  display: block;
  width: 8px;
  height: 8px;
  background: var(--teal);
  border-radius: 50%;
  animation: dotBounce 1.4s ease-in-out infinite;
}

.typing-dots .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots .dot:nth-child(3) {
  animation-delay: 0.4s;
}

.typing-text {
  margin-left: 4px;
}

@keyframes dotBounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* #3 — slightly more top padding for breathing room */
.chat-footer {
  padding: 14px 16px 16px;
  background: var(--white);
  border-top: 1px solid rgba(11, 31, 58, 0.08);
}

/* #8 — message timestamps */
.message-time {
  display: block;
  font-size: 0.7rem;
  color: #999;
  margin-top: 4px;
}
.message.user .message-time {
  text-align: right;
}

.chat-footer .reset {
  background: transparent;
  border: none;
  color: var(--teal);
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(11, 31, 58, 0.12);
  font-family: inherit;
}

/* #4 — more prominent send button */
.input-row button {
  background: var(--teal);
  color: var(--white);
  border: none;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  70% {
    transform: scale(2.4);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-to-input {
  position: absolute;
  top: -100px;
  left: 10px;
  background: var(--navy);
  color: var(--white);
  padding: 8px 16px;
  border-radius: 4px;
  z-index: 99999;
  font-size: 0.85rem;
}

.skip-to-input:focus {
  top: 60px;
}

.demo-watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-30deg);
  z-index: 9000;
  pointer-events: none;
  font-size: 6vw;
  font-weight: 900;
  color: rgba(255, 0, 0, 0.35);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  user-select: none;
}

@media (prefers-reduced-motion: reduce) {
  .pulse,
  .typing-dots .dot {
    animation: none;
  }
}

@media (max-width: 1100px) {
  .chat-panel {
    width: 100%;
    min-width: 0;
  }
  body.chat-expanded .chat-panel {
    width: 100%;
  }
  .provider-btn {
    font-size: 0.65rem !important;
    padding: 3px 7px !important;
  }
}

@media (max-width: 600px) {
  .chat-panel,
  body.chat-expanded .chat-panel {
    width: 100vw !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 100dvh;
    left: 0 !important;
    right: 0 !important;
  }

  .chat-panel header {
    padding: 8px 10px;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .chat-panel header h3 {
    font-size: 0.82rem;
  }

  .chat-panel header p {
    font-size: 0.65rem;
    margin: 0;
  }

  .chat-panel header > div:first-child {
    min-width: 0;
    flex-shrink: 1;
  }

  .chat-actions {
    gap: 4px;
    margin-left: auto;
  }

  #chatNew {
    font-size: 0.65rem;
    padding: 3px 6px;
    white-space: normal;
    line-height: 1.2;
    max-width: 5.5em;
    text-align: center;
  }

  #chatPrint,
  #chatClose {
    padding: 3px 6px;
    min-width: 28px;
    min-height: 28px;
  }


  .chat-body {
    padding: 10px;
    gap: 8px;
  }

  /* #10 — iOS safe area for home indicator */
  .chat-footer {
    padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  }

  .chat-disclaimer {
    font-size: 0.65em;
  }

  .message {
    max-width: 95%;
    font-size: var(--fs-base);
  }

  .test-mode-badge {
    font-size: 0.75em;
    padding: 3px 8px;
  }

  .feedback-bar {
    gap: 3px;
  }

  .feedback-label {
    font-size: 0.65em;
  }

  .feedback-dialog-inline {
    padding: 8px;
  }
}


#chatNew {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--white);
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}

#chatNew:hover {
  background: rgba(255, 255, 255, 0.22);
}

#chatPrint,
#chatExpand,
#chatClose {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--white);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
}

#chatPrint:hover,
#chatExpand:hover,
#chatClose:hover {
  background: rgba(255, 255, 255, 0.22);
}


.chat-bubble, .chat-panel, .voice-bubble {
  pointer-events: auto;
}

/* Voice bubble — above chat bubble */
.voice-bubble {
  position: fixed;
  right: 28px;
  bottom: 90px;
  background: var(--navy);
  color: var(--white);
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 20px 50px rgba(11, 31, 58, 0.25);
  z-index: 10001;
}

.voice-bubble .pulse {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--gold);
  border-radius: 50%;
  top: 4px;
  right: 4px;
  animation: pulse 2s infinite;
}

/* Hide bubbles when panels are open */
body.chat-open .voice-bubble,
body.voice-open .chat-bubble,
body.voice-open .voice-bubble {
  display: none;
}

/* --- Print styles --- */
@media print {
  /* Hide everything except chat messages */
  body > *:not(.chat-panel) {
    display: none !important;
  }
  .chat-bubble,
  .voice-bubble,
  .voice-overlay,
  .chat-panel header,
  .chat-footer,
  .feedback-bar,
  .message.typing,
  #chatPrint {
    display: none !important;
  }

  .demo-watermark {
    display: none !important;
  }

  .chat-panel {
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    box-shadow: none !important;
    border: none !important;
    background: white !important;
  }

  .chat-body {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
    display: block !important;
    padding: 0 !important;
  }

  .message {
    break-inside: avoid;
    box-shadow: none !important;
    max-width: 100% !important;
    margin-bottom: 12px;
  }

  .message.user {
    background: #e8edf2 !important;
    color: #1a1a1a !important;
    text-align: right;
  }

  .message.bot {
    background: #f5f5f5 !important;
    border: 1px solid #ddd !important;
  }

  /* Print header */
  .chat-panel::before {
    content: "Wirtualny Asystent UM Szczecin — zapis rozmowy";
    display: block;
    font-size: 14pt;
    font-weight: 700;
    padding: 12px 0 16px;
    border-bottom: 2px solid #333;
    margin-bottom: 16px;
  }
}
