/* Diagnosetagebuch — Messenger-Style Chat UI */

/* ── Login-Overlay ── */
#login-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
#login-overlay.visible { display: flex; }
#login-box {
  background: white;
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  margin: 20px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
#login-box h2 {
  font-size: 20px;
  margin-bottom: 6px;
}
#login-box p {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 20px;
}
#login-token {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: var(--font);
  margin-bottom: 12px;
  outline: none;
}
#login-token:focus { border-color: #999; }
#login-btn {
  width: 100%;
  padding: 13px;
  background: #1a1a1a;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-family: var(--font);
  cursor: pointer;
  font-weight: 500;
}
#login-btn:active { opacity: 0.8; }
#login-error {
  margin-top: 10px;
  font-size: 13px;
  color: #e53935;
  min-height: 18px;
}

:root {
  --bg: #f5f5f5;
  --chat-bg: #ffffff;
  --bot-bubble: #e8e8e8;
  --user-bubble: #1a1a1a;
  --user-text: #ffffff;
  --bot-text: #1a1a1a;
  --confirm-color: #4a7c59;
  --ai-bubble: #e8eef5;
  --muted: #999999;
  --border: #e0e0e0;
  --btn-bg: #f0f0f0;
  --btn-hover: #d8d8d8;
  --btn-active: #1a1a1a;
  --btn-active-text: #ffffff;
  --pending-badge: #e53935;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  background: var(--bg);
  color: var(--bot-text);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--chat-bg);
}

/* ── Header ── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--chat-bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

#header h1 {
  font-size: 17px;
  font-weight: 600;
}

#header .status {
  font-size: 12px;
  color: var(--muted);
}

/* ── Reload-Button ── */
#reload-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  color: var(--bot-text);
}
#reload-btn:active { opacity: 0.5; }

/* ── Hamburger-Menü ── */
#menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
#menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--bot-text);
  border-radius: 2px;
  transition: background 0.15s;
}
#menu-btn:active span { background: var(--muted); }

#menu-dropdown {
  display: none;
  position: absolute;
  top: 53px;
  right: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  z-index: 200;
  overflow: hidden;
  min-width: 180px;
}
#menu-dropdown.open { display: block; }
#menu-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  font-size: 15px;
  color: var(--bot-text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
#menu-dropdown a:last-child { border-bottom: none; }
#menu-dropdown a:active { background: var(--bg); }

/* ── Chat ── */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Nachrichten ── */
.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.4;
  word-wrap: break-word;
  font-size: 15px;
}

.msg.bot {
  background: var(--bot-bubble);
  border-bottom-left-radius: 4px;
}

.msg.user {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.msg.confirm {
  background: none;
  color: var(--confirm-color);
  font-size: 14px;
  padding: 4px 14px;
}

.msg.ai-bot {
  background: var(--ai-bubble);
  border-bottom-left-radius: 4px;
}

.msg.ai-user {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.msg.note {
  background: #fff3e0;
  color: #5d4037;
  border-bottom-right-radius: 4px;
  font-style: italic;
}

.msg-tag {
  display: inline-block;
  font-size: 10px;
  font-style: normal;
  padding: 1px 7px;
  border-radius: 8px;
  color: white;
  margin-left: 6px;
  vertical-align: middle;
}

.msg.system {
  background: none;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* Wrapper-Alignment im Chat-Flex */
.swipe-wrapper { align-self: stretch; }
.swipe-wrapper.align-start .msg { margin-right: auto; }
.swipe-wrapper.align-end .msg { margin-left: auto; }
.swipe-wrapper.align-center .msg { margin-left: auto; margin-right: auto; }

.msg.archived {
  opacity: 0.5;
}

.msg .time {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.msg.user .time,
.msg.ai-user .time {
  color: rgba(255,255,255,0.6);
}

/* ── Kompaktblock ── */
.compact-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.compact-block .question-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.compact-block .question-text {
  font-size: 14px;
  color: var(--bot-text);
}

.compact-block .question-row.answered .question-text {
  color: var(--confirm-color);
}

.compact-block .question-row.answered .question-text::before {
  content: '✓ ';
}

/* ── Question Header + Info ── */
.question-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.info-btn:hover {
  border-color: var(--bot-text);
  color: var(--bot-text);
}

.info-popup {
  position: fixed;
  z-index: 100;
  max-width: 260px;
  padding: 10px 12px;
  background: var(--bot-text);
  color: var(--user-text);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.info-popup strong {
  font-size: 14px;
}

/* ── Buttons ── */
.btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-row button {
  flex: 1;
  min-width: 44px;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--btn-bg);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-row button:hover {
  background: var(--btn-hover);
}

.btn-row button:active,
.btn-row button.selected {
  background: var(--btn-active);
  color: var(--btn-active-text);
  border-color: var(--btn-active);
}

.btn-row button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Numerische Eingabe (Garmin) ── */
.numeric-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.numeric-input {
  width: 80px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: var(--font);
  text-align: center;
  -moz-appearance: textfield;
}

.numeric-input::-webkit-outer-spin-button,
.numeric-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.numeric-input:focus {
  outline: none;
  border-color: #999;
}

.numeric-unit {
  font-size: 13px;
  color: var(--muted);
}

/* ── Block-Senden-Button ── */
.block-send-btn {
  margin-top: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--btn-active);
  color: var(--btn-active-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.block-send-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ── Tag-Bar ── */
#tag-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--chat-bg);
  transition: opacity 0.3s;
}
#tag-bar.fading { opacity: 0; }
.tag-label {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}
.tag-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.tag-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--btn-bg);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tag-btn:active, .tag-btn.selected {
  background: var(--tag-color, #999);
  color: white;
  border-color: var(--tag-color, #999);
}
.tag-dismiss {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ── Pending-Bar ── */
#pending-bar {
  display: none;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 16px;
  border-top: 1px solid var(--border);
  background: var(--chat-bg);
}

/* ── Notification-Banner ── */
#notification-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  background: #f8f4e8;
  border-bottom: 1px solid #e8dfc8;
  font-size: 13px;
}
#notification-banner button {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
}
#notif-allow {
  background: var(--accent);
  color: white;
}
#notif-dismiss {
  background: transparent;
  color: var(--muted);
}

/* ── Input-Bar ── */
#input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--chat-bg);
  position: sticky;
  bottom: 0;
}

#input-bar textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  resize: none;
  overflow: hidden;
  line-height: 1.4;
  max-height: 120px;
  min-height: 38px;
  height: 38px;
  transition: height 0.1s ease;
}

#input-bar textarea:focus {
  border-color: #999;
}

#input-bar textarea.multiline {
  overflow-y: auto;
  border-radius: 16px;
}

#input-bar button {
  padding: 10px 16px;
  border: none;
  border-radius: 20px;
  background: var(--user-bubble);
  color: var(--user-text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

#input-bar button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Swipe-to-Delete ── */
.swipe-wrapper {
  position: relative;
  overflow: visible;
}
.swipe-wrapper .msg {
  position: relative;
  z-index: 1;
}

.swipe-delete-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background: #e53935;
  color: white;
  border: none;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.swipe-wrapper.swiped .swipe-delete-btn {
  opacity: 1;
  pointer-events: auto;
}

/* ── Datum-Trenner ── */
.date-separator {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 12px 0 4px;
}

/* ── Loading ── */
.loading {
  text-align: center;
  color: var(--muted);
  padding: 20px;
  font-size: 14px;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  #app { max-width: 100%; }
}
