:root {
  --bg: #f4f8f7;
  --bg-soft: #eef6f4;
  --surface: #ffffff;
  --surface-soft: #f8fbfa;
  --surface-muted: #eef5f4;
  --text: #172136;
  --muted: #66758a;
  --line: #dbe7e8;
  --line-strong: #c4d5d9;
  --primary: #0b778d;
  --primary-strong: #07586a;
  --primary-soft: #e0f3f5;
  --accent: #42b883;
  --accent-soft: #e5f8ef;
  --nav: #07323c;
  --nav-soft: #114955;
  --green: #227a55;
  --red: #bd3d36;
  --amber: #a86512;
  --blue: #2268a8;
  --shadow-sm: 0 8px 24px rgba(16, 48, 57, .06);
  --shadow-md: 0 18px 48px rgba(16, 48, 57, .1);
  --shadow-lg: 0 30px 90px rgba(8, 52, 62, .22);
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
  --radius: 8px;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 4%, rgba(66, 184, 131, .14), transparent 270px),
    radial-gradient(circle at 92% 0%, rgba(11, 119, 141, .12), transparent 340px),
    linear-gradient(180deg, #fbfdfd 0%, var(--bg) 48%, #edf5f2 100%);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(66, 184, 131, .24); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #edf4f4; }
::-webkit-scrollbar-thumb { background: #bfd2d7; border-radius: 999px; border: 2px solid #edf4f4; }
::-webkit-scrollbar-thumb:hover { background: #9fb9c0; }

button, input, select, textarea { font: inherit; }

button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #12869d, var(--primary));
  color: white;
  padding: 10px 15px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
  transition: background .18s ease, box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}

button:hover {
  background: linear-gradient(180deg, #0f7186, var(--primary-strong));
  box-shadow: 0 12px 24px rgba(13, 120, 144, .2);
  transform: translateY(-1px);
}

button:active { transform: translateY(0); }

button.secondary {
  background: #e8f0f3;
  color: #223247;
  box-shadow: none;
}

button.secondary:hover {
  background: #dbe8ed;
  box-shadow: none;
}

button.danger,
#confirmDeleteUser {
  background: linear-gradient(180deg, #c84a43, var(--red));
  color: white;
}

button.danger:hover,
#confirmDeleteUser:hover {
  background: linear-gradient(180deg, #b63c36, #98302b);
  box-shadow: 0 12px 24px rgba(189, 61, 54, .2);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(13, 120, 144, .2);
  outline-offset: 2px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 20px; }
.success { color: var(--green); min-height: 20px; }

.eyebrow {
  display: inline-flex;
  color: var(--primary);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 800;
  font-size: .92rem;
  color: #263449;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: white;
  color: var(--text);
  font-weight: 650;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

input:hover, select:hover, textarea:hover { border-color: rgba(13, 120, 144, .42); }

input:focus, select:focus, textarea:focus {
  border-color: rgba(13, 120, 144, .62);
  box-shadow: 0 0 0 4px rgba(13, 120, 144, .08);
}

textarea { resize: vertical; line-height: 1.45; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px;
  background:
    linear-gradient(90deg, rgba(0, 24, 31, .12) 0%, rgba(0, 24, 31, .28) 42%, rgba(2, 31, 40, .94) 62%, #021f28 100%),
    url("assets/login-agro-tech.png") center / cover no-repeat,
    #032b34;
}

.login-panel {
  width: min(1180px, 100%);
  min-height: min(710px, calc(100vh - 80px));
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(360px, 480px);
  gap: 70px;
  align-items: center;
}

.login-intro {
  min-height: 520px;
  display: grid;
  align-content: center;
  justify-items: start;
  color: white;
}

.login-intro > * { visibility: hidden; }

.logo-plate {
  width: min(260px, 70vw);
  min-height: 82px;
  display: grid;
  place-items: center;
  margin-bottom: 28px;
  padding: 18px 24px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #0d2f3a, #0f7186);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

.logo-plate img { width: 100%; height: auto; display: block; }

.login-panel h1 {
  margin: 18px 0 14px;
  max-width: 560px;
  font-size: 5rem;
  line-height: .9;
  letter-spacing: 0;
  color: white;
  text-shadow: 0 16px 40px rgba(0, 0, 0, .38);
}

.login-panel p {
  margin: 0;
  max-width: 470px;
  color: rgba(255, 255, 255, .88);
  font-size: 1.1rem;
  line-height: 1.45;
}

.login-panel .eyebrow { color: #6dd18b; }

.stack {
  display: grid;
  gap: 18px;
  align-content: center;
  padding: 42px;
  border: 1px solid rgba(190, 230, 236, .28);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(5, 43, 54, .88), rgba(8, 67, 76, .64));
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.form-heading { display: grid; gap: 8px; margin-bottom: 10px; }
.form-heading strong { font-size: 1.35rem; color: var(--text); line-height: 1.1; }
.form-heading span { color: var(--muted); font-size: 1rem; line-height: 1.4; }
.login-panel .form-heading { text-align: center; }
.login-panel .form-heading strong { font-size: 2.45rem; color: white; }
.login-panel .form-heading span { color: rgba(255, 255, 255, .68); font-size: 1.06rem; }
.login-panel label { color: white; }

.login-panel input {
  min-height: 56px;
  border-color: rgba(198, 230, 235, .28);
  background: rgba(255, 255, 255, .1);
  color: white;
}

.login-panel input::placeholder { color: rgba(255, 255, 255, .58); }

.password-field {
  position: relative;
  display: block;
}

.password-field input { padding-right: 104px; }

.password-field button {
  position: absolute;
  top: 50%;
  right: 8px;
  min-height: 40px;
  transform: translateY(-50%);
  border: 1px solid rgba(198, 230, 235, .3);
  background: rgba(255, 255, 255, .1);
  color: rgba(255, 255, 255, .88);
  padding: 8px 12px;
  box-shadow: none;
}

.password-field button:hover {
  background: rgba(255, 255, 255, .16);
  box-shadow: none;
  transform: translateY(-50%);
}

.login-panel button[type="submit"] {
  min-height: 58px;
  margin-top: 4px;
  background: linear-gradient(90deg, #5bd08d, #21bb84);
  color: white;
  font-size: 1.08rem;
  box-shadow: 0 16px 34px rgba(42, 196, 124, .24);
}

.login-panel button[type="submit"]:hover { background: linear-gradient(90deg, #6bd99b, #25c78d); }
.login-panel .muted { color: rgba(255, 255, 255, .66); line-height: 1.35; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
}

.app > *,
.content,
.sidebar,
.topbar,
.view-section,
.panel {
  min-width: 0;
  max-width: 100%;
}

.sidebar {
  position: sticky;
  top: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 32px 12px, rgba(66, 184, 131, .18), transparent 180px),
    linear-gradient(180deg, var(--nav-soft), var(--nav));
  color: white;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, .08);
}

.brand {
  display: grid;
  gap: 12px;
  align-items: center;
}

.brand img {
  width: 178px;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .1);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
}

.brand span {
  color: #d8edf1;
  font-weight: 900;
  letter-spacing: .01em;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  position: relative;
  min-height: 44px;
  text-align: left;
  background: transparent;
  color: #cde4e9;
  border: 1px solid transparent;
  overflow: hidden;
  box-shadow: none;
  padding-left: 16px;
}

.nav-item::before {
  content: "";
  position: absolute;
  inset: 9px auto 9px 0;
  width: 3px;
  border-radius: 999px;
  background: transparent;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, .105);
  color: white;
  border-color: rgba(255, 255, 255, .13);
  box-shadow: none;
}

.nav-item.active::before { background: var(--accent); }
.nav-item.active { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .04); }

.user-box {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: #cde4e9;
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .095);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
}

.user-box strong { color: white; }

.content {
  min-width: 0;
  padding: 24px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.app.view-new .content {
  padding: 12px 18px 18px;
  gap: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.topbar h2 {
  margin: 5px 0 4px;
  font-size: 2rem;
  line-height: 1.1;
}

.topbar p { margin: 0; color: var(--muted); }

.app.view-new .topbar {
  padding: 14px 18px;
}

.app.view-new .topbar h2 {
  margin: 3px 0 2px;
  font-size: 1.85rem;
}

.app.view-new .topbar p {
  font-size: .92rem;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.bell-button {
  position: relative;
  width: 48px;
  height: 44px;
  min-width: 48px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.bell-button.has-notifications {
  background: var(--accent-soft);
  color: var(--green);
  animation: bellPulse 1.6s ease-in-out infinite;
}

.bell-icon {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notification-count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--red);
  color: white;
  font-size: .72rem;
  font-weight: 900;
  border: 2px solid white;
}

@keyframes bellPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 122, 85, .22); }
  50% { box-shadow: 0 0 0 7px rgba(34, 122, 85, 0); }
}

.view-section {
  display: grid;
  gap: 16px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.card,
.panel {
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease;
}

.card:hover,
.panel:hover {
  border-color: rgba(11, 119, 141, .22);
  box-shadow: var(--shadow-md);
}

.card:hover { transform: translateY(-2px); }

.card {
  position: relative;
  overflow: hidden;
  padding: 18px;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.card span {
  color: var(--muted);
  font-size: .9rem;
  font-weight: 800;
}

.card strong {
  display: block;
  margin-top: 9px;
  font-size: 2rem;
  line-height: 1;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.chart-list {
  display: grid;
  gap: 13px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(100px, 180px) 1fr 42px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
}

.bar-row strong { color: #314158; }

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #e7eff2;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: white;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .85);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: white;
}

th, td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

tbody tr { transition: background .16s ease; }
tbody tr:hover { background: #f0faf8; }
tbody tr:last-child td { border-bottom: 0; }

th {
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: #f8fbfb;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: .76rem;
  font-weight: 900;
  background: #e8eef5;
  color: #334155;
  white-space: nowrap;
}

.badge.atendimento,
.badge.em-atendimento { background: #dbeafe; color: var(--blue); }
.badge.concluido { background: #dcfce7; color: var(--green); }
.badge.cancelado { background: #fee2e2; color: var(--red); }
.badge.urgente,
.badge.alta { background: #fef3c7; color: var(--amber); }
.badge.role-admin { background: #e0f2fe; color: #075985; }
.badge.role-tecnico { background: #dcfce7; color: var(--green); }
.badge.role-solicitante { background: #f1f5f9; color: #475569; }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .86);
  box-shadow: var(--shadow-sm);
}

.filters select { max-width: 240px; }
.filters input[type="search"] { flex: 1 1 280px; }

.form-panel { max-width: 1040px; }

.ticket-form {
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.form-actions,
.row-actions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  align-items: center;
}

#newSection {
  width: 100%;
  max-width: none;
  gap: 10px;
}

#newSection .form-panel {
  width: 100%;
  max-width: none;
  padding: 18px 18px 14px;
  box-shadow: var(--shadow-sm);
}

#newSection .new-ticket-form {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 13px 14px;
  align-items: start;
}

#newSection label {
  gap: 6px;
}

#newSection input,
#newSection select,
#newSection textarea {
  padding: 10px 12px;
}

#newSection textarea {
  min-height: 156px;
  max-height: 230px;
}

#newSection .form-grid {
  grid-template-columns: minmax(180px, 1fr) minmax(240px, 1.2fr);
  gap: 14px;
}

#newSection .field-title {
  grid-column: 1 / -1;
  grid-row: auto;
}

#newSection .field-description {
  grid-column: 1 / -1;
  grid-row: auto;
}

#newSection .field-meta {
  grid-column: 1 / span 5;
  grid-row: auto;
}

#newSection .field-attachment {
  grid-column: 6 / -1;
  grid-row: auto;
}

#newSection .request-actions {
  grid-column: 1 / -1;
  grid-row: auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding-top: 0;
}

#newSection input[type="file"] {
  min-height: 42px;
  padding: 7px 10px;
  background: white;
  color: #41516a;
  font-size: .92rem;
  font-weight: 800;
}

#newSection input[type="file"]::file-selector-button {
  min-height: 30px;
  margin-right: 10px;
  border: 0;
  border-radius: 7px;
  background: #e8f0f3;
  color: #223247;
  padding: 6px 10px;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
}

