:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e3e5e8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #7c3aed;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #059669;
  --pri-low: #6b7280;
  --pri-normal: #2563eb;
  --pri-high: #d97706;
  --pri-urgent: #dc2626;
  --status-open: #2563eb;
  --status-in_progress: #d97706;
  --status-closed: #6b7280;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.nav { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.nav-cat { width: 24px; height: 24px; color: var(--text); }
nav a { color: var(--muted); text-decoration: none; margin-left: 18px; font-size: 14px; }
nav a:hover { color: var(--text); }

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: 40px 20px 28px;
  margin-bottom: 28px;
  background:
    radial-gradient(ellipse at top, rgba(124, 58, 237, 0.08) 0%, transparent 60%),
    linear-gradient(180deg, #ffffff 0%, #f0f2f6 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}
.hero::before,
.hero::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.35;
  pointer-events: none;
}
.hero::before { background: #60a5fa; top: -40px; left: -40px; }
.hero::after  { background: #f59e0b; bottom: -40px; right: -40px; }

.caats-mark {
  width: 240px;
  height: auto;
  display: block;
  margin: 0 auto 12px;
  position: relative;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.12));
}
.caats-title {
  position: relative;
  font-size: 46px;
  font-weight: 800;
  letter-spacing: 0.14em;
  margin: 4px 0 0;
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 50%, #d946ef 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.caats-tagline {
  position: relative;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.04em;
}

/* Blink animation: both eyes squint shut briefly every ~5.5s */
.caats-mark .eyes {
  transform-origin: 160px 100px;
  animation: caats-blink 5.5s ease-in-out infinite;
}
@keyframes caats-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  94%, 97%      { transform: scaleY(0.06); }
}
@media (prefers-reduced-motion: reduce) {
  .caats-mark .eyes { animation: none; }
}

.form-heading { font-size: 22px; margin: 0 0 6px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.optional { color: var(--muted); font-weight: normal; font-size: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 16px;
}
.card.narrow { max-width: 380px; margin-left: auto; margin-right: auto; }
.card.center { text-align: center; }
.card.danger { border-color: #fecaca; }

label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 500; color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=file], textarea, select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
textarea { resize: vertical; min-height: 120px; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .row { grid-template-columns: 1fr; } }

button {
  font: inherit;
  font-weight: 500;
  padding: 9px 18px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); text-decoration: none; display: inline-block; padding: 9px 18px; border-radius: 6px; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }

.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; font-size: 14px; }
.flash-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.flash-success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }

/* Dashboard */
.dashboard-header { margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 9px 14px;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .count {
  display: inline-block;
  background: var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
  margin-left: 4px;
  color: var(--text);
}
.tab.active .count { background: var(--primary); color: white; }

table.tickets {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
table.tickets th, table.tickets td { padding: 10px 14px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--border); }
table.tickets th { background: #fafbfc; color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
table.tickets tr:last-child td { border-bottom: 0; }
table.tickets .row-link { cursor: pointer; }
table.tickets .row-link:hover { background: #fafbfc; }
table.tickets .subject { font-weight: 500; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  text-transform: capitalize;
  color: white;
}
.pri-low { background: var(--pri-low); }
.pri-normal { background: var(--pri-normal); }
.pri-high { background: var(--pri-high); }
.pri-urgent { background: var(--pri-urgent); }
.status-open { background: var(--status-open); }
.status-in_progress { background: var(--status-in_progress); }
.status-closed { background: var(--status-closed); }

/* Ticket detail */
.ticket-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.meta { display: grid; grid-template-columns: 140px 1fr; gap: 6px 16px; margin: 16px 0; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.description {
  white-space: pre-wrap;
  background: #fafbfc;
  padding: 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 14px;
}
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.actions { margin-top: 8px; }

/* Message thread */
.thread { margin-bottom: 18px; }
.msg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.msg.msg-admin {
  background: #eff6ff;
  border-color: #bfdbfe;
}
.msg-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}
.msg-author { font-weight: 500; color: var(--text); font-size: 13px; }
.msg-when { font-size: 12px; }
.msg-body { white-space: pre-wrap; font-size: 14px; }

/* Attachments */
.attachment-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}
.attachment-grid.small .attachment { width: 90px; }
.attachment-grid.small .attachment img { height: 90px; }
.attachment {
  display: block;
  width: 140px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  transition: transform 0.1s, border-color 0.1s;
}
.attachment:hover { transform: translateY(-1px); border-color: var(--primary); }
.attachment img {
  display: block;
  width: 100%;
  height: 110px;
  object-fit: cover;
  background: #fafbfc;
}
.attachment-name {
  font-size: 11px;
  padding: 6px 8px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dashboard indicators column */
.indicators span { margin-right: 8px; font-size: 12px; }

input[type=file] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 6px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: #fafbfc;
}
input[type=file]:hover { border-color: var(--primary); }

.admin-footer {
  text-align: center;
  padding: 16px;
  margin-top: 32px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  border-top: 1px solid var(--border);
}

.check-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  flex-wrap: wrap;
}
.check-cta .muted { margin: 0; }
.check-cta a.btn-secondary { padding: 7px 14px; font-size: 13px; }

.success-banner {
  background: linear-gradient(180deg, #ecfdf5 0%, #f0fdf4 100%);
  border-color: #a7f3d0;
  text-align: center;
  margin-bottom: 24px;
}
.success-banner h1 { color: var(--success); margin-top: 0; }

.required-mark { color: var(--danger); font-weight: 700; }
.dashboard-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
  margin-bottom: 8px;
}
.dashboard-filters input[type=text],
.dashboard-filters select {
  width: auto;
  display: inline-block;
  margin-top: 0;
}
.dashboard-filters input[type=text] { min-width: 240px; flex: 1; }
.dashboard-filters .small { font-size: 12px; }

table.tickets .code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 500;
}

label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: normal;
  margin-bottom: 12px;
}
label.checkbox input[type=checkbox] {
  width: auto;
  margin: 0;
}
label small.muted {
  display: block;
  font-weight: normal;
  margin-top: 2px;
}

/* SLA badges */
.badge.sla-ok       { background: #dcfce7; color: #166534; }
.badge.sla-warning  { background: #fef3c7; color: #92400e; }
.badge.sla-breached { background: #fee2e2; color: #991b1b; font-weight: 700; }

/* Bulk action bar */
.bulk-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #1f2937;
  color: #f9fafb;
  padding: 10px 14px;
  border-radius: 8px;
  margin: 12px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.bulk-bar select {
  width: auto;
  margin-top: 0;
}
.bulk-col { width: 28px; text-align: center; }
.bulk-col input { transform: scale(1.1); }
table.tickets tr td.bulk-col { vertical-align: middle; }

/* Saved reply picker on ticket page */
.reply-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
  margin-bottom: 4px;
}
.reply-tools select {
  width: auto;
  flex: 1;
  margin: 0;
}

/* System messages in thread */
.msg.msg-system {
  background: #f3f4f6;
  color: #4b5563;
  font-style: italic;
  border-left: 3px solid #9ca3af;
}
.msg.msg-system .msg-author { color: #6b7280; }

/* Report grid */
.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.report-grid .card { margin: 0; }
.report-grid h3 { margin-top: 0; }

label.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
label.inline select {
  width: auto;
  margin-top: 0;
}

@media (max-width: 600px) {
  .caats-title { font-size: 34px; letter-spacing: 0.1em; }
  .caats-mark { width: 200px; }
  .hero { padding: 28px 16px 22px; }
}
