@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-cyrillic-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-cyrillic-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-cyrillic-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-latin-ext-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-latin-ext-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-latin-ext-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Mulish";
  src: url("/static/fonts/mulish-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #ffffff;
  --bg-soft: #f9f9f9;
  --border: #eeeeee;
  --text: #000000;
  --text-muted: #9e9e9e;
  --text-second: #222222;
  --accent: #3c9df2;
  --accent-soft: #86bae8;
  --accent-bg: #f2f9ff;
  --danger: #fe6a00;
  --radius-btn: 10px;
  --radius-card: 15px;
  --sidebar: 260px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Mulish", system-ui, sans-serif;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
}
button, input, textarea { font-family: inherit; }
a { color: inherit; }
h1, h2, h3 { font-weight: 700; margin: 0; }

.app {
  display: flex;
  min-height: 100%;
}
.sidebar {
  width: var(--sidebar);
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
}
.sidebar-top {
  display: flex;
  gap: 8px;
  padding: 16px;
  align-items: center;
}
.btn-new-chat { flex: 1; }
.chat-list {
  flex: 1;
  overflow: auto;
  padding: 0 10px 12px;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-second);
  position: relative;
}
.chat-item:hover { background: #fff; }
.chat-item.is-active { background: var(--accent-bg); color: var(--text); }
.chat-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.chat-item-actions {
  display: none;
  gap: 2px;
}
.chat-item:hover .chat-item-actions { display: flex; }
.sidebar-bottom {
  padding: 12px 16px 18px;
  border-top: 1px solid var(--border);
}
.nav-link {
  display: block;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-second);
  font-weight: 600;
}
.nav-link.is-active, .nav-link:hover { background: #fff; }
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding: 0 10px;
}
.user-login { font-size: 13px; color: var(--text-muted); }
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.main-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 18px; }
.burger { display: none; }
.sidebar-close { display: none; }
.sidebar-backdrop { display: none; }

.btn {
  border: 0;
  border-radius: var(--radius-btn);
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-soft);
  color: var(--text);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-soft); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  background: transparent;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-second);
}
.icon-btn:hover { background: var(--bg-soft); }
.danger-btn { color: var(--danger); }

.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-lead { color: var(--text-muted); margin: 8px 0 22px; }
.login-form label, .modal-card label, .page-body label {
  display: block;
  margin-bottom: 14px;
}
.login-form span, .modal-card label span { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text-second); }
input[type="text"], input[type="password"], textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  background: var(--bg-soft);
  color: var(--text);
}
textarea { resize: vertical; }
.form-error { color: var(--danger); font-size: 14px; margin: 0 0 14px; }

.chat-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.app.is-chat .main { height: 100vh; min-height: 0; }
.chat-scroll {
  flex: 1;
  overflow: auto;
  padding: 24px 20px 12px;
}
.messages { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; }
.msg-user { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }
.bubble {
  max-width: min(78%, 640px);
  padding: 12px 14px;
  border-radius: 15px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
}
.msg-user .bubble { background: var(--accent-bg); }
.msg-assistant .bubble { background: var(--bg-soft); }
.msg-files { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.msg-files img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; }
.covers { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.cover-card { width: min(100%, 640px); }
.cover-card img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 15px;
  background: var(--bg-soft);
}
.cover-card.is-v { width: min(100%, 280px); }
.cover-actions { display: flex; gap: 4px; margin-top: 8px; }
.prompt-fold { margin-top: 8px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.prompt-fold summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.prompt-fold pre {
  margin: 0;
  padding: 0 12px 12px;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-second);
}
.slot {
  border-radius: 15px;
  background: #ececec;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  animation: pulse 1.4s ease-in-out infinite;
}
.slot.h { aspect-ratio: 16/9; width: min(100%, 640px); }
.slot.v { aspect-ratio: 9/16; width: min(100%, 280px); }
@keyframes pulse { 50% { opacity: 0.55; } }

.empty-chat {
  max-width: 560px;
  margin: 48px auto 0;
  text-align: center;
}
.empty-chat p { color: var(--text-muted); }
.empty-examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.example-chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}
.example-chip:hover { background: var(--accent-bg); }

