/* ClawdBot Mail — mobile-first, style proche Mail / iMessage iOS */
:root {
  --ios-blue: #007aff;
  --ios-gray: #8e8e93;
  --ios-bg: #ffffff;
  --ios-sep: rgba(60, 60, 67, 0.18);
  --bubble-me: #007aff;
  --bubble-bot: #e9e9eb;
  --cherry: #c41230;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  background: var(--ios-bg);
  color: #000;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100dvh;
  padding-bottom: var(--safe-bottom);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 0.5px solid var(--ios-sep);
  padding: 8px 12px 10px;
}

.app-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}

.search-wrap {
  padding: 0 4px;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  background: #f2f2f7;
  font-size: 1rem;
}

.mail-main {
  position: relative;
}

.view.hidden {
  display: none !important;
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.conv-item {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--ios-sep);
  touch-action: pan-y;
  user-select: none;
  position: relative;
  background: #fff;
  transition: transform 0.15s ease-out, background 0.15s;
}

.conv-item:active {
  background: #f2f2f7;
}

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c41230, #ff6b6b);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  flex-shrink: 0;
}

.conv-body {
  flex: 1;
  min-width: 0;
}

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.conv-from {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 0.8rem;
  color: var(--ios-gray);
  flex-shrink: 0;
}

.conv-subject {
  font-size: 0.95rem;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-snippet {
  font-size: 0.85rem;
  color: var(--ios-gray);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.conv-inbox-tag {
  font-size: 0.65rem;
  color: var(--cherry);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-toolbar {
  padding: 8px 12px;
  border-bottom: 0.5px solid var(--ios-sep);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 5;
}

.btn-text {
  border: none;
  background: none;
  color: var(--ios-blue);
  font-size: 1rem;
  padding: 8px 0;
  cursor: pointer;
}

.detail-meta {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--ios-sep);
  font-size: 0.9rem;
  color: var(--ios-gray);
}

.thread-bubbles {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 120px;
}

.detail-empty {
  margin: 0;
  color: var(--ios-gray);
  font-size: 0.95rem;
  text-align: center;
  padding: 24px 16px;
}

.bubble-row {
  display: flex;
  width: 100%;
}

.bubble-row.inbound {
  justify-content: flex-start;
}

.bubble-row.outbound {
  justify-content: flex-end;
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.inbound {
  background: var(--bubble-bot);
  color: #000;
  border-bottom-left-radius: 4px;
}

.bubble.outbound {
  background: var(--bubble-me);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble-meta {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-top: 4px;
}

.composer-mail {
  padding: 12px 16px 24px;
  border-top: 0.5px solid var(--ios-sep);
  background: #f2f2f7;
}

.reply-draft {
  width: 100%;
  border-radius: 10px;
  border: 0.5px solid var(--ios-sep);
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
}

.composer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.btn-primary {
  flex: 1;
  min-width: 140px;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  background: var(--cherry);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-send {
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  background: var(--ios-blue);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.fab-compose {
  position: fixed;
  right: 20px;
  bottom: calc(24px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--ios-blue);
  color: #fff;
  font-size: 1.4rem;
  box-shadow: 0 4px 16px rgba(0, 122, 255, 0.35);
  z-index: 30;
  cursor: pointer;
}

.chat-section {
  margin-top: 32px;
  padding: 16px 12px calc(24px + var(--safe-bottom));
  background: #fff;
  border-top: 8px solid #f2f2f7;
  min-height: 50vh;
}

.chat-heading {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ios-gray);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 45vh;
  overflow-y: auto;
  padding-bottom: 12px;
}

.chat-bubble-row {
  display: flex;
}

.chat-bubble-row.user {
  justify-content: flex-end;
}

.chat-bubble-row.bot {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.user {
  background: var(--bubble-me);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.bot {
  background: var(--bubble-bot);
  color: #000;
  border-bottom-left-radius: 4px;
}

.chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 0 0;
  border-top: 0.5px solid var(--ios-sep);
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 0.5px solid var(--ios-sep);
  font-size: 1rem;
}

.chat-send {
  padding: 10px 16px;
  border-radius: 20px;
  border: none;
  background: var(--ios-blue);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.swipe-hint {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.conv-item.swiping-left .swipe-hint.archive {
  opacity: 1;
  background: #ff9500;
  left: auto;
}

.conv-item.swiping-right .swipe-hint.read {
  opacity: 1;
  background: var(--ios-blue);
  right: auto;
  left: 0;
}

@media (min-width: 768px) {
  .mail-main {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    min-height: calc(100dvh - 120px);
  }

  .view-list {
    border-right: 0.5px solid var(--ios-sep);
  }

  .fab-compose {
    bottom: auto;
    top: 100px;
  }
}
