/* =====================================================================
   Soporte · estilos base (mobile-first, sin dependencias)
   ===================================================================== */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #1d2433;
  --muted: #667085;
  --primary: #2856e8;
  --primary-hover: #1f45c2;
  --primary-soft: #eef2fe;
  --success: #067647;
  --success-bg: #12b76a;
  --success-soft: #ecfdf3;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --info: #175cd3;
  --info-soft: #eff8ff;
  --purple: #5925dc;
  --purple-soft: #f4f3ff;
  --p1: #98a2b3;
  --p2: #2e90fa;
  --p3: #f79009;
  --p4: #f04438;
  --radius: 10px;
  --radius-sm: 7px;
  --staff-bg: #eef3ff;
  --staff-border: #c7d5fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 24px -6px rgba(16, 24, 40, .12), 0 4px 8px -4px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1217;
    --surface: #171b22;
    --surface-2: #1e232c;
    --border: #2a303b;
    --border-strong: #3a4250;
    --text: #e6e8ec;
    --muted: #98a1b0;
    --primary: #6189f6;
    --primary-hover: #7d9ef8;
    --primary-soft: #1c2640;
    --success: #47cd89;
    --success-soft: #0f2a1d;
    --danger: #f97066;
    --danger-soft: #3a1714;
    --warning: #fdb022;
    --warning-soft: #33250e;
    --info: #53b1fd;
    --info-soft: #102a43;
    --purple: #a48afb;
    --purple-soft: #231c3d;
    --staff-bg: #18213a;
    --staff-border: #2c3c66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 24px -6px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font: 15px/1.55 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.block { display: block; }
.mono, .code { font-family: var(--mono); }
.break { overflow-wrap: anywhere; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.main { flex: 1; padding-top: 20px; padding-bottom: 40px; }

/* ---------------------------------------------------------------- Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 12px; min-height: 58px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); margin-right: auto; }
.brand:hover { text-decoration: none; }
.brand-logo { display: block; height: 40px; width: auto; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border-radius: 8px; background: var(--primary); color: #fff; flex: none;
}
.nav-toggle {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer;
}
.nav {
  display: none; width: 100%; flex-direction: column; gap: 12px; padding: 8px 0 16px;
}
.nav.is-open { display: flex; }
.nav-links { display: flex; flex-direction: column; gap: 2px; }
.nav-links a {
  padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.nav-links a:hover { background: var(--surface-2); text-decoration: none; }
.nav-links a.is-active { background: var(--primary-soft); color: var(--primary); }
.nav-count {
  display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin-left: 3px;
  border-radius: 999px; background: var(--p4); color: #fff; font-size: .7rem; font-weight: 700;
}
.nav-search {
  display: flex; align-items: center; gap: 6px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--muted);
}
.nav-search input { border: 0; background: transparent; padding: 8px 0; width: 100%; font: inherit; color: var(--text); text-transform: uppercase; }
.nav-search input::placeholder { text-transform: none; }
.nav-search input:focus { outline: none; }
.nav-search:focus-within { border-color: var(--primary); }
.nav-user { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.avatar-link { display: flex; align-items: center; gap: 9px; color: var(--text); min-width: 0; }
.avatar-link:hover { text-decoration: none; }
.nav-user-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.nav-user-text strong { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-user-text small { color: var(--muted); font-size: .75rem; }
.avatar {
  display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .8rem;
}
.avatar-sm { width: 28px; height: 28px; font-size: .7rem; }

@media (min-width: 1100px) {
  .nav-toggle { display: none; }
  .nav { display: flex; flex-direction: row; align-items: center; width: auto; padding: 0; flex: 1; gap: 12px; }
  .brand { margin-right: 4px; }
  .nav-links { flex-direction: row; }
  .nav-links a { padding: 7px 9px; font-size: .9rem; white-space: nowrap; }
  .nav-search { margin-left: auto; width: 190px; }
  .nav-user-text { max-width: 130px; }
}
@media (min-width: 1100px) and (max-width: 1279px) {
  .nav-user-text { display: none; }
}

.footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  padding-top: 18px; padding-bottom: 24px; color: var(--muted); font-size: .82rem; border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------- Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
  font: 600 .92rem/1.2 var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn[data-start-button]:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-success { background: var(--success-bg); color: #fff; }
.btn-success:hover { filter: brightness(.94); }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.btn-xs { min-height: 26px; padding: 3px 8px; font-size: .75rem; font-weight: 500; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- Tarjetas y encabezados */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card-title { font-size: 1rem; margin-bottom: 14px; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px;
}
.page-head p { margin: 0; }
.back-link { display: inline-block; margin-bottom: 10px; color: var(--muted); font-size: .9rem; }

/* ---------------------------------------------------------------- Formularios */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; margin: 0; }
fieldset.field { border: 0; padding: 0; }
.field > label, .field > legend, .field-row > label, .label { font-weight: 600; font-size: .88rem; padding: 0; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.label-note { font-weight: 400; color: var(--muted); }
.label-note.is-required { color: var(--warning); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px; min-height: 42px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input:disabled, input[readonly] { background: var(--surface-2); color: var(--muted); }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--primary); }
.has-error input, .has-error select, .has-error textarea, .dropzone.has-error { border-color: var(--danger); }
.field-error { margin: 0; color: var(--danger); font-size: .83rem; }
.hint { margin: 0; color: var(--muted); font-size: .82rem; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .9rem; }
.check input { width: 17px; height: 17px; }
.field-inline { flex-direction: row; align-items: center; gap: 8px; }
.field-inline label { font-weight: 500; font-size: .85rem; white-space: nowrap; color: var(--muted); }
.field-inline select { min-height: 36px; padding-top: 6px; padding-bottom: 6px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
.narrow { max-width: 760px; }

.form-layout { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
.form-layout .card { display: flex; flex-direction: column; gap: 14px; }
.form-layout .card-title { margin-bottom: 0; }
.ticket-form .form-actions { margin-top: 4px; }

@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 900px) {
  .form-layout { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
}

/* Selector de prioridad */
.priority-picker { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 560px) { .priority-picker { grid-template-columns: 1fr 1fr; } }
.priority-option {
  position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; transition: border-color .15s, background .15s;
}
.priority-option input { position: absolute; opacity: 0; pointer-events: none; }
.priority-dot { flex: none; width: 12px; height: 12px; margin-top: 4px; border-radius: 50%; background: var(--pc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pc) 20%, transparent); }
.priority-text { display: flex; flex-direction: column; line-height: 1.3; }
.priority-text small { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.priority-option:hover { background: var(--surface-2); }
.priority-option:has(input:checked) { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 8%, var(--surface)); box-shadow: 0 0 0 1px var(--pc); }
.priority-option:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.prio-1 { --pc: var(--p1); }
.prio-2 { --pc: var(--p2); }
.prio-3 { --pc: var(--p3); }
.prio-4 { --pc: var(--p4); }

/* Adjuntos (selector) */
.dropzone {
  position: relative; border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.dropzone input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; min-height: 0; }
.dropzone-label { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 12px; text-align: center; color: var(--muted); font-size: .9rem; pointer-events: none; }
.dropzone-label strong { color: var(--primary); }
.dropzone-label small { font-size: .78rem; }
.dropzone.is-drag, .dropzone:focus-within { border-color: var(--primary); background: var(--primary-soft); }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list:empty { display: none; }
.file-list li {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; font-size: .85rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.file-list li img { width: 36px; height: 36px; object-fit: cover; border-radius: 5px; }
.file-list li span { overflow-wrap: anywhere; }
.file-list li.is-bad { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

/* ---------------------------------------------------------------- Alertas */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: .92rem; }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success); }
.alert-error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.alert-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--info); }

