/* Walter — meter.me Setup Agent */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --navy:     #313349;
  --blue:     #4997c7;
  --darkblue: #1b4e66;
  --green:    #87ac63;
  --gray1:    #898a95;
  --gray2:    #cbcbd1;
  --bg:       #f4f5f7;
  --white:    #ffffff;
  --radius:   20px;
  --topbar-h: 54px;
}
html, body { height: 100%; font-family: 'Montserrat', sans-serif; background: var(--bg); color: var(--navy); }
body.chat-page { height: 100dvh; overflow: hidden; overscroll-behavior: none; }
.topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); background: var(--navy); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { height: 28px; }
.walter-label { color: var(--gray2); font-size: 13px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; padding-left: 10px; border-left: 1px solid rgba(255,255,255,0.2); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--blue); }
.user-name { color: var(--gray2); font-size: 13px; font-weight: 500; }
.nav-link { color: var(--gray2); text-decoration: none; font-size: 13px; font-weight: 500; padding: 4px 10px; border-radius: 10px; transition: background 0.15s; }
.nav-link:hover { background: rgba(255,255,255,0.1); color: white; }
.main-layout { display: flex; height: 100vh; height: 100dvh; padding-top: var(--topbar-h); overflow: hidden; }
.viewer-panel { flex: 0 0 50%; width: 50%; background: #e8eaed; position: relative; overflow: hidden; border-right: 1px solid var(--gray2); }
.viewer-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--gray1); gap: 12px; }
.placeholder-icon { font-size: 48px; opacity: 0.4; }
.viewer-placeholder p { font-size: 14px; font-weight: 500; }
.viewer-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: none; background: white; }
.resize-handle { flex: 0 0 5px; width: 5px; background: var(--gray2); cursor: col-resize; transition: background 0.15s; position: relative; z-index: 10; }
.resize-handle:hover, .resize-handle.dragging { background: var(--blue); }
.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 300px; background: var(--white); }
.chat-header { padding: 14px 18px; border-bottom: 1px solid var(--gray2); background: var(--white); }
.chat-title { display: flex; align-items: center; gap: 12px; }
.chat-icon { font-size: 22px; }
.chat-name { font-size: 15px; font-weight: 700; color: var(--navy); }
.chat-sub { font-size: 11px; color: var(--gray1); font-weight: 500; }
.messages { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }
.bubble { max-width: 80%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.55; word-break: break-word; }
.message.user .bubble { background: var(--blue); color: white; border-bottom-right-radius: 4px; }
.message.assistant .bubble { background: var(--bg); color: var(--navy); border-bottom-left-radius: 4px; }
.typing-dots { display: flex; gap: 4px; align-items: center; padding: 4px 2px; }
.typing-dots span { display: block; width: 7px; height: 7px; border-radius: 50%; background: var(--gray1); animation: bounce 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-5px); } }
.fix-panel { border-top: 1px solid var(--gray2); background: #f9fafb; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.fix-header { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; color: var(--navy); }
.fix-close { background: none; border: none; cursor: pointer; font-size: 14px; color: var(--gray1); }
.fix-input { width: 100%; padding: 8px 10px; border: 1px solid var(--gray2); border-radius: 8px; font-family: 'Montserrat', sans-serif; font-size: 13px; resize: vertical; min-height: 60px; }
.fix-input:focus { outline: none; border-color: var(--blue); }
.fix-submit { align-self: flex-end; background: var(--green); color: white; border: none; border-radius: var(--radius); padding: 7px 18px; font-family: 'Montserrat', sans-serif; font-size: 13px; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.fix-submit:hover { background: #709a4e; }
.fix-note { font-size: 11px; color: var(--gray1); }
.input-area { border-top: 1px solid var(--gray2); padding: 12px 14px; background: var(--white); }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.user-input { flex: 1; border: 1.5px solid var(--gray2); border-radius: 12px; padding: 10px 14px; font-family: 'Montserrat', sans-serif; font-size: 14px; resize: none; line-height: 1.45; max-height: 130px; overflow-y: auto; transition: border-color 0.15s; }
.user-input:focus { outline: none; border-color: var(--blue); }
.send-btn { flex: 0 0 40px; height: 40px; background: var(--blue); border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; color: white; transition: background 0.15s, transform 0.1s; }
.send-btn:hover { background: var(--darkblue); }
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { background: var(--gray2); cursor: not-allowed; }
.fix-trigger { margin-top: 6px; }
.fix-btn { background: none; border: 1px solid var(--gray2); border-radius: var(--radius); padding: 4px 12px; font-size: 12px; font-family: 'Montserrat', sans-serif; color: var(--gray1); cursor: pointer; transition: border-color 0.15s, color 0.15s; }
.fix-btn:hover { border-color: var(--blue); color: var(--blue); }
body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--navy); }
.login-card { background: white; border-radius: 20px; padding: 48px 40px; max-width: 400px; width: 90%; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 24px; }
.login-walter-badge { background: var(--navy); color: white; font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; padding: 3px 10px; border-radius: 10px; }
.login-title { font-size: 20px; font-weight: 700; color: var(--navy); margin-bottom: 8px; }
.login-sub { font-size: 13px; color: var(--gray1); margin-bottom: 28px; line-height: 1.5; }
.google-btn { display: inline-flex; align-items: center; gap: 10px; background: var(--navy); color: white; text-decoration: none; padding: 12px 24px; border-radius: var(--radius); font-size: 14px; font-weight: 600; transition: background 0.15s; }
.google-btn:hover { background: var(--darkblue); }
.login-domain-note { margin-top: 14px; font-size: 12px; color: var(--gray1); }
.admin-page { max-width: 900px; margin: calc(var(--topbar-h) + 24px) auto 24px; padding: 0 20px; }
.admin-section { background: white; border-radius: 16px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.admin-section h2 { font-size: 16px; font-weight: 700; color: var(--navy); margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--gray2); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; padding: 8px 10px; background: var(--bg); color: var(--gray1); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.admin-table td { padding: 10px; border-top: 1px solid var(--gray2); vertical-align: top; }
.admin-table tr:hover td { background: #fafbfc; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-approved { background: #e8f4e8; color: #4a7c4a; }
.badge-pending { background: #fff3cd; color: #856404; }
.badge-viewer { background: #e8eef4; color: #4a6c8a; }
.badge-contributor { background: #e8f4ff; color: #1b4e66; }
.badge-moderator { background: #f0e8ff; color: #5a3080; }
.badge-admin { background: #ffe8e8; color: #8a1a1a; }
.btn { display: inline-block; padding: 6px 14px; border-radius: var(--radius); font-size: 12px; font-weight: 600; font-family: 'Montserrat', sans-serif; border: none; cursor: pointer; transition: opacity 0.15s; text-decoration: none; }
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--blue); color: white; }
.btn-success { background: var(--green); color: white; }
.btn-danger { background: #dc3545; color: white; }
.btn-secondary { background: var(--gray2); color: var(--navy); }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--navy); margin-bottom: 5px; }
.form-control { width: 100%; padding: 9px 12px; border: 1.5px solid var(--gray2); border-radius: 8px; font-family: 'Montserrat', sans-serif; font-size: 13px; }
.form-control:focus { outline: none; border-color: var(--blue); }
select.form-control { cursor: pointer; }
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--gray2); }
.tab-btn { background: none; border: none; padding: 8px 16px; font-family: 'Montserrat', sans-serif; font-size: 13px; font-weight: 600; color: var(--gray1); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color 0.15s; }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--navy); color: white; padding: 12px 20px; border-radius: 12px; font-size: 13px; font-weight: 600; z-index: 999; box-shadow: 0 4px 16px rgba(0,0,0,0.2); opacity: 0; transform: translateY(10px); transition: opacity 0.2s, transform 0.2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--green); }
.toast.error { background: #dc3545; }

/* Markdown rendering in chat bubbles */
.bubble p { margin: 0 0 8px 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul.md-list { margin: 8px 0; padding-left: 20px; list-style: disc; }
.bubble ul.md-list li { margin: 4px 0; line-height: 1.5; }
.bubble strong { font-weight: 600; }
.bubble code { background: rgba(0,0,0,0.08); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

/* Technical term links */
.term-link { color: var(--blue); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; cursor: pointer; font-weight: 500; transition: color 0.15s; }
.term-link:hover { color: var(--darkblue); text-decoration-style: solid; }

/* Version badge */
.walter-version { color: var(--gray1); font-size: 10px; font-weight: 500; opacity: 0.7; }

/* ── Mobile responsive ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topbar { padding: 0 12px; }
  .logo { height: 22px; }
  .walter-label { font-size: 11px; padding-left: 8px; }
  .walter-version { font-size: 9px; }
  .topbar-right { gap: 6px; }
  .nav-link { font-size: 11px; padding: 3px 8px; }
  .user-name { display: none; }

  body.chat-page {
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  .main-layout {
    flex-direction: column;
    height: 100%;
    padding-top: var(--topbar-h);
    overflow: hidden;
  }

  /* Hide viewer panel on mobile — not usable on small screens */
  .viewer-panel { display: none; }
  .resize-handle { display: none; }

  .chat-panel {
    flex: 1;
    min-width: unset;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    min-height: 0;
  }

  .chat-header { padding: 10px 14px; flex-shrink: 0; }
  .chat-name { font-size: 14px; }
  .chat-sub { font-size: 10px; }
  .bubble { max-width: 90%; font-size: 13px; padding: 8px 12px; }

  .input-area {
    padding: 8px 10px;
    flex-shrink: 0;
    background: var(--white);
    border-top: 1px solid var(--gray2);
  }

  /* Prevent iOS zoom on input focus (font-size >= 16px) */
  .user-input { font-size: 16px; padding: 8px 12px; }

  .fix-panel { padding: 8px 12px; flex-shrink: 0; }
  .fix-input { font-size: 16px; min-height: 48px; }
}

/* Extra small screens */
@media (max-width: 480px) {
  .topbar-left { gap: 6px; }
  .avatar { width: 24px; height: 24px; }
}

/* ── KB article images ─────────────────────────────────────────────── */
.kb-images {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.kb-image {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  transition: opacity .15s, transform .15s;
  display: block;
}
.kb-image:hover {
  opacity: .9;
  transform: scale(1.01);
}

/* ── Chat hyperlinks ───────────────────────────────────────────────── */
.bubble .chat-link {
  color: var(--accent, #2563eb);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
  cursor: pointer;
}
.bubble .chat-link:hover { opacity: .8; }

/* ── Vote buttons ──────────────────────────────────────────────────── */
.vote-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,.08);
}
.vote-label {
  font-size: 12px;
  color: #64748b;
}
.vote-label.voted {
  color: var(--accent, #2563eb);
  font-weight: 600;
}
.vote-btn {
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  line-height: 1.4;
}
.vote-btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.vote-btn.up:hover  { background: #ecfdf5; border-color: #34d399; }
.vote-btn.down:hover { background: #fef2f2; border-color: #f87171; }
