/* NOVAGLOW CRM — оформление панели команды. Акцент — фирменный оранжевый приложения. */
@font-face { font-family: Inter; src: url('/public/Inter.ttf') format('truetype'); font-weight: 100 900; font-display: swap; }

:root {
  --accent: #ff481b;
  --accent-soft: #fff0e9;
  --danger: #d92d20;
  --ink: #202329;
  --muted: #7d838c;
  --line: #e9eaed;
  --bg: #f6f7f9;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, Arial, sans-serif; font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
svg { width: 20px; height: 20px; flex-shrink: 0; }
:focus-visible { outline: 3px solid #ffb59f; outline-offset: 2px; }
small { display: block; color: var(--muted); font-size: 11px; line-height: 1.6; font-weight: 400; }
h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.5px; }
h2 { margin: 0; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* --- Кнопки и поля --- */
.primary, .danger, .ghost { display: inline-flex; align-items: center; gap: 8px; border-radius: 10px; padding: 11px 16px; font-weight: 600; font-size: 13px; border: 1px solid transparent; }
.primary { background: var(--accent); color: white; }
.danger { background: var(--danger); color: white; }
.ghost { background: white; border-color: var(--line); color: var(--ink); }
.ghost.danger { color: var(--danger); background: white; border-color: #f3c7c3; }
.primary.small, .ghost.small { padding: 7px 11px; font-size: 12px; }
.primary:disabled { opacity: 0.5; cursor: wait; }
.textbtn { background: none; border: 0; padding: 6px 0; color: var(--muted); font-size: 12px; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; }
label { display: grid; gap: 6px; font-size: 12px; font-weight: 600; color: #4a505a; }
input, select, textarea { border: 1px solid #dcdee3; border-radius: 10px; padding: 11px 12px; background: white; color: var(--ink); font-weight: 400; }
textarea { resize: vertical; }
.formerror { color: var(--danger); font-size: 12px; min-height: 1em; margin: 0; }

/* --- Вход --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.loginbox { width: min(380px, 100%); background: white; border: 1px solid var(--line); border-radius: 18px; padding: 32px; display: grid; gap: 16px; }
.loginbox h1 { font-size: 20px; margin: 12px 0 0; }
.loginbox .primary { justify-content: center; padding: 13px; }

/* --- Каркас --- */
.brand { display: grid; grid-template-columns: 36px 1fr; column-gap: 10px; font-size: 19px; font-weight: 850; align-items: center; letter-spacing: -0.5px; text-decoration: none; }
.brand img { width: 36px; grid-row: span 2; }
.brand span { font-size: 9px; letter-spacing: 2.5px; font-weight: 500; color: #8b8d95; }
aside { width: 240px; background: white; border-right: 1px solid var(--line); position: fixed; inset: 0 auto 0 0; padding: 28px 16px; display: flex; flex-direction: column; overflow-y: auto; }
nav { display: grid; gap: 4px; margin-top: 30px; }
nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; color: #6f7580; border-radius: 10px; font-size: 13px; font-weight: 550; text-decoration: none; }
nav a:hover { background: #f6f7f9; }
nav a.active { background: var(--accent-soft); color: var(--accent); }
nav .short { display: none; }
nav b { margin-left: auto; background: var(--accent); color: white; border-radius: 6px; padding: 1px 7px; font-size: 11px; }
.sidefoot { margin-top: auto; padding-top: 20px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.person { display: flex; gap: 10px; align-items: center; font-size: 13px; font-weight: 600; }
.avatar { width: 34px; height: 34px; background: #f0f1f4; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; font-weight: 650; font-size: 12px; }
.main { margin-left: 240px; min-height: 100vh; }
header { height: 64px; padding: 0 36px; display: flex; align-items: center; background: white; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
header em { font-style: normal; margin: 0 10px; color: #c3c6ce; }
header a { text-decoration: none; color: var(--ink); }
main { padding: 26px 36px 40px; max-width: 1500px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.pagetitle { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.pagetitle p { margin: 0; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

/* --- Панели и таблицы --- */
.panel { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin-bottom: 18px; }
.panel.error { color: var(--danger); }
.sectionhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid2 .panel { margin-bottom: 0; }
.grid2 + .panel { margin-top: 18px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; display: grid; gap: 4px; text-decoration: none; }
a.stat[href]:hover { border-color: #ffc7b5; }
.stat strong { font-size: 30px; letter-spacing: -1px; }
.stat span { font-size: 12px; color: var(--muted); }
.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 7px 13px; font-size: 12px; color: #5d636d; }
.tabs button.active { background: var(--ink); border-color: var(--ink); color: white; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid #dcdee3; border-radius: 10px; padding: 0 10px; color: var(--muted); min-width: 260px; }
.search input { border: 0; padding: 9px 0; outline: none; flex: 1; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid #f1f2f4; vertical-align: top; }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover td { background: #fafafb; }
tr.dim td { opacity: 0.55; }
td a { color: var(--accent); text-decoration: none; font-weight: 600; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.s0 { background: #f0f1f4; color: #5d636d; }
.s1 { background: #fff4d6; color: #9a6400; }
.s3 { background: #e3f6ee; color: #167a57; }
.s4 { background: #fdeceb; color: #b42318; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); margin: 0 0 6px; font-size: 15px; }
.empty p { margin: 0; font-size: 13px; }

.facts { display: grid; grid-template-columns: 170px 1fr; gap: 10px 16px; margin: 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list li { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.docs li { display: flex; gap: 14px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.docs li div { flex: 1; min-width: 0; }
.docs li svg { color: var(--accent); }
.switch { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

/* --- Модальные окна --- */
dialog { border: 0; border-radius: 18px; padding: 24px; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgba(20, 22, 28, 0.45); }
.modalhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modalhead h2 { font-size: 17px; }
.close { border: 0; background: #f2f3f5; width: 32px; height: 32px; border-radius: 10px; font-size: 18px; }
.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.formgrid .wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 14px; }
.chatlog { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.message { max-width: 85%; padding: 10px 13px; border-radius: 14px; background: #f0f1f4; align-self: flex-start; overflow-wrap: anywhere; }
.message.right { align-self: flex-end; background: var(--accent-soft); }
.message p { margin: 4px 0 0; white-space: pre-wrap; }
.docpreview { max-width: 100%; max-height: 65vh; display: block; margin: 0 auto 10px; border-radius: 10px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: white; padding: 12px 18px; border-radius: 12px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 10; }
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Адаптив: телефон команды --- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  aside { position: fixed; inset: auto 0 0 0; width: auto; height: 64px; padding: 0 6px; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); z-index: 5; overflow-x: auto; }
  aside .brand, .sidefoot { display: none; }
  nav { display: flex; margin: 0; gap: 2px; }
  nav a { flex-direction: column; gap: 2px; padding: 8px 10px; font-size: 10px; white-space: nowrap; position: relative; }
  nav .full { display: none; }
  nav .short { display: inline; }
  nav b { position: absolute; top: 4px; right: 4px; padding: 0 5px; font-size: 9px; }
  #toast { bottom: 80px; }
  .main { margin-left: 0; padding-bottom: 70px; }
  header { padding: 0 16px; }
  main { padding: 18px 14px 30px; }
  .stats { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
  .search { min-width: 0; width: 100%; }
  .formgrid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) { button, a { transition: background 0.15s, color 0.15s, border-color 0.15s; } }

/* --- Чат поддержки (модуль support.js) --- */
.support-grid { display: grid; grid-template-columns: minmax(230px, 32%) 1fr; border-top: 1px solid #eee; min-height: 480px; }
.support-threads { border-right: 1px solid #eee; max-height: 620px; overflow: auto; }
.support-thread { display: grid; gap: 6px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #eee; background: white; padding: 18px; color: #343941; }
.support-thread.selected { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: 15px; }
.support-thread strong { font-size: 13px; }
.support-thread span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; color: var(--muted); }
.support-thread b { font-size: 10px; color: #dc441f; font-weight: 600; }
.support-chat { padding: 20px; display: flex; flex-direction: column; min-width: 0; }
.support-chat h3 { margin: 0 0 16px; font-size: 14px; }
.support-history { height: 330px; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px; }
.support-message { max-width: 85%; padding: 12px 14px; border-radius: 14px; background: #f0f1f4; align-self: flex-start; overflow-wrap: anywhere; }
.support-message.from-support { align-self: flex-end; background: var(--accent-soft); }
.support-message p { white-space: pre-wrap; margin: 5px 0; font-size: 13px; }
.support-message small { font-size: 10px; }
.support-compose { border-top: 1px solid #eee; padding-top: 14px; display: grid; gap: 12px; }
.support-compose[hidden] { display: none; }
.support-compose button { justify-self: end; }
.support-error { padding: 12px 20px; background: #fff1ee; color: #c84428; font-size: 12px; }
.support-empty { padding: 20px; color: var(--muted); font-size: 12px; }
.support-inbox [data-support-status] { font-size: 11px; color: #6f7580; }
@media (max-width: 760px) {
  .support-grid { grid-template-columns: 1fr; }
  .support-threads { border-right: 0; border-bottom: 1px solid #eee; max-height: 200px; }
  .support-chat { padding: 16px; }
  .support-message { max-width: 95%; }
}
