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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2e2e2e;
  --accent: #00d4ff;
  --accent2: #7c3aed;
  --text: #e8e8e8;
  --text-dim: #888;
  --user-bubble: #1e3a4a;
  --ai-bubble: #1e1e2e;
  --danger: #ef4444;
  --canvas-bg: #111;
  --grid: #1e1e1e;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
}

/* HEADER */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}
#header h1 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .08em;
  line-height: 1;
}
.logo-laser {
  color: var(--accent);
  letter-spacing: .12em;
}
.logo-ai {
  color: #fff;
  font-weight: 400;
  letter-spacing: .18em;
  font-size: 13px;
  opacity: .9;
}
#header .meta {
  font-size: 11px;
  color: var(--text-dim);
}
#btn-clear-drawing {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
}
#btn-clear-drawing:active { opacity: .7; }

/* PREVIEW */
#preview-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--canvas-bg);
  overflow: hidden;
}
#preview-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
#preview-label {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-dim);
  pointer-events: none;
  background: rgba(0,0,0,.5);
  padding: 2px 8px;
  border-radius: 10px;
}
#shape-count {
  position: absolute;
  bottom: 8px;
  right: 10px;
  font-size: 11px;
  color: var(--text-dim);
  pointer-events: none;
}
#btn-download {
  position: absolute;
  bottom: 8px;
  left: 10px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: none;
}
#btn-download.visible { display: block; }
#btn-download:active { opacity: .8; }

/* CHAT */
#chat-wrap {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 45dvh;
}
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 80px;
  max-height: 30dvh;
  scroll-behavior: smooth;
}
.msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.msg.ai {
  align-self: flex-start;
  background: var(--ai-bubble);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.msg.system {
  align-self: center;
  font-size: 12px;
  color: var(--text-dim);
  background: transparent;
  padding: 2px 0;
}
.msg-photo {
  align-self: flex-end;
  max-width: 130px;
}
.msg-photo img {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}
.msg-photo .photo-caption {
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
  margin-top: 3px;
}

/* INPUT BAR */
#input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
}
#user-input {
  flex: 1;
  background: #111;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 16px; /* ≥16px zapobiega auto-zoom iOS Safari */
  resize: none;
  outline: none;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
}
#user-input:focus { border-color: var(--accent); }
#user-input::placeholder { color: var(--text-dim); }

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .1s;
}
.icon-btn:active { transform: scale(.9); }

#btn-camera {
  background: var(--border);
  color: var(--text);
}
#btn-mic {
  background: var(--border);
  color: var(--text);
}
#btn-mic.recording {
  background: var(--danger);
  animation: pulse 1s infinite;
}
#btn-send {
  background: var(--accent);
  color: #000;
}
#btn-send:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: default;
}

@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.4); }
  50%      { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* THINKING INDICATOR */
.thinking { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.thinking span {
  width: 7px; height: 7px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: bounce .9s infinite;
}
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); }
  40%          { transform: translateY(-6px); }
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
