:root {
  --bg: #f3f6fb;
  --bg-secondary: #e8eef8;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --sidebar: #0f172a;
  --sidebar-muted: #94a3b8;
  --line: #d7dfeb;
  --text: #0f172a;
  --muted: #5b6b82;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #15803d;
  --danger: #b91c1c;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius-lg: 3px;
  --radius-md: 3px;
  --radius-sm: 2px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.1), transparent 24%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 48%, var(--bg-secondary) 100%);
}

body {
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}

.auth-card {
  width: min(1100px, 100%);
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 3px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-copy {
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(239, 246, 255, 0.88)),
    var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

.hero-copy::after {
  content: "";
  position: absolute;
  inset: auto -60px -60px auto;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.16), transparent 68%);
  pointer-events: none;
}

.hero-copy h1,
.content-header h2,
.section-head h3,
.ticket-head h3,
.auth-form h2 {
  margin: 0;
  font-size: clamp(1.9rem, 3vw, 2.8rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.content-header h2,
.section-head h3,
.ticket-head h3,
.auth-form h2 {
  font-size: 1.15rem;
}

.lead {
  margin: 8px 0 0;
  max-width: 54ch;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.demo-box {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: #f8fbff;
  border: 1px solid var(--line);
}

.auth-form,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.ticket-detail {
  padding: 12px;
}

.auth-form {
  display: grid;
  gap: 8px;
  padding: 16px;
  align-content: center;
}

.stack-form {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.inline-form {
  padding: 8px 0 0;
}

.inline-delete-form {
  margin-top: 7px;
}

label {
  display: grid;
  gap: 8px;
}

fieldset {
  margin: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fbff;
}

legend {
  padding: 0 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

label span,
.ticket-meta-grid article span,
.stat-pill span,
.ticket-row span,
.attachment-card span,
.attachment-card small {
  color: var(--muted);
  font-size: 0.78rem;
}

input,
textarea,
select {
  width: 100%;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(37, 99, 235, 0.6);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

textarea {
  resize: vertical;
  min-height: 110px;
}

button {
  appearance: none;
  border: 0;
  padding: 7px 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.2);
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.danger-button {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  box-shadow: 0 10px 22px rgba(185, 28, 28, 0.18);
}

.warning-button {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 10px 22px rgba(217, 119, 6, 0.18);
}

.secondary-button {
  background: linear-gradient(135deg, #475569, #334155);
  box-shadow: 0 10px 22px rgba(51, 65, 85, 0.18);
}

.eyebrow {
  margin: 0 0 7px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.58rem;
  color: var(--primary);
  font-weight: 700;
}

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

.sidebar {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px 11px;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(17, 24, 39, 0.96)),
    var(--sidebar);
  color: #e5edf8;
  border-right: 1px solid rgba(148, 163, 184, 0.14);
}

.sidebar .eyebrow,
.sidebar-note {
  color: var(--sidebar-muted);
}

.sidebar h1 {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.user-card,
.menu a {
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.04);
}

.user-card {
  display: grid;
  gap: 4px;
  padding: 8px;
}

.role-badge {
  width: fit-content;
  padding: 4px 6px;
  border-radius: 3px;
  background: rgba(37, 99, 235, 0.2);
  color: #bfdbfe;
  font-size: 0.68rem;
  border: 1px solid rgba(96, 165, 250, 0.24);
}

.menu {
  display: grid;
  gap: 5px;
}

.menu a {
  padding: 7px 8px;
  color: #dce7f7;
}

.menu a.active,
.menu a:hover {
  background: rgba(37, 99, 235, 0.16);
  border-color: rgba(96, 165, 250, 0.28);
}

.sidebar-note {
  font-size: 0.74rem;
  line-height: 1.4;
}

.content {
  padding: 14px;
}

.content-header,
.section-head,
.ticket-head,
.section-head p {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.ticket-head {
  align-items: start;
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(180px, 3fr);
}

.ticket-head > div,
.ticket-head-main {
  flex: 1;
  min-width: 0;
}

.ticket-title-box {
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid rgba(220, 38, 38, 0.12);
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(255, 248, 248, 0.98), rgba(255, 255, 255, 0.98));
}

.ticket-head h3 {
  font-size: 1.32rem;
  line-height: 1.15;
}

.ticket-head-side {
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 8px 10px;
  border: 1px solid rgba(59, 130, 246, 0.12);
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(239, 246, 255, 0.95), rgba(255, 255, 255, 0.98));
  text-align: left;
}

.ticket-head-side span,
.ticket-head-side small {
  color: var(--muted);
}

.content-header {
  margin-bottom: 12px;
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-pill {
  min-width: 84px;
  padding: 7px 8px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
}

.stat-pill strong {
  font-size: 0.9rem;
}

.flash {
  margin-bottom: 8px;
  padding: 7px 8px;
  border-radius: 3px;
  border: 1px solid transparent;
}

.flash.success {
  background: rgba(22, 163, 74, 0.1);
  color: var(--success);
  border-color: rgba(22, 163, 74, 0.18);
}

.flash.error {
  background: rgba(220, 38, 38, 0.08);
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.16);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 12px;
}

.dashboard-side {
  display: grid;
  gap: 12px;
}

.dashboard-grid > .panel {
  padding: 12px;
}

.dashboard-grid > .panel .section-head {
  margin-bottom: 8px;
}

.filter-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fbff;
}

.filter-actions {
  display: grid;
  align-content: end;
  gap: 5px;
}

.text-link {
  color: var(--primary);
  font-weight: 700;
}

.compact-form {
  padding-top: 0;
}

.client-admin {
  padding: 12px;
}

.users-page {
  padding: 12px;
}

.users-layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 12px;
  margin-top: 10px;
}

.users-create-panel,
.users-list-panel {
  min-width: 0;
}

.users-list-panel .client-list {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.client-list {
  display: grid;
  gap: 8px;
  margin-top: 5px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.client-card {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fbff;
}

.client-card-head {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.client-card strong,
.client-card span,
.client-card small {
  display: block;
}

.category-preview {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.category-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.12);
}

.client-card-meta {
  display: grid;
  gap: 4px;
  justify-items: end;
}

.client-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.client-state.active {
  color: #166534;
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.2);
}

.client-state.suspended {
  color: #b45309;
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.24);
}

.client-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 6px;
  align-items: end;
}

.client-form-grid label {
  margin: 0;
}

.client-delete-form {
  display: flex;
  justify-content: flex-end;
}

.client-actions-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.form-row,
.ticket-meta-grid,
.attachment-grid {
  display: grid;
  gap: 8px;
}

.form-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ticket-meta-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 8px 0 10px;
}

.ticket-meta-grid article {
  padding: 8px;
  background: #f1f5f9;
  border: 1px solid #d7e0ea;
  border-radius: 3px;
}

.ticket-meta-grid article strong .status-chip {
  margin-top: 2px;
}

.ticket-body {
  margin-bottom: 12px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(248, 251, 255, 0.95), #ffffff);
  border: 1px solid var(--line);
  border-radius: 3px;
  line-height: 1.45;
}

.ticket-edit-form,
.message-compose-form {
  background: linear-gradient(180deg, rgba(240, 253, 244, 0.96), rgba(236, 253, 245, 0.98));
  border: 1px solid rgba(34, 197, 94, 0.16);
  border-radius: 3px;
}

.ticket-edit-form label,
.message-compose-form label {
  padding: 8px;
  border: 1px solid rgba(34, 197, 94, 0.1);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.45);
}