#newSection .request-message {
  grid-column: 1 / -1;
  grid-row: auto;
  min-height: 20px;
  margin: 0;
}

#newSection .request-message:empty {
  display: none;
}

.check-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfe;
}

.check-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  font-weight: 800;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
}

.check-list input { width: auto; }

.service-comment {
  display: grid;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.workflow-actions {
  display: grid;
  gap: 12px;
  padding-top: 2px;
}

.chat-launch {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.chat-launch h3 { margin: 0 0 4px; }
.chat-launch p { margin: 0; }

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

.attachment-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
}

.attachment-item small {
  color: var(--muted);
  font-weight: 800;
}

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

.comment-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfe;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8);
}

.comment-item strong { display: block; }
.comment-item small { color: var(--muted); }
.comment-item p { margin: 8px 0 0; }

dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  width: min(920px, calc(100vw - 26px));
  max-width: calc(100vw - 26px);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgba(8, 52, 62, .56);
  backdrop-filter: blur(4px);
}

.dialog-card {
  background: white;
}

#ticketDialog .dialog-card {
  max-height: min(92vh, 860px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.chat-card {
  min-height: min(720px, calc(100vh - 42px));
  display: grid;
  grid-template-rows: auto 1fr;
}

.dialog-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  padding: 20px 28px 18px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f7fbfc);
}

