*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #000;
  --line: rgba(96,200,255,0.16);
  --line-soft: rgba(96,200,255,0.09);
  --teal: #60c8ff;
  --white: #f2ede6;
  --dim: rgba(242,237,230,0.55);
  --dim-2: rgba(242,237,230,0.38);
  --gold: #e6a817;
  --green: #3a9e4f;
  --red: #e2543f;
  --purple: #b0459e;
  --gray: #6b7280;
  --head: 'Unbounded', sans-serif;
  --body: 'Inter', sans-serif;
  --radius: 4px;
}

html { overflow-x: hidden; }
body {
  background: var(--bg); color: var(--white); font-family: var(--body);
  overflow-x: hidden; min-height: 100vh; font-weight: 400; font-size: 14px; line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; color: inherit; background: transparent; }
a { color: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(96,200,255,0.25); border-radius: 8px; }

/* ---------- shared bits ---------- */

.logo {
  font-family: var(--head); font-weight: 400; font-size: 13px; letter-spacing: 0.06em;
  color: var(--white); text-decoration: none; display: inline-flex; align-items: baseline; gap: 10px;
}
.logo .dot { color: var(--teal); }
.logo .sub { opacity: 0.6; font-weight: 300; }
.logo .portal-tag {
  font-family: var(--head); font-size: 10px; letter-spacing: 0.12em; color: var(--dim-2);
  padding-left: 10px; border-left: 1px solid var(--line);
}

.field { margin-bottom: 20px; }
.field label {
  display: block; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--dim-2); margin-bottom: 10px;
}
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 13px;
  font-size: 14px; color: var(--white); outline: none; transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus { border-color: rgba(96,200,255,0.5); }
.field input::placeholder, .field textarea::placeholder { color: var(--dim-2); }

.btn-primary {
  width: 100%; background: var(--teal); color: #04141f; border: none;
  padding: 13px; border-radius: var(--radius); font-size: 13px; font-weight: 600; letter-spacing: 0.02em;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-new {
  background: rgba(96,200,255,0.1); border: 1px solid rgba(96,200,255,0.3); color: var(--teal);
  padding: 12px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
  transition: background 0.15s;
}
.btn-new:hover { background: rgba(96,200,255,0.18); }

.back-link {
  background: none; border: none; color: var(--dim); font-size: 12px; padding: 0; margin-bottom: 18px;
  display: inline-flex; align-items: center; gap: 6px; transition: color 0.15s;
}
.back-link:hover { color: var(--teal); }

.empty-hint {
  padding: 60px 20px; text-align: center; color: var(--dim-2); font-size: 13px; border: 1px dashed var(--line);
}

.login-error, .form-error, .composer-error, .admin-error {
  font-size: 12px; color: var(--red); background: rgba(226,84,63,0.08); border: 1px solid rgba(226,84,63,0.3);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 16px;
}

.file-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 10px; font-size: 11.5px; color: var(--dim); max-width: 220px;
}
.fc-remove { color: var(--dim-2); background: none; border: none; font-size: 13px; line-height: 1; padding: 0 0 0 2px; }
.fc-remove:hover { color: var(--red); }

/* ---------- badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 10px; letter-spacing: 0.06em;
  padding: 4px 9px; border-radius: 3px; white-space: nowrap; font-weight: 500;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; background: currentColor; }

.badge-status-new { color: var(--teal); background: rgba(96,200,255,0.1); }
.badge-status-in_progress { color: var(--gold); background: rgba(230,168,23,0.12); }
.badge-status-waiting { color: var(--purple); background: rgba(176,69,158,0.14); }
.badge-status-resolved { color: var(--green); background: rgba(58,158,79,0.14); }
.badge-status-closed { color: var(--dim-2); background: rgba(242,237,230,0.06); }

.badge-urgency-normal { color: var(--dim); border: 1px solid var(--line); }
.badge-urgency-urgent { color: var(--red); border: 1px solid rgba(226,84,63,0.5); background: rgba(226,84,63,0.08); }

.badge-role-admin { color: var(--teal); background: rgba(96,200,255,0.1); }
.badge-role-manager { color: var(--gold); background: rgba(230,168,23,0.12); }
.badge-role-user { color: var(--dim); background: rgba(242,237,230,0.06); }

/* ---------- login ---------- */

