:root {
  --bg: #10140f;
  --bg2: #0c0f0b;
  --panel: #181e17;
  --panel2: #1e261c;
  --line: #2c3628;
  --text: #e7f0d8;
  --muted: #8a9778;
  --accent: #d6f26a;
  --accent-dim: #a4c24a;
  --ok: #7ee0a3;
  --warn: #f0b14a;
  --bad: #ef6b5c;
  --info: #8ec8ff;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(214, 242, 106, 0.08), transparent 50%),
    var(--bg);
  color: var(--text);
  font: 15px/1.45 "IBM Plex Sans", "Segoe UI", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 20, 15, 0.92);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.brand {
  font-weight: 600;
  letter-spacing: 0.16em;
  font-size: 13px;
  color: var(--accent);
  text-transform: uppercase;
}

.brand span { color: var(--muted); letter-spacing: 0.04em; font-weight: 400; }

nav { display: flex; gap: 18px; }
nav a { color: var(--muted); font-size: 14px; }
nav a.active, nav a:hover { color: var(--text); text-decoration: none; }

.top-right { margin-left: auto; display: flex; gap: 12px; align-items: center; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px; }

h1 { font-size: 26px; font-weight: 600; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 0 0 12px; font-weight: 600; }
.lead { color: var(--muted); margin: 0 0 22px; }

.flash, .flash-error {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
}
.flash { background: #22311d; color: var(--ok); }
.flash-error { background: #3a1d1a; color: var(--bad); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1.2fr 0.8fr; }
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.row-list { display: grid; gap: 10px; }

.account-row {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.6fr 0.5fr 0.5fr;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.account-row:hover { border-color: var(--accent-dim); }
.account-row .name { font-weight: 600; }
.account-row .meta { color: var(--muted); font-size: 13px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--bg2);
}
.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.pill-online { color: var(--ok); border-color: #2e5a40; }
.pill-connecting { color: var(--info); }
.pill-flood, .pill-waiting { color: var(--warn); }
.pill-error, .pill-frozen { color: var(--bad); }
.pill-auth_required, .pill-offline { color: var(--muted); }
.pill-unread { color: var(--accent); }

.btn, button, input[type="submit"] {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
}
.btn:hover, button:hover, input[type="submit"]:hover { border-color: var(--accent-dim); }
.btn-primary, .btn-primary:hover {
  background: var(--accent);
  color: #1a220f;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-ghost { background: transparent; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
[hidden] { display: none !important; }
input[type="text"], input[type="password"], input[type="number"], input[type="file"],
textarea, select {
  width: 100%;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
  margin-bottom: 12px;
}
textarea { min-height: 120px; resize: vertical; }
.hint { color: var(--muted); font-size: 12px; margin: -6px 0 12px; }
.tiny { color: var(--muted); font-size: 12px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  margin: 0 0 14px;
  font-size: 14px;
}
.check input { width: auto; margin: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr.dim td { color: var(--muted); }

.tabs { display: flex; gap: 6px; margin: 0 0 18px; }
.tabs a {
  padding: 7px 12px;
  border-radius: 9px;
  color: var(--muted);
  border: 1px solid transparent;
}
.tabs a.active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
  text-decoration: none;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { width: min(420px, 100%); }

.photo {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--bg2);
}

.thread { display: grid; gap: 10px; margin: 0 0 18px; }
.bubble {
  max-width: 70%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  white-space: pre-wrap;
}
.bubble.in { background: var(--panel2); }
.bubble.out { background: #24301c; margin-left: auto; }
.bubble .meta { color: var(--muted); font-size: 11px; margin-bottom: 4px; }

.log { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 12px; color: var(--muted); }
.log b { color: var(--text); font-weight: 500; }

.htmx-indicator { display: none; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { display: inline; }

.photo-upload { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; }
.photo-upload input[type="file"] { display: none; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 700px) {
  .photo-grid { grid-template-columns: repeat(3, 1fr); }
}
.photo-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--line);
  background: var(--bg2);
}
.photo-item.main { border-color: var(--accent); }
.photo-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-set { position: absolute; inset: 0; margin: 0; }
.photo-set button {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}
.photo-set button:hover {
  border: 0;
  background: rgba(214, 242, 106, 0.16);
}
.photo-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  z-index: 1;
  pointer-events: none;
  background: var(--accent);
  color: #1a220f;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
}
.photo-del-form { position: absolute; top: 4px; right: 4px; z-index: 2; margin: 0; }
.photo-del {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  background: #3a1d1a;
  color: var(--bad);
  line-height: 1;
}

.chat-card {
  display: grid;
  grid-template-columns: 1.5fr 0.9fr;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: inherit;
}
.chat-card:hover { border-color: var(--accent-dim); }
.chat-card.dim { opacity: 0.6; }
.chat-card .name { font-weight: 600; }
.chat-card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.chat-card-main {
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.chat-card-main:hover { text-decoration: none; }
.chat-card-job {
  text-align: right;
  display: grid;
  justify-items: end;
  gap: 4px;
}
.chat-card-job form { margin: 0; }
.chat-toggle {
  padding: 5px 12px;
  font-size: 13px;
}
@media (max-width: 900px) {
  .chat-card { grid-template-columns: 1fr; }
  .chat-card-job { text-align: left; justify-items: start; }
}
.tmpl-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}
.tmpl-photo {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg2);
}
.tmpl-photo.first { border-color: var(--accent); }
.tmpl-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tmpl-photo .photo-set,
.tmpl-photo .photo-set button {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}
.tmpl-photo .photo-set button:hover { border: 0; background: rgba(214, 242, 106, 0.16); }
.tmpl-photo-add {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px dashed var(--line);
  display: grid;
  place-items: center;
  margin: 0;
  background: var(--bg2);
}
.tmpl-photo-add label {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  color: var(--muted);
  font-size: 22px;
}
.tmpl-photo-add input { display: none; }

.tmpl-list { display: grid; gap: 8px; }
.tmpl-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px 8px 4px 4px;
}
.tmpl-row-main {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 6px;
  min-width: 0;
}
.tmpl-row-main:hover { border: 0; }
.tmpl-row-copy { min-width: 0; }
.tmpl-row-copy .name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tmpl-row-copy .tiny {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tmpl-row-thumbs {
  display: flex;
  gap: 4px;
  min-height: 48px;
  align-items: center;
}
.tmpl-row-thumbs img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.tmpl-row-textmark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.tmpl-add {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  border-radius: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.label-row label { margin: 0; }
.tag-insert {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
}
.tag-insert:hover { border: 0; text-decoration: underline; }