.ticket-edit-form select,
.ticket-edit-form input[type="file"],
.message-compose-form textarea {
  background: #f7fff9;
}

.ticket-clients-panel {
  margin-bottom: 12px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fbff;
}

.ticket-client-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.ticket-client-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 600;
}

.ticket-client-chip.primary {
  border-color: rgba(37, 99, 235, 0.26);
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary-dark);
}

.client-checklist-grid {
  display: grid;
  gap: 5px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-item {
  display: flex;
  align-items: start;
  gap: 5px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
}

.check-item input {
  width: 14px;
  min-width: 14px;
  margin: 2px 0 0;
  padding: 0;
  box-shadow: none;
}

.check-item span {
  display: grid;
  gap: 2px;
  color: var(--text);
}

.check-item small {
  color: var(--muted);
}

.ticket-list {
  display: grid;
  gap: 6px;
}

.ticket-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px;
  border-radius: 3px;
  background:
    linear-gradient(90deg, rgba(37, 99, 235, 0.08), rgba(59, 130, 246, 0.03) 26%, rgba(255, 255, 255, 0.96) 62%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 251, 255, 0.96));
  border: 1px solid rgba(37, 99, 235, 0.16);
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.ticket-row:hover {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.34);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.09);
}

.ticket-row.has-incoming-message {
  border-left: 3px solid var(--warning, #d97706);
  background:
    linear-gradient(90deg, rgba(245, 158, 11, 0.16), rgba(251, 191, 36, 0.06) 24%, rgba(255, 255, 255, 0.97) 62%),
    linear-gradient(180deg, rgba(255, 251, 235, 0.98), rgba(255, 255, 255, 0.96));
}

.ticket-row strong,
.attachment-card strong {
  display: block;
  margin-bottom: 4px;
}

.ticket-row strong {
  color: #163b7a;
  font-size: 0.92rem;
}

.ticket-row-meta {
  display: grid;
  gap: 4px;
  justify-items: end;
  align-content: center;
  min-width: 88px;
}

.ticket-row-meta small {
  display: block;
  text-align: right;
}

.attention-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 3px 6px;
  border: 1px solid rgba(217, 119, 6, 0.22);
  border-radius: 3px;
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  padding: 4px 6px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--chip-color) 14%, white);
  color: color-mix(in srgb, var(--chip-color) 72%, #0f172a);
  font-weight: 700;
  font-size: 0.7rem;
  border: 1px solid color-mix(in srgb, var(--chip-color) 22%, white);
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  padding: 4px 6px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--chip-color) 12%, white);
  color: color-mix(in srgb, var(--chip-color) 78%, #0f172a);
  font-weight: 700;
  font-size: 0.68rem;
  border: 1px solid color-mix(in srgb, var(--chip-color) 24%, white);
}

