:root {
  --bg-primary: #0a1f14;
  --bg-secondary: #142e1f;
  --bg-chat: #0f2419;
  --bg-card: #1a3328;
  --accent: #2d8f5f;
  --accent-light: #45b87a;
  --accent-glow: rgba(45, 143, 95, 0.25);
  --text-primary: #f0f7f3;
  --text-secondary: #9bb8a8;
  --user-bubble: #1e6b42;
  --user-bubble-text: #ffffff;
  --bot-bubble: #1a2e24;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --radius-sm: 12px;
  --header-h: 72px;
  --input-h: 88px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --app-max-w: 100%;
  --touch-min: 44px;
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

html, body {
  overflow: hidden;
}

body {
  font-family: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  min-height: 100dvh;
}

/* Background decor */
.page-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(45, 143, 95, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(45, 143, 95, 0.08), transparent),
    var(--bg-primary);
  pointer-events: none;
  z-index: 0;
}

.page-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%232d8f5f' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  opacity: 0.6;
}

/* App shell - responsive container */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--app-max-w);
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg-chat);
  position: relative;
  overflow: hidden;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  padding-top: calc(14px + var(--safe-top) * 0);
  background: linear-gradient(180deg, var(--bg-secondary) 0%, rgba(20, 46, 31, 0.95) 100%);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.avatar {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.brand-mark {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  box-shadow: none;
}

.avatar-user {
  background: #3a4f44;
  color: var(--text-secondary);
}

.header-info {
  min-width: 0;
}

.header-info h1 {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: var(--accent-light);
  margin-top: 4px;
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: var(--accent-light);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.status.offline {
  color: #e74c3c;
}

.status.offline .status-dot {
  background: #e74c3c;
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.9); }
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  width: var(--touch-min);
  height: var(--touch-min);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:active {
  transform: scale(0.95);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: rgba(45, 143, 95, 0.4);
}

/* Chat Area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Welcome - Gemini style */
.welcome {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  padding: 24px 8px 32px;
  animation: fadeIn 0.4s ease;
}

.welcome-gemini {
  width: 100%;
  max-width: 680px;
  text-align: center;
}

.welcome-greeting {
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  font-weight: 400;
  line-height: 1.25;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.welcome-sub {
  font-size: clamp(1rem, 3vw, 1.125rem);
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 32px;
  font-weight: 400;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 560px;
  margin: 0 auto;
}

.suggestion-chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: 24px;
  font-size: 0.875rem;
  font-weight: 400;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  text-align: left;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

.suggestion-chip:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
}

.suggestion-chip:active {
  background: rgba(45, 143, 95, 0.12);
  border-color: rgba(45, 143, 95, 0.35);
}

/* Messages */
.message {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  animation: slideUp 0.35s ease;
  align-items: flex-end;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  flex-shrink: 0;
  margin-bottom: 4px;
}

.message-body {
  display: flex;
  flex-direction: column;
  max-width: min(85%, 320px);
}

.message.user .message-body {
  align-items: flex-end;
}

.message.bot .message-body {
  align-items: flex-start;
}

.message-sender {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 4px;
  padding-left: 4px;
}

.message.user .message-sender {
  display: none;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.925rem;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: linear-gradient(135deg, var(--user-bubble), #25855a);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(30, 107, 66, 0.3);
}

.message.bot .message-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
}

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

.message-time {
  font-size: 0.65rem;
  color: var(--text-secondary);
  margin-top: 4px;
  padding: 0 4px;
  opacity: 0.7;
}

.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 6px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Input Area */
.input-area {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(0deg, var(--bg-secondary) 0%, rgba(20, 46, 31, 0.98) 100%);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 8px 8px 8px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-form:focus-within {
  border-color: rgba(45, 143, 95, 0.5);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.45;
  padding: 10px 0;
  outline: none;
  min-height: 24px;
}

#message-input::placeholder {
  color: var(--text-secondary);
}

.btn-send {
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-send:disabled {
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-send:not(:disabled):active {
  transform: scale(0.92);
}

.btn-send:not(:disabled):hover {
  background: var(--accent-light);
}

.powered {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-secondary);
  margin-top: 10px;
  opacity: 0.55;
  letter-spacing: 0.02em;
}

/* Scroll to bottom */
.btn-scroll-bottom {
  position: absolute;
  bottom: calc(var(--input-h) + 16px + var(--safe-bottom));
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  z-index: 10;
  transition: transform 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-scroll-bottom:active {
  transform: scale(0.9);
}

/* Scrollbar */
.chat-area::-webkit-scrollbar {
  width: 5px;
}

.chat-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Small phones (< 360px) */
@media (max-width: 359px) {
  .suggestions {
    flex-direction: column;
    align-items: stretch;
  }

  .suggestion-chip {
    text-align: center;
  }

  .header-info h1 {
    font-size: 0.95rem;
  }
}

/* Phones (360px - 480px) */
@media (min-width: 360px) and (max-width: 480px) {
  .message-body {
    max-width: 88%;
  }
}

/* Large phones / small tablets (481px+) */
@media (min-width: 481px) {
  :root {
    --app-max-w: 440px;
  }

  .app-shell {
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .app {
    height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom));
    max-height: 860px;
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  .header {
    border-radius: 20px 20px 0 0;
  }
}

/* Tablets (768px+) */
@media (min-width: 768px) {
  :root {
    --app-max-w: 480px;
  }

  .welcome-gemini {
    max-width: 440px;
  }

  .suggestion-chip {
    font-size: 0.9rem;
    padding: 13px 20px;
  }

  .message-body {
    max-width: min(80%, 360px);
  }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  :root {
    --app-max-w: 520px;
  }

  .app {
    max-height: 900px;
  }

  .welcome-greeting {
    font-size: 2.25rem;
  }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
  .welcome {
    min-height: auto;
    padding: 12px 8px 16px;
    justify-content: flex-start;
  }

  .welcome-greeting {
    font-size: 1.35rem;
    margin-bottom: 6px;
  }

  .welcome-sub {
    font-size: 0.9rem;
    margin-bottom: 16px;
  }

  .suggestions {
    gap: 8px;
  }

  .suggestion-chip {
    padding: 8px 14px;
    font-size: 0.8rem;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== SETTINGS PAGE ===== */
.settings-app .header {
  gap: 12px;
}

.settings-app .header-info h1 {
  font-size: 1.05rem;
  font-weight: 700;
}

.settings-app .header-info .status {
  margin-top: 2px;
}

.header-spacer {
  width: var(--touch-min);
  flex-shrink: 0;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.form-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.form-section h2 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 16px;
  letter-spacing: 0.02em;
}

.form-group {
  margin-bottom: 14px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: var(--touch-min);
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group small {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.4;
}

.form-group small a {
  color: var(--accent-light);
}

.status-item {
  margin-top: 12px;
}

.status-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 12px;
}

.status-badge.pending {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.status-badge.success {
  background: rgba(45, 143, 95, 0.2);
  color: var(--accent-light);
}

.status-badge.error {
  background: rgba(231, 76, 60, 0.2);
  color: #e74c3c;
}

.form-actions {
  display: flex;
  gap: 12px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(0deg, var(--bg-chat) 70%, transparent);
  padding: 8px 0 4px;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  min-height: var(--touch-min);
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:hover {
  background: var(--accent-light);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-card);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.alert {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  text-align: center;
  font-weight: 500;
}

.alert-success {
  background: rgba(45, 143, 95, 0.2);
  color: var(--accent-light);
  border: 1px solid var(--accent);
}

.alert-error {
  background: rgba(231, 76, 60, 0.15);
  color: #e74c3c;
  border: 1px solid #e74c3c;
}

.form-check {
  margin-bottom: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-primary);
  cursor: pointer;
  min-height: var(--touch-min);
}

.checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.webhook-url-box {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.webhook-url-box input {
  flex: 1;
  min-width: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-family: monospace;
  padding: 12px 14px;
}

.btn-copy {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0 18px;
  cursor: pointer;
  white-space: nowrap;
  min-height: var(--touch-min);
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-copy:active {
  transform: scale(0.98);
}

.btn-copy:hover {
  background: var(--accent-light);
}

@media (min-width: 481px) {
  .settings-app.app {
    max-width: 600px;
  }

  .form-actions {
    position: static;
    background: none;
    padding: 0;
  }
}

@media (max-width: 480px) {
  .webhook-url-box {
    flex-direction: column;
  }

  .btn-copy {
    width: 100%;
  }

  .form-actions {
    flex-direction: column-reverse;
  }
}
