:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #6b7280;
  --line: #d9dee7;
  --accent: #1677ff;
  --danger: #c2410c;
  --shadow: 0 8px 28px rgba(24, 35, 52, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid rgba(22, 119, 255, .45);
  outline-offset: 2px;
}
button, input, select, textarea {
  font: inherit;
}
button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 9px 13px;
  cursor: pointer;
}
a.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 9px 13px;
}
a.button-link.secondary {
  background: #edf2f7;
  color: var(--ink);
}
button.secondary {
  background: #edf2f7;
  color: var(--ink);
}
button.danger {
  background: var(--danger);
}
button.compact {
  padding: 6px 9px;
  font-size: 12px;
}
button:disabled {
  opacity: .5;
  cursor: not-allowed;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 9px 10px;
}
textarea { resize: vertical; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
}
.brand {
  color: var(--ink);
  font-weight: 700;
}
.topbar nav {
  display: flex;
  gap: 6px;
  flex: 1;
}
.topbar nav a {
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 6px;
}
.topbar nav a.active {
  background: #eef5ff;
  color: var(--accent);
}
.logout { color: var(--muted); }
.page {
  padding: 24px;
}
.readonly-banner {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid #fde68a;
  border-radius: 8px;
  background: #fffbeb;
  color: #92400e;
  font-weight: 600;
}
.page-head {
  margin-bottom: 18px;
}
.page-head.split {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.page-head h1 {
  margin: 0 0 4px;
  font-size: 26px;
}
.page-head p, .muted {
  color: var(--muted);
}
.head-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.metric, .panel, .kanban-column {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric {
  display: block;
  padding: 16px;
  color: var(--ink);
}
.metric span {
  color: var(--muted);
}
.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}
.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.product-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}
.clickable-card, .clickable-row {
  cursor: pointer;
}
.clickable-card {
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
.clickable-card:hover, .clickable-card:focus-visible {
  border-color: rgba(22, 119, 255, .42);
  box-shadow: 0 10px 32px rgba(24, 35, 52, .12);
}
.product-card.clickable-card:hover, .product-card.clickable-card:focus-visible,
.metric.clickable-card:hover, .metric.clickable-card:focus-visible {
  transform: translateY(-1px);
}
.product-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.product-head h2 {
  margin: 0;
  font-size: 17px;
}
.product-head span {
  min-width: 34px;
  border-radius: 999px;
  background: #eef5ff;
  color: var(--accent);
  padding: 4px 9px;
  text-align: center;
  font-weight: 700;
}
.product-stats {
  grid-template-columns: 1fr auto;
  margin: 14px 0;
}
.product-actions {
  display: flex;
  gap: 8px;
}
.bars, .table-wrap, .panel {
  padding: 14px;
}
.bar-row {
  display: flex;
  justify-content: space-between;
  color: var(--ink);
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.table-wrap {
  overflow-x: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}
tr.clickable-row {
  transition: background .16s ease;
}
tr.clickable-row:hover td, tr.clickable-row:focus-visible td {
  background: #f8fbff;
}
.filters {
  display: grid;
  grid-template-columns: 1fr 220px 180px 190px auto;
  gap: 10px;
  margin-bottom: 14px;
}
.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef2f7;
  color: #374151;
  font-size: 12px;
  white-space: nowrap;
}
.status.new { background: #e7f5ff; color: #075985; }
.status.open { background: #eef2ff; color: #3730a3; }
.status.in_progress { background: #fff7ed; color: #9a3412; }
.status.pending { background: #fef9c3; color: #854d0e; }
.status.resolved { background: #dcfce7; color: #166534; }
.status.closed { background: #e5e7eb; color: #374151; }

.kanban {
  display: grid;
  grid-template-columns: repeat(5, minmax(260px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 12px;
}
.kanban-column {
  min-height: 68vh;
}
.kanban-column header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.kanban-column h2 {
  margin: 0;
  font-size: 15px;
}
.dropzone {
  min-height: 60vh;
  padding: 10px;
}
.ticket-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 11px;
  margin-bottom: 10px;
  cursor: grab;
}
.ticket-card.clickable-card {
  cursor: grab;
}
.ticket-card.clickable-card:hover, .ticket-card.clickable-card:focus-visible {
  transform: none;
}
.ticket-card.dragging {
  opacity: .55;
}
.card-top, .badges {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.ticket-card h3 {
  margin: 8px 0 4px;
  font-size: 15px;
}
.badges {
  margin: 10px 0;
  color: var(--muted);
  font-size: 12px;
}
.turn {
  border-radius: 999px;
  padding: 2px 7px;
}
.turn.needs-support {
  background: #fef2f2;
  color: #991b1b;
}
.turn.support-replied {
  background: #ecfdf5;
  color: #047857;
}
.detail-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}
.panel {
  margin-bottom: 18px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 17px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head h2 {
  margin: 0;
}
dl {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0 0 14px;
}
dt {
  color: var(--muted);
}
dd {
  margin: 0;
  overflow-wrap: anywhere;
}
.data-list {
  grid-template-columns: 190px minmax(0, 1fr);
}
.stack {
  display: grid;
  gap: 10px;
}
.conversation {
  display: grid;
  gap: 12px;
}
.attachment-list {
  display: grid;
  gap: 8px;
}
.attachment-list code {
  display: block;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  padding: 9px;
}
.screenshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.screenshot-card {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
}
.screenshot-card:hover, .screenshot-card:focus-visible {
  border-color: rgba(22, 119, 255, .42);
  box-shadow: 0 8px 24px rgba(24, 35, 52, .10);
}
.screenshot-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 6px;
  background: #eef2f7;
}
.screenshot-card span {
  color: var(--muted);
  font-size: 12px;
}
.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}
.message.initial {
  background: #ffffff;
}
.message.from-support {
  border-left: 4px solid var(--accent);
}
.message.from-user {
  border-left: 4px solid #16a34a;
}
.message.deleted {
  opacity: .55;
}
.message header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}
.message header strong {
  color: var(--ink);
}
.message header span {
  font-size: 12px;
  text-align: right;
}
.message p {
  white-space: pre-wrap;
  margin: 10px 0 0;
}
.message-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.message-attachment {
  display: grid;
  gap: 7px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.message-attachment img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 6px;
  background: #eef2f7;
}
.message-attachment span {
  color: var(--muted);
  font-size: 12px;
}
.paste-target {
  display: grid;
  gap: 2px;
  padding: 11px;
  border: 1px dashed #b8c4d6;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
}
.paste-target:focus-visible {
  outline: 2px solid rgba(22, 119, 255, .45);
  outline-offset: 2px;
}
.paste-target strong {
  color: var(--ink);
  font-weight: 600;
}
.reply-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
}
.inline-reply {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.inline-reply-actions {
  display: flex;
  justify-content: flex-end;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, .45);
}
.modal[hidden] {
  display: none;
}
.modal-panel {
  width: min(560px, calc(100vw - 24px));
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}
.modal-head, .modal-actions, .file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  background: #edf2f7;
  color: var(--ink);
}
.drawer-shell {
  position: fixed;
  inset: 0;
  z-index: 45;
}
.drawer-shell[hidden] {
  display: none;
}
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .28);
}
.ticket-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: min(720px, 100vw);
  height: 100%;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 20px;
  background: #ffffff;
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px rgba(15, 23, 42, .18);
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.drawer-head h2 {
  margin: 4px 0;
}
.drawer-head p {
  margin: 0;
  color: var(--muted);
}
.drawer-fields {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px 14px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.drawer-fields dt {
  color: var(--muted);
}
.drawer-fields dd {
  margin: 0;
}
.drawer-section h3 {
  margin: 0 0 10px;
}
.compact-conversation {
  gap: 10px;
}
.drawer-loading, .drawer-error {
  padding: 16px;
  color: var(--muted);
}
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-card {
  width: min(380px, calc(100vw - 24px));
  display: grid;
  gap: 12px;
  padding: 22px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0 0 6px;
}
.error {
  color: var(--danger);
}
@media (max-width: 900px) {
  .metric-grid, .two-col, .detail-grid, .filters {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-wrap: wrap;
  }
}