.dialog-header h3 { margin: 10px 0 0; }

.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  justify-self: end;
  align-self: start;
  margin-top: 0;
  margin-right: 2px;
  background: #e8eef5;
  color: var(--text);
  box-shadow: none;
}

.icon-btn:hover {
  background: #dbe8ed;
  box-shadow: none;
  transform: none;
}

.dialog-body {
  padding: 18px 20px 20px;
  display: grid;
  gap: 16px;
}

#ticketDialog .dialog-body {
  max-height: calc(92vh - 112px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfdfe;
  min-width: 0;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  margin-bottom: 5px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
}

.history {
  display: grid;
  gap: 10px;
}

.history-item {
  border-left: 3px solid var(--primary);
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.history-item strong { display: block; }
.history-item small { color: var(--muted); }

.chat-messages {
  min-width: 0;
  min-height: 320px;
  max-height: 46vh;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f7fafb;
}

.chat-message {
  width: min(78%, 560px);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  box-shadow: 0 8px 20px rgba(15, 47, 58, .05);
}

.chat-message.own {
  justify-self: end;
  border-color: rgba(13, 120, 144, .24);
  background: var(--primary-soft);
}

.chat-message div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.chat-message small {
  color: var(--muted);
  font-weight: 800;
}

.chat-message p {
  margin: 8px 0 0;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-form {
  display: grid;
  gap: 12px;
}

.chat-form textarea { min-width: 0; }

.direct-chat-card {
  width: min(940px, calc(100vw - 26px));
  max-width: calc(100vw - 26px);
  overflow: hidden;
}

#directChatDialog .dialog-header,
#chatDialog .dialog-header {
  padding-right: 30px;
}

.direct-chat-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: min(640px, calc(100vh - 130px));
  min-width: 0;
  overflow: hidden;
}

