:root {
  --bg: #f4efe6;
  --bg-2: #ece4d7;
  --ink: #1c1915;
  --muted: #6b645b;
  --line: #d9cfc0;
  --paper: #fffaf3;
  --accent: #c45c26;
  --accent-dark: #9d4316;
  --good: #2f6f4e;
  --good-bg: #e6f3ea;
  --bad: #9f2d2d;
  --bad-bg: #f8e8e6;
  --shadow: 0 18px 40px rgba(47, 36, 22, 0.08);
  --radius: 18px;
  font-family: "Source Sans 3", "Noto Sans SC", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body {
  background:
    radial-gradient(1200px 500px at 10% -10%, #f8e1c9 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #dfe8dc 0%, transparent 50%),
    var(--bg);
}

.wrap { width: min(1180px, calc(100% - 32px)); margin: 28px auto 64px; }
header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 24px; }
.brand { display: flex; flex-direction: column; gap: 4px; }
.brand h1 { margin: 0; font-size: 28px; letter-spacing: -0.03em; }
.brand p { margin: 0; color: var(--muted); }

.status { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
}
.pill.ok { color: var(--good); background: var(--good-bg); border-color: #cfe3d5; }
.pill.warn { color: var(--accent-dark); background: #f8eadf; border-color: #efd3bf; }

.grid { display: grid; grid-template-columns: 1.4fr 0.9fr; gap: 20px; }
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card h2 { margin: 0 0 6px; font-size: 18px; }
.hint { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
input, textarea, select, button { font: inherit; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink);
}
textarea { min-height: 110px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 14px; }
.check input { width: auto; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  background: var(--bg-2);
  color: var(--ink);
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.55; cursor: wait; }

.banner { border-radius: 12px; padding: 10px 12px; margin-top: 14px; font-size: 14px; display: none; }
.banner.show { display: block; }
.banner.ok { background: var(--good-bg); color: var(--good); }
.banner.err { background: var(--bad-bg); color: var(--bad); }

.chat { display: flex; flex-direction: column; min-height: 520px; }
.messages {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  padding-right: 4px;
}
.msg { border-radius: 14px; padding: 10px 12px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.msg.user { background: #1c1915; color: #fff; align-self: flex-end; max-width: 92%; }
.msg.agent { background: var(--bg-2); align-self: flex-start; max-width: 92%; }
.composer { display: flex; gap: 8px; margin-top: 14px; }
.composer input { flex: 1; }

.recent { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; }
.recent a, .recent .item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  font-size: 14px;
}
.recent .meta { color: var(--muted); }

#login-gate {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 21, 0.45);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#login-gate.show { display: flex; }
#login-gate .card { width: min(420px, 100%); }

@media (max-width: 900px) {
  .grid, .row, .row-3 { grid-template-columns: 1fr; }
  header { align-items: flex-start; flex-direction: column; }
}

.settings { margin-bottom: 20px; }
.check-wrap { display: flex; align-items: flex-end; min-height: 70px; }
.image-drop {
  border: 1.5px dashed var(--line);
  border-radius: 16px;
  padding: 14px;
  background: #fff;
}
.image-drop.dragover { border-color: var(--accent); background: #f8eadf; }
.image-tray {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.image-empty { margin: 8px 0 4px; color: var(--muted); font-size: 14px; text-align: center; }
.thumb {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-2);
  aspect-ratio: 1;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute;
  left: 6px;
  top: 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 2px 6px;
}
.thumb .remove {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  background: rgba(28, 25, 21, 0.8);
  color: #fff;
}
.thumb .caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 4px 6px;
  font-size: 11px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.url-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.url-row button { margin-top: 0; }