.composer {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px 16px;
  position: relative;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 8px;
}
.composer textarea {
  flex: 1;
  border: 0;
  background: transparent;
  max-height: 180px;
  padding: 8px 4px;
  outline: none;
}
.send-btn { white-space: nowrap; }
.composer-opts {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 6px 0;
  flex-wrap: wrap;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.toggle input { accent-color: var(--accent); }
.count-switch { display: flex; gap: 4px; margin-left: auto; }
.count-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}
.count-btn.is-on { background: var(--accent); color: #fff; border-color: var(--accent); }
.plus-wrap { position: relative; }
.plus-menu {
  position: absolute;
  bottom: 44px;
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 15px;
  box-shadow: var(--shadow);
  min-width: 180px;
  overflow: hidden;
  z-index: 5;
}
.plus-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.plus-menu button:hover { background: var(--bg-soft); }
.attach-preview { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 6px 8px; }
.attach-preview:empty { display: none; padding: 0; }
.attach-item { position: relative; }
.attach-item img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.attach-item .x {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
}
.drop-on .composer-row,
.modal.drop-on .modal-card { outline: 2px dashed var(--accent); }

.slash-menu {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 15px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow: auto;
  z-index: 6;
}
.slash-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  position: relative;
}
.slash-item.is-active, .slash-item:hover { background: var(--accent-bg); }
.slash-cmd { color: var(--accent); font-weight: 600; }
.slash-tip {
  position: absolute;
  left: calc(100% - 8px);
  top: 8px;
  background: var(--text-second);
  color: #fff;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  width: 220px;
  z-index: 7;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.28);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: #fff;
  border-radius: 15px;
  padding: 22px;
  width: min(560px, 100%);
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow: auto;
}
.modal-card.full { width: min(980px, 100%); height: min(90vh, 900px); display: flex; flex-direction: column; }
.modal-full .modal-card { width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
.raw-attach-row { display: flex; gap: 8px; margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions.stacked { flex-direction: column; }
.library-head { display: flex; align-items: center; gap: 12px; }
.library-head h3 { flex: 1; }
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  overflow: auto;
  margin-top: 16px;
  flex: 1;
}
.lib-item { position: relative; border-radius: 12px; overflow: hidden; cursor: pointer; border: 2px solid transparent; }
.lib-item.is-on { border-color: var(--accent); }
.lib-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.lib-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  cursor: pointer;
}

.page-body { padding: 20px; max-width: 860px; }
.page-toolbar { margin-bottom: 16px; }
.card-list { display: flex; flex-direction: column; gap: 10px; }
.tpl-card, .users-table {
  background: var(--bg-soft);
  border-radius: 15px;
}
.tpl-card {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.tpl-card .meta { flex: 1; }
.tpl-card .cmd { color: var(--accent); font-weight: 600; font-size: 13px; }
.users-table { width: 100%; border-collapse: collapse; overflow: hidden; }
.users-table th, .users-table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.users-table th { font-size: 13px; color: var(--text-muted); font-weight: 600; }

.tooltip {
  position: fixed;
  z-index: 50;
  background: var(--text-second);
  color: #fff;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 400;
  pointer-events: none;
  max-width: 220px;
}
.tooltip[hidden] { display: none !important; }

.retry-row { margin-top: 8px; }

@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    z-index: 30;
    transition: transform .2s ease;
  }
  .sidebar.is-open { transform: none; }
  .sidebar-close { display: inline-flex; }
  .burger { display: inline-flex; }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.25);
    z-index: 25;
    opacity: 0;
    pointer-events: none;
  }
  .sidebar-backdrop.is-on { opacity: 1; pointer-events: auto; }
  .bubble { max-width: 92%; }
  .cover-card, .cover-card.is-v, .slot.h, .slot.v { width: 100%; }
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .modal-full .modal-card { border-radius: 0; }
  .chat-item-actions { display: flex; }
  .slash-tip { left: 12px; right: 12px; top: auto; bottom: calc(100% + 4px); width: auto; }
}
