:root {
  color-scheme: dark;
  --bg: #121214;
  --panel: #1b1b1f;
  --border: #2c2c33;
  --text: #e6e6ea;
  --muted: #9a9aa6;
  --accent: #ea580c;
  --accent-soft: #3a2214;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 18px; margin: 0; }
header #new-chat { margin-left: auto; }

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

aside {
  width: 300px;
  padding: 16px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

aside h2 { font-size: 15px; margin: 0; }

.muted { color: var(--muted); font-size: 13px; }

button, .button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
}

button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }

select {
  width: 100%;
  margin-top: 4px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
}

#profile-text {
  white-space: pre-wrap;
  font-size: 11px;
  max-height: 50vh;
  overflow-y: auto;
  background: var(--panel);
  padding: 8px;
  border-radius: 6px;
}

#chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  max-width: 900px;
  line-height: 1.5;
  font-size: 14px;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid #5a3218;
  padding: 8px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
}

.msg.assistant { align-self: flex-start; width: 100%; }
.msg.error { color: #f87171; }

.activity {
  font-size: 12px;
  color: var(--muted);
  border-left: 2px solid var(--border);
  padding-left: 8px;
  margin-bottom: 8px;
}

.activity div { margin: 2px 0; }

.usage { font-size: 11px; color: var(--muted); margin-top: 6px; }

.msg table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.msg th, .msg td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.msg th { background: var(--panel); }
.msg code { background: var(--panel); padding: 1px 4px; border-radius: 4px; font-size: 12px; }
.msg pre code { display: block; padding: 8px; overflow-x: auto; }

#suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 8px;
}

#suggestions button { font-size: 12px; padding: 5px 10px; }

#composer {
  display: flex;
  gap: 8px;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--border);
}

#composer textarea {
  flex: 1;
  resize: vertical;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}

#composer button { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }

@media (max-width: 800px) {
  main { flex-direction: column; }
  aside { width: auto; border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
}

aside ul { margin: 0; padding-left: 18px; }
aside li { margin: 2px 0; }
#legacy-save summary { cursor: pointer; }
#legacy-save[open] { display: flex; flex-direction: column; gap: 8px; }

#composer > .button { align-self: flex-end; }

#attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 18px 0;
}

.attachment { position: relative; }
.attachment img, .thumbs img {
  height: 64px;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}
.attachment button {
  position: absolute;
  top: -6px;
  right: -6px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  line-height: 18px;
}

.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

aside .row { display: flex; gap: 6px; flex-wrap: wrap; }
aside .stack { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
aside textarea {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
  resize: vertical;
}
button.primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }

#library-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
#library-grid .shot {
  position: relative;
  padding: 0;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: 6px;
  border: 2px solid var(--border);
  opacity: 0.6;
}
#library-grid .shot.read { opacity: 1; border-color: #3f7d4f; }
#library-grid .shot.selected { border-color: var(--accent); }
#library-grid .shot img { width: 100%; height: 100%; object-fit: cover; display: block; }

#shot-detail { display: flex; flex-direction: column; gap: 6px; }
#shot-detail[hidden] { display: none; }
#shot-image { width: 100%; border-radius: 6px; border: 1px solid var(--border); }
#shot-title { font-size: 13px; font-weight: 600; }

[hidden] { display: none !important; }
