/* NexoraAI — фирменный стиль ПЛИТ №99 (цвета из логотипа image.png) */
:root {
  --bg-navy: #01122c;
  --bg-navy-2: #062244;
  --bg: #f5f7fa;
  --gold: #efb11f;
  --gold-soft: #f7cf6b;
  --ink: #17233b;
  --muted: #61708c;
  --line: #dbe2ee;
  --card: #ffffff;
  --ok: #1e9e5a;
  --err: #d64545;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(2, 18, 44, .1);
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, 'Inter', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: #1c5ed6; }
.hidden { display: none !important; }

/* ---------- логотип ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; }
.logo img { width: 34px; height: 34px; border-radius: 9px; }
.logo .name { font-weight: 800; letter-spacing: .2px; }
.logo .sub { display: block; font-size: 11px; font-weight: 600; color: var(--muted); line-height: 1.1; }

/* ---------- экран входа ---------- */
#auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(239, 177, 31, .16), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(28, 94, 214, .25), transparent 55%),
    var(--bg-navy);
  padding: 20px;
}
.auth-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(1, 18, 44, .45);
  padding: 34px 34px 26px;
}
.auth-card .brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 22px; text-align: center; }
.auth-card .brand img { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 10px 30px rgba(1,18,44,.25); }
.auth-card h1 { font-size: 24px; margin: 0; color: var(--bg-navy); }
.auth-card .brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fbfcfe;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(239,177,31,.22); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
  background: var(--bg-navy);
  color: #fff;
  transition: transform .08s, box-shadow .15s, background .15s;
}
.btn:hover { background: #0b2a54; box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn.full { width: 100%; }
.btn.gold { background: linear-gradient(135deg, var(--gold), #e59a10); color: #221b06; }
.btn.gold:hover { background: linear-gradient(135deg, var(--gold-soft), var(--gold)); }
.btn.ghost { background: transparent; color: var(--bg-navy); border: 1.5px solid var(--line); }
.btn.ghost:hover { background: #eef2f8; }
.btn.danger { background: var(--err); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.auth-note { margin-top: 18px; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.5; }
.alert {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 14px;
  line-height: 1.45;
}
.alert.err { background: #fdecec; color: #8f2323; border: 1px solid #f2c7c7; }
.alert.ok { background: #e9f9f0; color: #146c41; border: 1px solid #bfe8d2; }

/* ---------- каркас приложения ---------- */
#app-page { display: flex; height: 100vh; overflow: hidden; }
#sidebar {
  width: 288px;
  flex: none;
  background: var(--bg-navy);
  color: #cdd9ee;
  display: flex;
  flex-direction: column;
  transition: margin-left .2s;
}
#sidebar .side-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; color: #fff; }
#sidebar .side-head img { width: 38px; height: 38px; border-radius: 11px; background: #fff; }
.new-chat { margin: 10px 14px; background: linear-gradient(135deg, var(--gold), #e59a10); color: #221b06; width: calc(100% - 28px); }
.new-chat:hover { background: linear-gradient(135deg, var(--gold-soft), var(--gold)); }
#chat-list { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
#chat-list .sec { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #6d80a5; padding: 10px 8px 6px; font-weight: 700; }
.chat-item {
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c3d2ea;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}
.chat-item:hover { background: rgba(255,255,255,.07); }
.chat-item.active { background: rgba(239,177,31,.16); color: #ffe9b8; }
.chat-item .t { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chat-item .acts { display: none; gap: 4px; }
.chat-item:hover .acts { display: flex; position: absolute; right: 6px; }
.chat-item .acts button {
  background: rgba(1,18,44,.65);
  border: none;
  color: #d7e2f4;
  width: 24px; height: 24px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.chat-item .acts button:hover { background: var(--gold); color: #1d1606; }
.side-foot { border-top: 1px solid rgba(255,255,255,.09); padding: 12px 14px; }
.side-user { display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: 10px; padding: 8px; color: #fff; }
.side-user:hover { background: rgba(255,255,255,.07); }
.side-user .avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--gold), #d8951a);
  color: #221b06;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.side-user .who { flex: 1; min-width: 0; }
.side-user .who .nm { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who .rl { font-size: 11.5px; color: #9fb1d6; }

/* ---------- основная область ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
#main-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
#main-head .h-title { font-weight: 800; font-size: 16px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-scroll { flex: 1; overflow-y: auto; }
#chat-area { max-width: 860px; margin: 0 auto; padding: 26px 22px 30px; width: 100%; }

/* сообщения */
.msg { display: flex; gap: 12px; margin-bottom: 22px; }
.msg .avatar {
  width: 34px; height: 34px;
  border-radius: 10px;
  flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  font-weight: 800;
}
.msg.user .avatar { background: var(--bg-navy); color: #fff; }
.msg.ai .avatar { background: linear-gradient(135deg, var(--gold), #d8951a); color: #221b06; }
.msg .body { flex: 1; min-width: 0; }
.msg .who { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.msg .content { word-wrap: break-word; }
.msg.ai .content p { margin: 0 0 10px; }
.msg.ai .content ul, .msg.ai .content ol { margin: 0 0 10px; padding-left: 22px; }
.msg .content table { border-collapse: collapse; margin: 8px 0 12px; display: block; overflow-x: auto; max-width: 100%; }
.msg .content th, .msg .content td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; font-size: 13.5px; }
.msg .content th { background: #eef2f9; }
.msg .content code { background: #eef2f8; border-radius: 6px; padding: 2px 6px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.msg .content pre { background: #0d1526; color: #e7eefc; border-radius: 12px; padding: 14px 16px; overflow-x: auto; margin: 10px 0 12px; }
.msg .content pre code { background: none; color: inherit; padding: 0; font-size: 13px; line-height: 1.5; }
.msg .content blockquote { border-left: 3px solid var(--gold); margin: 8px 0; padding: 4px 14px; color: var(--muted); background: #fbf7ee; border-radius: 0 8px 8px 0; }
.msg .content h1, .msg .content h2, .msg .content h3 { margin: 14px 0 8px; line-height: 1.3; }
.msg .tool-line { font-size: 12.5px; color: var(--muted); background: #f0f4fa; border: 1px dashed var(--line); padding: 5px 10px; border-radius: 9px; display: inline-flex; gap: 6px; margin: 2px 0 8px; align-items: center; }
.msg .tool-line .spin { width: 11px; height: 11px; border: 2px solid var(--gold); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.msg .acts-row { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .acts-row { opacity: 1; }
.acts-row button {
  background: #eef2f8;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
}
.acts-row button:hover { background: var(--gold); border-color: var(--gold); color: #221b06; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: #eef2f8;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--ink);
  text-decoration: none;
}
.file-chip img { max-width: 120px; max-height: 90px; border-radius: 8px; }
.typing-dots span { display: inline-block; width: 7px; height: 7px; background: var(--gold); border-radius: 50%; margin-right: 4px; animation: blink 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- композер ---------- */
#composer-wrap { padding: 0 22px 18px; background: linear-gradient(transparent, var(--bg) 30%); }
#composer {
  max-width: 860px;
  margin: 0 auto;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px 14px 10px;
}
#composer.disabled { opacity: .6; }
#attach-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
#attach-row .file-chip button { border: none; background: none; cursor: pointer; font-size: 14px; padding: 0 2px; color: var(--muted); }
#input-row { display: flex; gap: 10px; align-items: flex-end; }
#prompt-input {
  flex: 1;
  min-height: 44px;
  max-height: 180px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  padding: 10px 6px;
  line-height: 1.45;
}
.icon-btn {
  border: 1.5px solid var(--line);
  background: #fff;
  width: 40px; height: 40px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex: none;
  color: var(--ink);
}
.icon-btn:hover { border-color: var(--gold); background: #fffaf0; }
#send-btn { background: var(--bg-navy); color: #fff; border: none; width: 44px; height: 44px; border-radius: 13px; font-size: 18px; }
#send-btn:hover { background: #0b2a54; }
#send-btn.stop { background: var(--err); }
#composer-hint { max-width: 860px; margin: 7px auto 0; text-align: center; font-size: 11.5px; color: var(--muted); }

/* пустой экран */
#empty-hero { text-align: center; padding: 60px 20px 20px; }
#empty-hero img { width: 88px; height: 88px; border-radius: 24px; box-shadow: 0 14px 40px rgba(1,18,44,.18); }
#empty-hero h2 { color: var(--bg-navy); margin: 18px 0 6px; }
#empty-hero p { color: var(--muted); margin: 0 0 26px; }
.suggests { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; max-width: 760px; margin: 0 auto; }
.suggests button {
  text-align: left;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 13px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, transform .08s;
}
.suggests button:hover { border-color: var(--gold); transform: translateY(-1px); }
.suggests .b { font-weight: 700; display: block; margin-bottom: 3px; color: var(--bg-navy); }
.suggests .d { font-size: 12.5px; color: var(--muted); }

/* ---------- админ-панель ---------- */
#admin-page { display: flex; height: 100vh; }
#admin-side { width: 240px; background: var(--bg-navy); color: #cdd9ee; padding: 14px 10px; flex: none; overflow-y: auto; }
#admin-side .nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: #c3d2ea;
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
#admin-side .nav-item:hover { background: rgba(255,255,255,.07); }
#admin-side .nav-item.active { background: rgba(239,177,31,.16); color: #ffe9b8; }
#admin-side .brand { padding: 10px 12px 16px; display: flex; align-items: center; gap: 8px; }
#admin-side .brand img { width: 30px; height: 30px; border-radius: 9px; }
#admin-side .brand b { color: #fff; }
#admin-main { flex: 1; overflow-y: auto; padding: 26px 30px 60px; }
.admin-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.admin-head h1 { font-size: 22px; margin: 0; }
.card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 2px 10px rgba(2,18,44,.04);
}
.card h3 { margin: 0 0 12px; font-size: 16px; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: 1fr 1fr; }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.c3, .grid.c4 { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .v { font-size: 26px; font-weight: 800; color: var(--bg-navy); }
.stat .l { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 9px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:hover td { background: #f7f9fc; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; background: #eef2f8; color: var(--ink); }
.badge.gold { background: #fff3d6; color: #8a6410; }
.badge.green { background: #e5f7ee; color: #15794b; }
.badge.red { background: #fdecec; color: #a33030; }
.badge.blue { background: #e8f0ff; color: #23549c; }
form.inline .field { display: inline-block; margin-right: 10px; min-width: 160px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
select, input[type="text"], input[type="number"], input[type="password"], textarea.form {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: #fbfcfe;
  outline: none;
}
select:focus, input:focus, textarea.form:focus { border-color: var(--gold); }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { width: auto; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.kbd { font-family: ui-monospace, Consolas, monospace; background: #eef2f8; border-radius: 6px; padding: 2px 7px; font-size: 12.5px; }
code.leaf { font-family: ui-monospace, monospace; background: #eef2f8; padding: 1px 6px; border-radius: 6px; }
.modal-back { position: fixed; inset: 0; background: rgba(1,18,44,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--card); border-radius: 16px; padding: 24px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; }
.modal h3 { margin: 0 0 14px; }
.temp-pass { background: #fff8e6; border: 1.5px dashed var(--gold); border-radius: 12px; padding: 14px; text-align: center; font-size: 20px; letter-spacing: .1em; font-family: ui-monospace, monospace; margin: 10px 0; }

/* ---------- мобильная адаптация ---------- */
#burger { display: none; }
@media (max-width: 860px) {
  #sidebar { position: fixed; z-index: 40; height: 100vh; box-shadow: 20px 0 60px rgba(1,18,44,.4); }
  #sidebar.collapsed { margin-left: -288px; }
  #burger { display: inline-flex; }
  #admin-side { position: fixed; z-index: 40; height: 100vh; margin-left: -240px; }
  #admin-side.open { margin-left: 0; }
  #admin-page { display: block; }
  #admin-main { height: 100vh; }
  .grid.c2 { grid-template-columns: 1fr; }
}

/* скроллбары */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #b9c6da; border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
#sidebar ::-webkit-scrollbar-thumb { background: #2a3f63; background-clip: content-box; }
/* доступность */
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
/* перетаскивание файлов в чат */
#chat-area.drop-active {
  outline: 2px dashed var(--gold, #EFB11F);
  outline-offset: -8px;
  border-radius: 14px;
  background: rgba(239, 177, 31, 0.05);
}