.login-wrap { position: relative; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: linear-gradient(var(--line-soft) 1px, transparent 1px), linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 0%, #000 20%, transparent 90%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 0%, #000 20%, transparent 90%);
  opacity: 0.6;
}
.login-card { position: relative; z-index: 1; width: 100%; max-width: 380px; }
.login-card .logo { display: flex; justify-content: center; font-size: 16px; margin-bottom: 22px; }
.login-card h1 { font-family: var(--head); font-weight: 300; font-size: 24px; text-align: center; margin-bottom: 10px; }
.login-card .lead { font-size: 13px; color: var(--dim); text-align: center; line-height: 1.6; margin-bottom: 32px; }

.quick-login { margin-top: 32px; border-top: 1px solid var(--line); padding-top: 24px; }
.qh { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim-2); margin-bottom: 14px; }
.quick-user {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  background: none; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; color: var(--white); transition: border-color 0.15s, background 0.15s;
}
.quick-user:hover { border-color: rgba(96,200,255,0.4); background: rgba(96,200,255,0.04); }
.qa {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--head); font-size: 12px; background: rgba(96,200,255,0.12); color: var(--teal);
  border: 1px solid var(--line); flex: 0 0 auto;
}
.qn { font-size: 13px; }
.qc { font-size: 11px; color: var(--dim-2); margin-top: 2px; }
.qrole { margin-left: auto; font-size: 10px; color: var(--dim-2); letter-spacing: 0.04em; white-space: nowrap; }

/* ---------- top nav ---------- */

.top {
  height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 0 28px; border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.7); backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 20;
}
.nav-links { display: flex; align-items: center; gap: 4px; flex: 1 1 auto; }
.nav-link {
  background: none; border: none; color: var(--dim); font-size: 13px; padding: 8px 14px;
  border-radius: var(--radius); transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: var(--white); }
.nav-link.is-active { color: var(--teal); background: rgba(96,200,255,0.08); }

.nav-user { display: flex; align-items: center; gap: 14px; }
.who { text-align: right; line-height: 1.3; }
.who .n { font-size: 13px; color: var(--white); }
.who .c { font-size: 11px; color: var(--dim-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--head); font-size: 12px; flex: 0 0 auto;
  background: rgba(96,200,255,0.12); color: var(--teal); border: 1px solid var(--line);
}
.logout-btn {
  background: none; border: 1px solid var(--line); color: var(--dim);
  font-size: 11px; letter-spacing: 0.06em; padding: 8px 14px; border-radius: var(--radius);
  transition: color 0.15s, border-color 0.15s;
}
.logout-btn:hover { color: var(--teal); border-color: rgba(96,200,255,0.4); }

/* ---------- portal layout ---------- */

.portal { max-width: 1100px; margin: 0 auto; padding: 32px 28px 60px; }
.portal-header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.portal-header h1 { font-family: var(--head); font-weight: 300; font-size: 22px; }
.portal-header .sub { font-size: 12px; color: var(--dim-2); margin-top: 4px; }

/* ---------- ticket list ---------- */