.direct-chat-users {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #f7fafb;
}

.direct-user-list {
  display: grid;
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
}

.direct-user-item {
  position: relative;
  min-width: 0;
  width: 100%;
  display: grid;
  gap: 3px;
  text-align: left;
  background: white;
  color: var(--text);
  border: 1px solid var(--line);
  padding-right: 42px;
  box-shadow: none;
}

.direct-user-item strong,
.direct-user-item small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.direct-user-item:hover,
.direct-user-item.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
  box-shadow: none;
}

.direct-user-item small {
  color: var(--muted);
  font-weight: 800;
}

.direct-user-unread {
  position: absolute;
  top: 50%;
  right: 10px;
  min-width: 23px;
  height: 23px;
  display: inline-grid;
  place-items: center;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--red);
  color: white;
  font-size: .72rem;
  font-weight: 900;
}

.direct-chat-main {
  min-width: 0;
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 18px;
  overflow: hidden;
}

.direct-chat-main h3 { margin: 0; }

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #newSection .new-ticket-form {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }
  #newSection textarea {
    min-height: 150px;
  }
}

@media (max-width: 920px) {
  .login-shell { padding: 22px; }
  .login-panel {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 0;
  }
  .login-intro { display: none; }
  .stack { width: min(520px, 100%); justify-self: center; padding: 34px; }
  .login-panel .form-heading strong { font-size: 2.1rem; }

  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    min-height: auto;
    padding: 16px;
    gap: 16px;
  }
  .brand {
    grid-template-columns: auto 1fr;
  }
  .brand img { width: 150px; }
  .sidebar nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 3px;
  }
  .nav-item {
    flex: 0 0 auto;
    min-height: 42px;
    white-space: nowrap;
  }
  .nav-item::before { display: none; }
  .user-box {
    margin-top: 0;
    grid-template-columns: 1fr auto;
    align-items: center;
  }
  .user-box span { grid-column: 1; }
  .user-box button { grid-column: 2; grid-row: 1 / span 2; }

  .content { padding: 18px; }
  .app.view-new .content {
    padding: 10px 12px 14px;
    gap: 10px;
  }
  .topbar { align-items: flex-start; }
  .topbar h2 { font-size: 1.9rem; }
  .app.view-new .topbar {
    padding: 12px 14px;
  }
  .grid-two,
  .detail-grid,
  .actions {
    grid-template-columns: 1fr;
  }
  #newSection .new-ticket-form {
    grid-template-columns: 1fr;
  }
  #newSection .field-title,
  #newSection .field-description,
  #newSection .field-meta,
  #newSection .field-attachment,
  #newSection .request-actions,
  #newSection .request-message {
    grid-column: 1;
    grid-row: auto;
  }
  #newSection .field-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #newSection textarea {
    min-height: 170px;
  }
  .direct-chat-layout { grid-template-columns: 1fr; }
  .direct-chat-users {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .direct-user-list { max-height: 180px; }
}

