:root {
  --bg: #0a0a0a;
  --bg2: #121212;
  --bg3: #1a1a1a;
  --accent: #ff2d55;
  --accent2: #ff6b9d;
  --text: #f0f0f0;
  --text-dim: #aaa;
  --border: #2a2a2a;
  --user-bubble: #2a1520;
  --ai-bubble: #1a1a1a;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

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

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

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

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

.header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent2);
}

.status {
  font-size: 0.7rem;
  color: #4ade80;
}

.header-right {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: var(--bg3);
}

/* Sidebar */
.sidebar {
  position: absolute;
  top: 57px;
  left: 0;
  width: 260px;
  height: calc(100% - 57px);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  z-index: 30;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.sidebar:not(.hidden) {
  transform: translateX(0);
}

.sidebar-content {
  padding: 16px;
}

.sidebar h2 {
  font-size: 0.9rem;
  color: var(--accent2);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.side-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg3);
  border: none;
  color: var(--text);
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 12px;
  font-size: 0.95rem;
  cursor: pointer;
}

.side-btn:active {
  background: var(--accent);
}

.side-info {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.4;
  margin-top: 12px;
}

.side-info code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}

/* Chat */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 0.95rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  color: #ffd6e0;
}

.message.ai {
  align-self: flex-start;
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.ai .name {
  font-size: 0.75rem;
  color: var(--accent2);
  margin-bottom: 4px;
  font-weight: 600;
}

.message img {
  max-width: 100%;
  border-radius: 12px;
  margin-top: 8px;
  display: block;
}

.message a {
  color: var(--accent2);
  text-decoration: underline;
}

.typing {
  align-self: flex-start;
  padding: 12px 18px;
  background: var(--ai-bubble);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* Input bar */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#user-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 22px;
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  resize: none;
  max-height: 120px;
  outline: none;
  font-family: inherit;
}

#user-input:focus {
  border-color: var(--accent);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Image panel */
.img-panel {
  position: absolute;
  bottom: 70px;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 14px;
  z-index: 25;
  max-height: 55%;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
}

.img-panel.hidden {
  display: none;
}

.img-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.img-panel-header h3 {
  color: var(--accent2);
  font-size: 1rem;
}

.img-controls select,
.img-controls textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
  margin-bottom: 10px;
  font-family: inherit;
}

.img-controls textarea {
  resize: vertical;
}

.img-actions {
  display: flex;
  gap: 10px;
}

.primary-btn, .secondary-btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

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

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

.img-result {
  margin-top: 14px;
  text-align: center;
}

.img-result img {
  max-width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.img-result .error {
  color: #ff6b6b;
  font-size: 0.9rem;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg2);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  border-radius: 20px 20px 0 0;
  padding: 16px;
  overflow-y: auto;
}

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

.modal-header h3 {
  color: var(--accent2);
}

.settings label {
  display: block;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.settings input,
.settings select {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
}

.settings .hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 12px;
  line-height: 1.4;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.gallery-grid img {
  width: 100%;
  border-radius: 12px;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* Utilities */
.hidden {
  display: none !important;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

/* Mobile polish */
@media (max-width: 480px) {
  .message {
    max-width: 92%;
  }
}