.ticket-list { border-top: 1px solid var(--line); }
.ticket-row {
  display: grid; grid-template-columns: 92px 1fr 130px 150px 100px; gap: 16px; align-items: center;
  padding: 16px 4px; border-bottom: 1px solid var(--line-soft);
  text-align: left; background: none; border-left: none; border-right: none;
  width: 100%; color: inherit; transition: background 0.15s;
}
.ticket-row:hover { background: rgba(96,200,255,0.035); }
.ticket-row .num { font-family: var(--head); font-size: 12px; color: var(--dim); }
.ticket-row .subj-wrap { min-width: 0; }
.ticket-row .subj { font-size: 13.5px; color: var(--white); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-row .meta { font-size: 11px; color: var(--dim-2); margin-top: 3px; }
.ticket-row .date { font-size: 11px; color: var(--dim-2); text-align: right; }

/* ---------- new ticket form ---------- */

.form-card { max-width: 640px; }
.form-card h1 { font-family: var(--head); font-weight: 300; font-size: 22px; margin-bottom: 24px; }
.company-readout { font-size: 14px; color: var(--dim); }

.radio-row { display: flex; gap: 10px; }
.radio-opt {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius); color: var(--dim); font-size: 13px;
  cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.radio-opt input { accent-color: var(--teal); }
.radio-opt.is-active { border-color: rgba(96,200,255,0.5); background: rgba(96,200,255,0.06); color: var(--teal); }
.radio-opt.urgency-urgent.is-active { border-color: rgba(226,84,63,0.6); background: rgba(226,84,63,0.08); color: var(--red); }

.file-drop {
  display: block; border: 1px dashed var(--line); border-radius: var(--radius); padding: 20px;
  text-align: center; cursor: pointer; transition: border-color 0.15s;
}
.file-drop:hover { border-color: rgba(96,200,255,0.4); }
.file-drop input[type=file] { display: none; }
.fd-title { font-size: 13px; color: var(--white); }
.fd-sub { font-size: 11px; color: var(--dim-2); margin-top: 4px; }

/* ---------- ticket detail / chat ---------- */

.ticket-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.ticket-head .num { font-size: 12px; color: var(--dim-2); margin-bottom: 6px; }
.ticket-head h1 { font-family: var(--head); font-weight: 300; font-size: 20px; max-width: 560px; }
.badges { display: flex; gap: 8px; flex: 0 0 auto; }

.specialist-banner, .pending-note, .closed-note {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 20px; background: rgba(96,200,255,0.03);
}
.pending-note, .closed-note { color: var(--dim-2); font-size: 12.5px; border-style: dashed; }
.sp-avatar {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--head); font-size: 12px; background: rgba(96,200,255,0.12); color: var(--teal);
  border: 1px solid var(--line); flex: 0 0 auto;
}
.sp-text { font-size: 12.5px; color: var(--dim); }
.sp-label { color: var(--dim-2); }
.sp-name { color: var(--white); font-weight: 500; }

.chat-thread {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  display: flex; flex-direction: column; gap: 16px; max-height: 480px; overflow-y: auto;
}
.chat-msg { max-width: 72%; display: flex; gap: 10px; align-items: flex-start; }
.chat-msg.from-client { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.from-specialist { align-self: flex-start; }
.chat-msg.from-system { align-self: center; max-width: 90%; }
.chat-msg.from-system .cm-avatar { display: none; }
.chat-msg.from-system .cm-bubble { background: none; border: none; color: var(--dim-2); font-size: 12px; text-align: center; padding: 2px; }
.chat-msg.from-system .cm-head { display: none; }

.cm-avatar {
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--head); font-size: 11px; background: rgba(96,200,255,0.12); color: var(--teal);
  border: 1px solid var(--line); flex: 0 0 auto;
}
.cm-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.chat-msg.from-client .cm-body { align-items: flex-end; }
.cm-head { display: flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--dim-2); }
.cm-name { color: var(--white); font-weight: 500; }
.cm-time { color: var(--dim-2); }
.cm-role { padding: 1px 6px; border-radius: 3px; background: rgba(96,200,255,0.1); color: var(--teal); letter-spacing: 0.03em; }
.cm-bubble { padding: 10px 14px; border-radius: 10px; font-size: 13.5px; line-height: 1.55; }
.chat-msg.from-client .cm-bubble { background: rgba(96,200,255,0.13); border: 1px solid rgba(96,200,255,0.22); border-bottom-right-radius: 2px; }
.chat-msg.from-specialist .cm-bubble { background: rgba(242,237,230,0.05); border: 1px solid var(--line-soft); border-bottom-left-radius: 2px; }
.cm-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cm-att-chip {
  font-size: 11px; color: var(--dim); border: 1px solid var(--line); border-radius: 3px; padding: 4px 8px;
  text-decoration: none; display: inline-block; transition: color 0.15s, border-color 0.15s;
}
.cm-att-chip:hover { color: var(--teal); border-color: rgba(96,200,255,0.4); }

