:root {
  --bg-main: #0b0e14;
  --bg-surface: #121721;
  --bg-card: #182030;
  --bg-input: #1a2334;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 7, 11, 0.5);
  --primary-red: #FF070B;
  --primary-gradient: linear-gradient(135deg, #FF070B 0%, #b91c1c 100%);
  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --safe-bottom: env(safe-area-inset-bottom, 12px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
}

#app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg-main);
}

/* Header */
.pwa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px 14px;
  background: rgba(18, 23, 33, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  z-index: 20;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mascot-img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 7, 11, 0.4);
  object-fit: cover;
  background: #000;
}

.header-info h1 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: #fff;
  line-height: 1.2;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #f59e0b; /* default pending */
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
  transition: all 0.3s ease;
}

.status-dot.online {
  background-color: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.status-dot.offline {
  background-color: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.1);
}

#btn-pwa-install {
  color: var(--primary);
  border-color: rgba(255, 7, 11, 0.35);
  background: rgba(255, 7, 11, 0.1);
}

#btn-pwa-install:hover {
  background: rgba(255, 7, 11, 0.2);
}

/* Chat Messages */
.pwa-chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  user-select: text;
}

.chat-bubble {
  max-width: 86%;
  padding: 12px 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  word-break: break-word;
  animation: fadeIn 0.2s ease forwards;
}

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

.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary-gradient);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 3px 12px rgba(255, 7, 11, 0.25);
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 18px 18px 18px 4px;
}

.chat-bubble.assistant strong {
  color: #fff;
}

.exec-result-card {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 6px 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
}

.inline-code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: #38bdf8;
  font-weight: 600;
}

.chat-bubble.assistant pre {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.82rem;
  margin: 6px 0;
  font-family: monospace;
}

.chat-bubble.assistant code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: monospace;
}

.chat-bubble.assistant table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 8px 0;
}

.chat-bubble.assistant th,
.chat-bubble.assistant td {
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4px 8px;
  text-align: left;
}

.chat-bubble.assistant th {
  background: rgba(255, 255, 255, 0.05);
}

.msg-time {
  display: block;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 4px;
  text-align: right;
}

/* Thinking Indicator */
.thinking-bubble {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px 18px 18px 4px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.84rem;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 5px;
  height: 5px;
  background-color: var(--primary-red);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* Quick Action Chips */
.quick-chips-wrapper {
  padding: 4px 10px 8px 10px;
  overflow-x: auto;
  white-space: nowrap;
  display: flex;
  gap: 8px;
  scrollbar-width: none;
}
.quick-chips-wrapper::-webkit-scrollbar {
  display: none;
}

.quick-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.78rem;
  padding: 5px 12px;
  border-radius: 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.quick-chip:active {
  background: var(--primary-red);
  color: #fff;
  border-color: var(--primary-red);
  transform: scale(0.96);
}

/* Input Bar */
.pwa-input-container {
  background: rgba(18, 23, 33, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  padding: 8px 12px calc(8px + var(--safe-bottom)) 12px;
  z-index: 20;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s ease;
}

.input-row:focus-within {
  border-color: var(--primary-red);
  box-shadow: 0 0 0 2px rgba(255, 7, 11, 0.15);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 0.94rem;
  padding: 6px 0;
  max-height: 100px;
  resize: none;
  font-family: inherit;
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.btn-mic {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.15rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.btn-mic.listening {
  color: #fff;
  background: #FF070B;
  animation: pulseMic 1.2s infinite ease-in-out;
}

@keyframes pulseMic {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 7, 11, 0.7); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(255, 7, 11, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 7, 11, 0); }
}

.btn-send {
  background: var(--primary-gradient);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(255, 7, 11, 0.35);
  transition: all 0.2s ease;
}

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

/* Modal Settings */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  padding: 20px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.1rem;
  color: #fff;
}

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

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  color: #fff;
  outline: none;
}

.form-input:focus {
  border-color: var(--primary-red);
}

.modal-footer {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.btn-save {
  flex: 1;
  background: var(--primary-gradient);
  border: none;
  color: #fff;
  padding: 10px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-cancel {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}