.priority-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  padding: 4px 6px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--chip-color) 12%, white);
  color: color-mix(in srgb, var(--chip-color) 78%, #0f172a);
  font-weight: 700;
  font-size: 0.68rem;
  border: 1px solid color-mix(in srgb, var(--chip-color) 24%, white);
}

.attachments {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.conversation {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.message-list {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.message-card {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #ffffff;
}

.message-card.agency {
  border-left: 3px solid #2563eb;
}

.message-card.client {
  border-left: 3px solid #0f766e;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
}

.message-body {
  line-height: 1.45;
  color: var(--text);
}

.attachment-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.attachment-card {
  display: grid;
  gap: 5px;
  padding: 9px;
  border-radius: 3px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--line);
}

.attachment-card a,
.section-head a {
  color: var(--primary);
  font-weight: 700;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

code {
  font-family: Consolas, Monaco, monospace;
}

@media (max-width: 980px) {
  .auth-card,
  .app-shell,
  .dashboard-grid,
  .users-layout,
  .filter-bar,
  .form-row,
  .ticket-meta-grid,
  .client-form-grid,
  .client-checklist-grid {
    grid-template-columns: 1fr;
  }

  .content-header,
  .section-head,
  .ticket-head {
    flex-direction: column;
  }

  .ticket-head {
    grid-template-columns: 1fr;
  }

  .ticket-row {
    flex-direction: column;
    align-items: start;
  }

  .ticket-row-meta {
    justify-items: start;
  }

  .message-meta {
    flex-direction: column;
  }

  .client-card-head,
  .client-delete-form,
  .client-actions-row,
  .client-card-meta {
    justify-content: start;
  }
}