/* ---------------------------------------------------------------- Badges y etiquetas */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: .76rem; font-weight: 600; white-space: nowrap; line-height: 1.6;
}
.badge.prio { color: var(--text); background: var(--surface-2); border: 1px solid var(--border); }
.badge.prio::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--pc); }
.badge.prio-4 { color: #fff; background: var(--p4); border-color: var(--p4); }
.badge.prio-4::before { background: #fff; }
.status-abierto { background: var(--info-soft); color: var(--info); }
.status-en_proceso { background: var(--warning-soft); color: var(--warning); }
.status-esperando_cliente { background: var(--purple-soft); color: var(--purple); }
.status-cerrado { background: var(--surface-2); color: var(--muted); }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: .72rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.tag-staff { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.tag-support { background: var(--primary); color: #fff; border-color: transparent; }
.tag-internal { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.tag-muted { opacity: .8; }
.code {
  display: inline-block; font-size: .8rem; font-weight: 700; letter-spacing: .03em; color: var(--primary);
}
.code-lg { font-size: 1rem; padding: 3px 9px; border-radius: 6px; background: var(--primary-soft); }

/* ---------------------------------------------------------------- Filtros */
.filters { margin-bottom: 16px; padding: 14px; }
.filters-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters-grid .field > label { font-size: .78rem; font-weight: 600; color: var(--muted); }
.filters-grid input, .filters-grid select { min-height: 38px; padding-top: 7px; padding-bottom: 7px; font-size: .9rem; }
.field-search { grid-column: 1 / -1; }
.filters-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.filters-actions .muted { margin-right: auto; }
@media (min-width: 760px) {
  .filters-grid { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
  .field-search { grid-column: span 2; }
}

/* ---------------------------------------------------------------- Estadísticas */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1000px) { .stats { grid-template-columns: repeat(6, 1fr); } }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  border-top: 3px solid var(--border-strong); transition: transform .15s, box-shadow .15s;
}
.stat:hover { text-decoration: none; box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-open { border-top-color: var(--info); }
.stat-progress { border-top-color: var(--p3); }
.stat-waiting { border-top-color: var(--purple); }
.stat-urgent { border-top-color: var(--p4); }
.stat-urgent .stat-value { color: var(--danger); }
.stat-closed { border-top-color: var(--success-bg); }

/* ---------------------------------------------------------------- Listado de tickets */
.ticket-list {
  display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.ticket-row {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 13px 16px 13px 14px;
  color: var(--text); border-bottom: 1px solid var(--border); border-left: 4px solid var(--pc, transparent);
  transition: background .12s;
}
.ticket-row:last-child { border-bottom: 0; }
.ticket-row:hover { background: var(--surface-2); text-decoration: none; }
.prio-edge-1 { --pc: var(--p1); }
.prio-edge-2 { --pc: var(--p2); }
.prio-edge-3 { --pc: var(--p3); }
.prio-edge-4 { --pc: var(--p4); }
.ticket-row.is-closed { --pc: var(--border); }
.ticket-row.is-closed .tr-subject { color: var(--muted); }
.tr-number {
  grid-column: 1 / -1; font-size: 1.15rem; font-weight: 800; line-height: 1.1; color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.ticket-row.is-closed .tr-number { color: var(--muted); }
.tr-main { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; grid-column: 1 / -1; }
.tr-subject { font-weight: 600; overflow-wrap: anywhere; }
.tr-meta { font-size: .82rem; color: var(--muted); }
.attach-count { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; color: var(--text); white-space: nowrap; }
.attach-count svg { color: var(--muted); }
.tr-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tr-side { display: flex; flex-direction: column; align-items: flex-end; font-size: .82rem; text-align: right; }
.tr-side small { font-size: .78rem; }
.dot-support {
  font-size: .72rem; font-weight: 700; color: var(--primary); background: var(--primary-soft);
  padding: 0 8px; border-radius: 999px; margin-top: 3px;
}
.dot-new {
  font-size: .7rem; font-weight: 700; color: var(--danger); background: var(--danger-soft);
  padding: 0 7px; border-radius: 999px;
}
@media (min-width: 760px) {
  .ticket-row { grid-template-columns: 72px minmax(0, 1fr) 230px 110px; align-items: center; }
  .tr-number, .tr-main { grid-column: auto; }
}

.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin-top: 16px; }
.page {
  display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 10px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .88rem;
}
.page:hover { text-decoration: none; background: var(--surface-2); }
.page.is-current { background: var(--primary); border-color: var(--primary); color: #fff; }
.page.is-disabled { color: var(--muted); opacity: .5; }
.page.gap { border: 0; background: none; }

.empty-state { text-align: center; padding: 40px 20px; }
.empty-state h2 { font-size: 1.15rem; }
.error-page { max-width: 520px; margin: 40px auto; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--primary); margin: 0; line-height: 1; }

/* ---------------------------------------------------------------- Detalle del ticket */
.ticket-head { margin-bottom: 18px; }
.ticket-head h1 { margin: 8px 0; overflow-wrap: anywhere; }
.ticket-id-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.ticket-number {
  font-size: 2rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; color: var(--primary);
}
.ticket-code { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; }
.ticket-code .mono { font-weight: 600; }
.ticket-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ticket-layout { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
.ticket-aside { display: flex; flex-direction: column; gap: 12px; }
.ticket-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
/* En móvil el equipo de soporte ve primero la gestión; el cliente, la conversación. */
@media (max-width: 899px) {
  .ticket-layout.is-staff .ticket-aside { order: -1; }
}
@media (min-width: 900px) {
  .ticket-layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .ticket-aside { position: sticky; top: 76px; }
}

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.msg {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; scroll-margin-top: 80px;
}
/* Respuestas del equipo de soporte: todo el comentario destacado */
.msg-staff {
  background: var(--staff-bg);
  border-color: var(--staff-border);
  border-left: 4px solid var(--primary);
}
.msg-staff .msg-head strong { color: var(--primary); }
.msg-staff .avatar { background: var(--primary); color: #fff; }
.msg-internal { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); border-left: 3px solid var(--warning); }
.msg-origin { border-top: 3px solid var(--border-strong); }
.msg:target { box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow); }
.msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 8px; font-size: .92rem; }
.msg-body { overflow-wrap: anywhere; line-height: 1.6; }
.msg-body a { word-break: break-all; }
.event {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 0 12px;
  font-size: .82rem; color: var(--muted);
}
.event time { font-size: .78rem; }
.event-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex: none; }

.attachments { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attachment {
  display: flex; align-items: center; gap: 9px; max-width: 260px; padding: 6px 10px 6px 6px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: .82rem;
}
.attachment:hover { border-color: var(--primary); text-decoration: none; }
.attachment img { width: 52px; height: 52px; object-fit: cover; border-radius: 5px; background: var(--surface-2); flex: none; }
.attachment-name { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.attachment-name small { color: var(--muted); }
.file-icon {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 5px;
  background: var(--primary-soft); color: var(--primary); font-size: .66rem; font-weight: 800;
}

.reply-form { gap: 12px; }
.reply-form .card-title { margin-bottom: 0; }
.reply-form.is-internal { background: var(--warning-soft); }
.reply-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px 14px; }
.reply-actions .check { margin-right: auto; }
.closed-note p { margin: 4px 0 12px; }

.details { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px 10px; margin: 0; font-size: .9rem; }
.details dt { color: var(--muted); font-size: .82rem; padding-top: 1px; }
.details dd { margin: 0; min-width: 0; }
.manage-form { gap: 10px; }
.manage-form .card-title { margin-bottom: 2px; }
.manage-form select { min-height: 38px; padding-top: 7px; padding-bottom: 7px; }
.quick-action { margin: 0; }

/* ---------------------------------------------------------------- Tablas (admin) */
.table-card { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-inactive td { opacity: .6; }
.table .actions { text-align: right; }
@media (max-width: 759px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  .table td { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border: 0; text-align: right; }
  .table td::before { content: attr(data-label); font-size: .78rem; color: var(--muted); text-align: left; }
  .table td:first-child { display: block; text-align: left; }
  .table td:first-child::before, .table td.actions::before { content: none; }
  .table .actions { justify-content: flex-end; }
}

.role-help { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: .85rem; }
.role-help ul { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.role-help li { color: var(--muted); }

.category-list { display: flex; flex-direction: column; gap: 10px; }
.category-row { display: grid; grid-template-columns: 1fr 90px; gap: 10px 14px; align-items: end; padding: 14px; }
.category-row .field > label { font-size: .78rem; color: var(--muted); }
.category-row input:not([type="checkbox"]) { min-height: 38px; padding-top: 7px; padding-bottom: 7px; }
.category-flags { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.category-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.category-row.is-inactive { opacity: .65; }
.category-new { border-style: dashed; box-shadow: none; }
@media (min-width: 900px) {
  .category-row { grid-template-columns: minmax(0, 1fr) 90px auto auto; }
  .category-flags, .category-actions { grid-column: auto; padding-bottom: 8px; }
}

/* ---------------------------------------------------------------- Empresas y solicitudes */
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.steps { margin-bottom: 16px; font-size: .9rem; background: var(--staff-bg); border-color: var(--staff-border); }
.steps ol { margin: 6px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 3px; }
.inline-create {
  display: grid; grid-template-columns: 1fr; gap: 12px; align-items: end; margin-bottom: 16px;
}
@media (min-width: 760px) {
  .inline-create { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; }
}
.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.people li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid var(--border);
}
.people li:last-child { border-bottom: 0; }
.people li.is-inactive { opacity: .6; }
.people-main { display: flex; flex-direction: column; flex: 1; min-width: 180px; line-height: 1.35; }
.people-actions { display: flex; gap: 4px; margin-left: auto; }
.people-actions form { margin: 0; }
.ticket-list-flat { box-shadow: none; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tabs a {
  padding: 8px 14px; color: var(--muted); font-weight: 600; font-size: .9rem; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.request-list { display: flex; flex-direction: column; gap: 12px; }
.request { display: grid; grid-template-columns: 1fr; gap: 16px; }
.request h2 { font-size: 1.05rem; }
.request-actions { display: flex; flex-direction: column; gap: 8px; }
.reject-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
@media (min-width: 900px) {
  .request { grid-template-columns: minmax(0, 1fr) 320px; }
  .request-actions { border-left: 1px solid var(--border); padding-left: 16px; }
}

/* ---------------------------------------------------------------- Autenticación */
.guest-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; }
.guest-main .flashes { width: 100%; max-width: 420px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg); padding: 28px 24px;
}
.auth-card-wide { max-width: 620px; }
.guest-main .flashes:has(+ .auth-card-wide) { max-width: 620px; }
.auth-card h1 { font-size: 1.35rem; margin-top: 18px; }
.auth-card .form { margin-top: 18px; }
.auth-brand { display: flex; justify-content: center; }
.auth-logo { display: block; width: 180px; max-width: 70%; height: auto; }
.auth-foot { margin: 18px 0 0; text-align: center; font-size: .9rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
@media print {
  .topbar, .footer, .reply-form, .ticket-aside form, .quick-action, .back-link { display: none !important; }
  .ticket-layout { grid-template-columns: 1fr; }
}
