:root {
  color-scheme: dark;
  --bg: #0e100e;
  --text: #f2f1eb;
  --muted: #8c9087;
  --line: #292c27;
  --surface: #191c18;
  --accent: #e8b85b;
  --danger: #e07770;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button, textarea, input { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }

.app {
  width: min(100%, 860px);
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 22px env(safe-area-inset-bottom);
}

.topbar {
  position: relative;
  z-index: 7;
  flex: 0 0 auto;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(14, 16, 14, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.identity,
.view-toggle {
  border: 0;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: 16px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.online { background: #74bd82; }
.status-dot.offline { background: var(--danger); }

.view-toggle {
  padding: 10px 0 10px 18px;
  color: var(--accent);
}

main {
  flex: 1 1 auto;
  min-height: 0;
}

.view { display: none; }
.view.active {
  height: 100%;
  display: block;
}

.messages {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  padding: 42px 0 calc(120px + env(safe-area-inset-bottom));
  scrollbar-width: none;
}

.messages::-webkit-scrollbar { display: none; }

.welcome {
  margin: auto;
  padding: min(24vh, 190px) 0 50px;
  text-align: center;
  color: var(--muted);
}

.welcome h1 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: clamp(42px, 12vw, 72px);
  font-weight: 560;
  letter-spacing: -.06em;
}

.welcome p { margin: 0; }

.message {
  max-width: 76%;
  line-height: 1.55;
  white-space: pre-wrap;
  animation: message-in .2s ease both;
}

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

.message.assistant {
  align-self: flex-start;
  padding-left: 16px;
  border-left: 2px solid var(--accent);
}

.message.capture.processing {
  color: var(--muted);
  border-left-color: var(--muted);
}

.message.capture.processing::before {
  color: var(--muted);
}

.message.capture.processing::after {
  content: "";
  display: inline-block;
  width: 18px;
  margin-left: 4px;
  overflow: hidden;
  vertical-align: bottom;
  animation: pending-dots 1.2s steps(4, end) infinite;
}

@keyframes pending-dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75%, 100% { content: "..."; }
}

.message.assistant::before {
  content: "Луна";
  display: block;
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.capture-thumb {
  width: min(210px, 58vw);
  max-height: 210px;
  display: block;
  margin: 0 0 10px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface);
}

.message.user {
  align-self: flex-end;
  padding: 12px 15px;
  color: #201b12;
  background: var(--accent);
  border-radius: 16px 16px 3px 16px;
}

.jobs-panel {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  width: min(calc(100% - 44px), 816px);
  transform: translateX(-50%);
}

.jobs-panel:empty { display: none; }

.job-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 14px;
  color: var(--muted);
  background: rgba(25, 28, 24, .97);
  border: 1px solid var(--line);
}

.job-notice b {
  display: block;
  margin-bottom: 2px;
  color: var(--text);
  font-size: 13px;
}

.approve-button {
  flex: 0 0 auto;
  border: 0;
  padding: 8px 11px;
  color: #201b12;
  background: var(--accent);
}

.composer {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(calc(100% - 32px), 828px);
  transform: translateX(-50%);
  padding: 8px;
  background: rgba(25, 28, 24, .96);
  border: 1px solid #343831;
  border-radius: 18px;
  backdrop-filter: blur(18px);
}

.composer-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: end;
  gap: 3px;
}

.attach-button,
.send-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.attach-button {
  color: var(--muted);
  background: transparent;
  font-size: 25px;
}

.attach-button input { display: none; }

.send-button {
  color: #201b12;
  background: var(--accent);
  font-size: 22px;
}

.composer textarea {
  min-height: 44px;
  max-height: 130px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 11px 8px 8px;
  color: var(--text);
  background: transparent;
}

.attachment-tray {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.attachment-tray:empty { display: none; }

.attachment-chip {
  flex: 0 0 auto;
  max-width: 210px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 1px 0 7px;
  padding: 7px 9px;
  color: var(--text);
  background: #252922;
  border-radius: 9px;
  font-size: 12px;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip button {
  border: 0;
  padding: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.files-view {
  overflow-y: auto;
  padding: 44px 0 30px;
}

.files-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 24px;
}

.files-heading h1 {
  margin: 0;
  font-size: clamp(38px, 9vw, 58px);
  font-weight: 560;
  letter-spacing: -.055em;
}

.files-heading p,
.files-hint,
.storage-warning {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.upload-button {
  padding: 10px 0 10px 18px;
  color: var(--accent);
  cursor: pointer;
}

.upload-button input { display: none; }

.storage-line {
  height: 2px;
  overflow: hidden;
  background: var(--line);
}

.storage-line span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width .3s ease;
}

.storage-warning { color: var(--danger); }
.files-hint { margin: 26px 0 8px; }

.file-list { border-top: 1px solid var(--line); }

.file-row {
  width: 100%;
  min-height: 68px;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.file-kind {
  width: 42px;
  min-height: 42px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
}

.file-kind img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
}

.file-row b,
.file-row small { display: block; }

.file-row b {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row small {
  margin-top: 4px;
  color: var(--muted);
}

.download-button {
  border: 0;
  padding: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.file-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.attach-existing-button,
.access-button,
.delete-button {
  border: 0;
  padding: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.attach-existing-button {
  color: var(--text);
  font-size: 17px;
}

.access-button {
  font-size: 11px;
}

.access-button.enabled {
  color: var(--accent);
}

.delete-button {
  font-size: 20px;
}

.empty {
  padding: 60px 0;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  max-width: calc(100% - 36px);
  padding: 10px 14px;
  color: var(--bg);
  background: var(--text);
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 600px) {
  .app { padding-left: 16px; padding-right: 16px; }
  .topbar { height: 58px; }
  .messages { padding-top: 28px; gap: 20px; }
  .message { max-width: 90%; }
  .welcome { padding-top: 22vh; }
  .files-view { padding-top: 32px; }
  .jobs-panel { width: calc(100% - 32px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