@media (max-width: 620px) {
  body { background: var(--bg); }
  .login-shell { padding: 14px; }
  .stack { padding: 24px; }
  .login-panel .form-heading strong { font-size: 1.85rem; }

  .content,
  .sidebar {
    padding: 14px;
  }
  .app.view-new .content {
    padding: 10px;
  }
  .brand img { width: 132px; }
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
  }
  .topbar h2 { font-size: 1.65rem; }
  .topbar-actions,
  .chat-launch button,
  .form-actions button,
  .filters button,
  .filters select,
  .filters input,
  .row-actions button {
    width: 100%;
    max-width: none;
  }
  .topbar-actions button:not(.bell-button) {
    width: 100%;
    max-width: none;
  }
  .topbar-actions .bell-button {
    width: 48px;
    max-width: 48px;
  }
  .cards,
  .form-grid {
    grid-template-columns: 1fr;
  }
  #newSection,
  #newSection .form-panel {
    max-width: none;
  }
  #newSection .form-grid {
    grid-template-columns: 1fr;
  }
  #newSection .field-meta {
    grid-template-columns: 1fr;
  }
  #newSection .field-meta,
  #newSection .field-attachment,
  #newSection .request-actions {
    padding: 12px;
  }
  #newSection textarea {
    min-height: 150px;
  }
  .panel,
  .card {
    padding: 16px;
  }
  .filters {
    padding: 12px;
  }
  .chat-launch {
    align-items: stretch;
    flex-direction: column;
  }
  .chat-message {
    width: 100%;
  }
  .dialog-header,
  .dialog-body,
  .direct-chat-users,
  .direct-chat-main {
    padding: 14px;
  }
  .dialog-header {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 16px 20px 14px 14px;
  }
  .icon-btn {
    margin-right: 0;
  }
  #ticketDialog .dialog-card {
    max-height: calc(100vh - 26px);
  }
  #ticketDialog .dialog-body {
    max-height: calc(100vh - 118px);
    padding-right: 12px;
  }
  .chat-card {
    min-height: calc(100vh - 26px);
  }
  .chat-messages {
    min-height: 240px;
    max-height: 42vh;
  }
  .password-field input {
    padding-right: 90px;
  }
}

@media (max-width: 420px) {
  .user-box {
    grid-template-columns: 1fr;
  }
  .user-box button {
    grid-column: auto;
    grid-row: auto;
    width: 100%;
  }
  .bar-row {
    grid-template-columns: 1fr 40px;
  }
  .bar-track {
    grid-column: 1 / -1;
    order: 3;
  }
  .password-field button {
    right: 6px;
    padding: 8px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
