:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d8deea;
  --primary: #176b87;
  --primary-dark: #104f65;
  --accent: #c2410c;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --shadow: 0 16px 44px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

a {
  color: var(--primary);
  text-decoration: none;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 0 16px;
  cursor: pointer;
}

.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--text);
  font-weight: 800;
  font-size: 20px;
}

.nav {
  display: flex;
  gap: 18px;
  align-items: center;
}

.nav a {
  color: var(--text);
  font-weight: 700;
}

.link-button {
  min-height: auto;
  border: 0;
  padding: 0;
  color: var(--danger);
  background: transparent;
}

.danger-button {
  border-color: #fecaca;
  background: #fff5f5;
  color: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.page {
  width: min(1120px, calc(100% - 32px));
  margin: 32px auto 64px;
}

.auth-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  align-items: center;
  gap: 48px;
  min-height: calc(100vh - 160px);
}

h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 52px);
  line-height: 1.04;
}

.page-head h1 {
  font-size: 34px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.center {
  text-align: center;
}

.panel,
.ticket-row,
.metric,
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel,
.form-wide,
.reply-form,
.user-form,
.status-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

label {
  display: grid;
  gap: 8px;
  color: #344054;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

input[type="file"] {
  padding: 8px;
}

textarea {
  resize: vertical;
}

.field-help {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.paste-drop-zone {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 14px;
  text-align: center;
}

.paste-drop-zone:focus,
.paste-drop-zone.dragging {
  border-color: var(--primary);
  color: var(--primary);
  outline: 0;
}

.attachment-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.preview-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.preview-item img {
  width: 100%;
  height: 120px;
  object-fit: contain;
  border-radius: 6px;
  background: #f8fafc;
}

.preview-item span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.flash {
  margin-bottom: 20px;
  border-radius: 6px;
  padding: 12px 14px;
  font-weight: 700;
}

.flash.success {
  background: #dcfce7;
  color: #14532d;
}

.flash.error {
  background: #fee2e2;
  color: #7f1d1d;
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.list {
  display: grid;
  gap: 12px;
}

.ticket-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  color: var(--text);
}

.ticket-row span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
}

.row-tags {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 800;
}

.badge {
  background: #eef2f7;
  color: #344054;
}

.status.open {
  background: #dbeafe;
  color: #1e40af;
}

.status.in_progress {
  background: #fef3c7;
  color: var(--warning);
}

.status.waiting_client {
  background: #ede9fe;
  color: #5b21b6;
}

.status.closed {
  background: #dcfce7;
  color: var(--success);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric {
  display: grid;
  gap: 8px;
  padding: 16px;
  color: var(--text);
}

.metric strong {
  font-size: 30px;
}

.metric.active {
  border-color: var(--primary);
}

.thread {
  display: grid;
  gap: 14px;
  margin: 20px 0;
}

.message {
  width: min(760px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
}

.admin-message {
  margin-left: auto;
  border-color: #b7d7df;
  background: #eef9fb;
}

.message header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.message header span {
  color: var(--muted);
  font-size: 13px;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
}

.attachments {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.attachment {
  display: grid;
  gap: 6px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.attachment img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 6px;
  background: #f8fafc;
}

.attachment span {
  color: var(--muted);
  font-size: 13px;
}

.status-form {
  grid-template-columns: minmax(180px, 260px) auto;
  align-items: end;
  width: fit-content;
}

.user-form {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
  margin-bottom: 24px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

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

th {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

.blocked-row {
  background: #fff7f7;
}

.user-status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
}

.user-status.active {
  background: #dcfce7;
  color: var(--success);
}

.user-status.blocked {
  background: #fee2e2;
  color: var(--danger);
}

.actions-cell {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.inline-password-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 8px;
}

.actions-cell input,
.actions-cell button {
  min-height: 36px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  .topbar,
  .page-head,
  .ticket-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .auth-shell {
    grid-template-columns: 1fr;
    gap: 24px;
    min-height: auto;
  }

  .metrics,
  .user-form {
    grid-template-columns: 1fr;
  }

  .status-form {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .nav {
    flex-wrap: wrap;
  }
}
