/* G2WOA Feedback Portal — mobile-first styles. No horizontal scroll at 360px. */

:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1a2330;
  --text-dim: #66707e;
  --border: #dde3ea;
  --accent: #0f4c81;
  --accent-contrast: #ffffff;
  --good: #1e9e5a;
  --good-bg: #e2f5ea;
  --bad: #d64545;
  --bad-bg: #fdeaea;
  --warn-bg: #fff4d6;
  --warn-text: #7a5b00;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 14px;
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #1a212b;
    --surface-2: #232c38;
    --text: #e7ecf2;
    --text-dim: #93a0af;
    --border: #2e3946;
    --accent: #5b9bd5;
    --accent-contrast: #0d1117;
    --good: #38c47b;
    --good-bg: #17301f;
    --bad: #ef6a6a;
    --bad-bg: #34191b;
    --warn-bg: #3a2f10;
    --warn-text: #ffd97a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

input, textarea, select { font: inherit; color: var(--text); }

a { color: var(--accent); }

/* word-wrap discipline: long URLs/handles must never widen the page */
.card, .bubble, .activity-row, .detail-pre, .post-link {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ============ login ============ */

#loginView {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
}

.login-lang { display: flex; justify-content: flex-end; }

.login-logo {
  width: 64px; height: 64px;
  margin: 6px auto 14px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 800;
  font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0.5px;
}

.login-box h1 { font-size: 22px; margin: 0 0 8px; }
.login-intro { color: var(--text-dim); font-size: 14px; margin: 0 0 20px; }

#loginForm { display: flex; flex-direction: column; gap: 12px; }

#loginEmail {
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  width: 100%;
}
#loginEmail:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

#loginSubmit {
  height: 48px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
#loginSubmit:disabled { opacity: 0.6; }

.login-msg { color: var(--good); font-size: 14px; margin: 16px 0 0; }
.login-err { color: var(--bad); font-size: 14px; margin: 16px 0 0; }

/* ============ app shell ============ */

#appView {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-title {
  font-weight: 700;
  font-size: 17px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company-select {
  max-width: 130px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 0 6px;
}

.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex: none;
}
.lang-toggle button {
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  min-height: 36px;
}
.lang-toggle button.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.logout-btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
  flex: none;
}

.banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.app-main {
  flex: 1;
  padding: 12px 12px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

body.chat-open .app-main {
  /* leave room for the chat input bar above the tabbar */
  padding-bottom: calc(var(--tabbar-h) + 78px + env(safe-area-inset-bottom));
}

.list-status {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 16px 0;
}

.retry-btn {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  padding: 8px;
  min-height: 44px;
}

.sentinel { height: 1px; }

/* ============ feed ============ */

.feed-controls {
  position: sticky;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 10;
  background: var(--bg);
  padding: 2px 0 8px;
}

.search-input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0 14px;
  margin-bottom: 8px;
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 0 14px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.feed-list { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.platform-badge {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.card-author { flex: 1; min-width: 0; }
.author-name { font-weight: 600; font-size: 15px; }
.author-handle { color: var(--text-dim); font-size: 13px; }

.class-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  margin-top: 2px;
}

.sent-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex: none;
}
.sent-m2 { background: #b91c1c; }
.sent-m1 { background: #f97316; }
.sent-0  { background: #9ca3af; }
.sent-p1 { background: #84cc16; }
.sent-p2 { background: #16a34a; }
.sent-none { background: transparent; border: 1.5px dashed var(--text-dim); }

.card-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--text-dim);
  font-size: 13px;
  margin: 8px 0 6px;
  flex-wrap: wrap;
}
.group-name { font-weight: 500; }
.card-meta .time::before { content: "·"; margin-right: 8px; }
.card-meta .group-name + .time::before { content: "·"; }
.card-meta .time:first-child::before { content: ""; margin: 0; }

.card-text {
  white-space: pre-wrap;
  font-size: 15px;
}
.card-text.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.expander {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 0;
  min-height: 32px;
}

.post-link {
  display: inline-block;
  font-size: 13px;
  margin-top: 4px;
  padding: 4px 0;
  text-decoration: none;
}
.post-link:hover { text-decoration: underline; }

.vote-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.vote-btn {
  flex: 1 1 50%;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.vote-count { font-size: 13px; font-weight: 500; color: var(--text-dim); }

.vote-rel.selected { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.vote-irr.selected { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.vote-rel.selected .vote-count { color: var(--good); }
.vote-irr.selected .vote-count { color: var(--bad); }

.card-foot { margin-top: 8px; }

.comment-toggle {
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 8px 8px 0;
  min-height: 44px;
}
.comment-toggle.has-comment { color: var(--accent); font-weight: 600; }

.comment-box {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.comment-area {
  flex: 1 1 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 10px 12px;
  resize: vertical;
  min-height: 44px;
}

.comment-save {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

.comment-hint {
  flex: 1 1 100%;
  color: var(--bad);
  font-size: 13px;
}

/* ============ chat ============ */

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble-row { display: flex; flex-direction: column; max-width: 85%; }
.bubble-row.from-user { align-self: flex-end; align-items: flex-end; }
.bubble-row.from-assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
}
.from-user .bubble {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  border-bottom-right-radius: 6px;
}
.from-assistant .bubble { border-bottom-left-radius: 6px; }

.bubble code {
  background: var(--surface-2);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.from-user .bubble code { background: rgba(255, 255, 255, 0.2); }

.bubble-error {
  background: var(--bad-bg);
  border-color: var(--bad);
  color: var(--bad);
}

.bubble-time {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
  padding: 0 4px;
}

.bubble-typing { display: flex; align-items: center; gap: 8px; }
.typing-text { color: var(--text-dim); font-size: 13px; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.chat-input-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 640px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 25;
}

#chatText {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 10px 12px;
  resize: none;
}
#chatText:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

#chatSendBtn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  flex: none;
}
#chatSendBtn:disabled { opacity: 0.6; }

/* ============ activity ============ */

.activity-list { display: flex; flex-direction: column; gap: 10px; }

.activity-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.activity-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 14px;
  text-align: left;
  min-height: 48px;
}

.activity-icon { font-size: 20px; flex: none; margin-top: 2px; }
.activity-main { flex: 1; min-width: 0; }

.activity-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.activity-kind { font-weight: 600; font-size: 15px; }

.status-chip {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.status-done { background: var(--good-bg); color: var(--good); }
.status-error { background: var(--bad-bg); color: var(--bad); }
.status-running { background: var(--warn-bg); color: var(--warn-text); }
.status-queued { background: var(--surface-2); color: var(--text-dim); }

.activity-summary {
  font-size: 14px;
  color: var(--text);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.activity-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.activity-detail {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  background: var(--surface-2);
}

.detail-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  margin: 8px 0 4px;
}
.detail-label:first-child { margin-top: 0; }

.detail-pre {
  margin: 0;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
}
.detail-error { color: var(--bad); }

/* ============ tab bar ============ */

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 640px;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar-h);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
}
.tab .tab-icon { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ============ toast ============ */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  max-width: min(92vw, 480px);
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 50;
  font-size: 14px;
}

.toast-action {
  color: #7cc4ff;
  font-weight: 700;
  min-height: 44px;
  padding: 0 6px;
  flex: none;
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.4px;
}

/* ============ desktop ============ */

@media (min-width: 700px) {
  .app-main { padding-left: 0; padding-right: 0; }
  #appView { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