.chat-composer { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.chat-composer textarea {
  width: 100%; border: none; outline: none; resize: none; font-size: 13.5px; min-height: 60px;
  color: var(--white); line-height: 1.5;
}
.chat-composer textarea::placeholder { color: var(--dim-2); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.composer-attach {
  font-size: 12px; color: var(--dim); display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  transition: color 0.15s;
}
.composer-attach:hover { color: var(--teal); }
.composer-send {
  background: var(--teal); color: #04141f; border: none; padding: 9px 20px; border-radius: var(--radius);
  font-size: 12.5px; font-weight: 600; transition: opacity 0.15s;
}
.composer-send:hover { opacity: 0.88; }
.composer-send:disabled { opacity: 0.4; cursor: default; }

/* ---------- admin ---------- */

.admin-filters { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.admin-search {
  flex: 1 1 260px; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 13px;
  font-size: 13px; color: var(--white); outline: none; transition: border-color 0.15s; min-width: 0;
}
.admin-search:focus { border-color: rgba(96,200,255,0.5); }
.admin-search::placeholder { color: var(--dim-2); }
.admin-company-filter {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 13px;
  font-size: 13px; color: var(--white); outline: none; background: #000;
}

.admin-add-form {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; background: rgba(96,200,255,0.03);
}
.admin-add-form .field { grid-column: span 1; }
.admin-add-form select {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 13px;
  font-size: 14px; color: var(--white); background: #000; outline: none;
}
.admin-add-actions { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 4px; }
.btn-cancel {
  background: none; border: 1px solid var(--line); color: var(--dim); padding: 11px 20px;
  border-radius: var(--radius); font-size: 13px; transition: color 0.15s, border-color 0.15s;
}
.btn-cancel:hover { color: var(--white); border-color: rgba(96,200,255,0.4); }
.add-user-error { grid-column: 1 / -1; }

.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; flex-wrap: wrap; gap: 10px; }
.pager-info { font-size: 12px; color: var(--dim-2); }
.pager-btns { display: flex; align-items: center; gap: 12px; }
.pager-btn {
  background: none; border: 1px solid var(--line); color: var(--dim); font-size: 12px;
  padding: 7px 14px; border-radius: var(--radius); transition: color 0.15s, border-color 0.15s;
}
.pager-btn:hover:not(:disabled) { color: var(--teal); border-color: rgba(96,200,255,0.4); }
.pager-btn:disabled { opacity: 0.35; cursor: default; }
.pager-page { font-size: 12px; color: var(--dim-2); }

.admin-table { border-top: 1px solid var(--line); }
.admin-row {
  display: grid; grid-template-columns: 1.2fr 1.6fr 1.2fr 140px 90px 100px; gap: 16px; align-items: center;
  padding: 14px 4px; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.admin-row.admin-head { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim-2); border-bottom: 1px solid var(--line); }
.au-name { color: var(--white); }
.au-email { color: var(--dim); font-size: 12.5px; }
.btn-delete-user {
  background: none; border: 1px solid rgba(226,84,63,0.4); color: var(--red);
  font-size: 11px; padding: 7px 12px; border-radius: var(--radius); transition: background 0.15s;
}
.btn-delete-user:hover { background: rgba(226,84,63,0.1); }
.btn-delete-user:disabled { opacity: 0.5; cursor: default; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .top { padding: 0 16px; gap: 14px; }
  .logo .portal-tag { display: none; }
  .portal { padding: 28px 20px 60px; }

  .ticket-row { grid-template-columns: 70px 1fr 110px 130px 90px; gap: 10px; font-size: 12.5px; }
  .admin-row { grid-template-columns: 1fr 1.4fr 1fr 110px 70px 80px; gap: 10px; font-size: 12.5px; }
  .admin-add-form { gap: 0 10px; }
}

@media (max-width: 700px) {
  .top { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; gap: 8px 14px; }
  .nav-links { order: 3; width: 100%; }
  .who { display: none; }
  .portal { padding: 22px 16px 50px; }
  .portal-header { gap: 12px; }
  .btn-new { width: 100%; text-align: center; }

  .login-wrap { padding: 24px 16px; }
  .quick-user { gap: 10px; }
  .qrole { margin-left: 0; }

  /* ticket list: card layout instead of a 5-column table row */
  .ticket-list { border-top: none; }
  .ticket-row {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 6px 10px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 14px;
  }
  .ticket-row > :nth-child(1) { grid-column: 1 / -1; grid-row: 1; order: 1; opacity: 0.7; }
  .ticket-row > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; order: 2; margin: 2px 0 4px; }
  .ticket-row > :nth-child(3) { grid-column: 1; grid-row: 3; order: 3; justify-self: start; }
  .ticket-row > :nth-child(4) { grid-column: 2; grid-row: 3; order: 4; justify-self: start; }
  .ticket-row > :nth-child(5) { grid-column: 3; grid-row: 3; order: 5; justify-self: end; font-size: 10.5px; }
  .ticket-row:hover { background: rgba(96,200,255,0.05); }

  /* admin users: same card treatment */
  .admin-filters { gap: 10px; }
  .admin-search, .admin-company-filter { width: 100%; flex-basis: 100%; }

  .admin-table { border-top: none; }
  .admin-row.admin-head { display: none; }
  .admin-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 14px;
  }
  .admin-row > :nth-child(1) { grid-column: 1 / -1; } /* имя */
  .admin-row > :nth-child(2) { grid-column: 1 / -1; margin-bottom: 4px; } /* email */
  .admin-row > :nth-child(3) { grid-column: 1; align-self: center; } /* компания */
  .admin-row > :nth-child(4) { grid-column: 2; justify-self: end; } /* роль */
  .admin-row > :nth-child(5) { grid-column: 1; font-size: 11px; color: var(--dim-2); margin-top: 6px; } /* обращений */
  .admin-row > :nth-child(5)::before { content: "Обращений: "; }
  .admin-row > :nth-child(6) { grid-column: 2; justify-self: end; margin-top: 6px; } /* удалить */

  .admin-add-form { grid-template-columns: 1fr; padding: 16px; }
  .admin-add-actions { flex-direction: column; }
  .admin-add-actions button { width: 100%; }

  .pager { gap: 12px; }
  .pager-btns { width: 100%; justify-content: space-between; }

  .form-card .radio-row { flex-direction: column; }

  .chat-thread { max-height: 56vh; padding: 14px; }
  .chat-msg { max-width: 90%; }
  .composer-bar { flex-wrap: wrap; gap: 8px; }
  .composer-send { width: 100%; }

  .ticket-head { gap: 10px; }
  .ticket-head h1 { font-size: 18px; max-width: 100%; }
}

@media (max-width: 420px) {
  .top { padding: 0 12px; }
  .logo { font-size: 11px; }
  .portal { padding: 18px 12px 44px; }
  .portal-header h1, .form-card h1 { font-size: 19px; }
  .login-card h1 { font-size: 21px; }
  .login-card { max-width: 100%; }

  .ticket-row, .admin-row { padding: 12px; font-size: 12px; }
  .qc, .qrole { font-size: 10px; }

  .chat-thread { max-height: 50vh; padding: 12px; }
  .cm-bubble { font-size: 13px; }
}
