/* Masesa · Soporte. Tokens de color (claro en :root, oscuro en [data-theme="dark"]); sin estilos en línea (CSP). */
:root {
  --brand: #12338f;        /* azul marino del logo de Masesa (muestreado de logo-masesa.jpg) */
  --brand-ink: #ffffff;
  --brand-soft: #e8edf9;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #d9dfe7;
  --text: #1b1f24;
  --muted: #5b6570;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #1b7a43;
  --ok-soft: #e4f4ea;
  --warn: #8a5a00;
  --warn-soft: #fdf1d8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --brand: #5ab4e5;        /* turquesa del ícono del logo, aclarado para el modo oscuro */
  --brand-ink: #0b1620;
  --brand-soft: #14253d;
  --bg: #0f1419;
  --surface: #171d24;
  --surface-2: #1e2630;
  --border: #2c3744;
  --text: #e8edf2;
  --muted: #9aa7b4;
  --danger: #ff8a80;
  --danger-soft: #3a1f1d;
  --ok: #6fd79a;
  --ok-soft: #173125;
  --warn: #f3c969;
  --warn-soft: #3a2f14;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
p { margin: 0; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; top: 8px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
main:focus { outline: none; } /* el contenido recibe el foco al cambiar de pantalla; no es un control */

/* Cabecera */
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; min-height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: inline-flex; align-items: center; gap: 14px; text-decoration: none; color: var(--text); padding: 8px 0; }
.brand-logo { display: block; height: 40px; width: auto; }
.brand-label { color: var(--muted); font-size: 0.95rem; padding-left: 14px; border-left: 1px solid var(--border); line-height: 1.6; }
:root[data-theme='dark'] .brand-logo { background: #fff; border-radius: 6px; padding: 3px 8px; } /* el logo es JPEG sobre blanco */
.topbar nav { display: flex; gap: 4px; margin-left: 8px; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.topbar nav a[aria-current='page'] { background: var(--brand-soft); color: var(--brand); }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; }
.container.narrow { max-width: 720px; }
.container.wide { max-width: 1600px; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h2 { margin-bottom: 12px; }
.hero { padding: 8px 0 4px; display: grid; gap: 6px; }

/* Formularios */
.form { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; align-content: start; }
.field label, .label { font-weight: 600; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.82rem; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; min-height: 40px; }
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
.error { color: var(--danger); font-size: 0.85rem; }
.check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.check input { width: auto; min-height: 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; } /* campo trampa para bots */

.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 9px 16px; min-height: 40px; border-radius: 8px; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); cursor: pointer; text-decoration: none; }
.button:hover { filter: brightness(1.08); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.button.secondary { background: transparent; color: var(--brand); }
.button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.button.small { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }

.notice { padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.notice.ok { background: var(--ok-soft); border-color: var(--ok); }
.notice.error { background: var(--danger-soft); border-color: var(--danger); color: var(--text); }
.notice.warn { background: var(--warn-soft); border-color: var(--warn); }
.copybox { display: flex; gap: 8px; align-items: center; }
.copybox input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82rem; }

/* Estados y prioridades */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.nuevo { background: var(--brand-soft); color: var(--brand); }
.badge.en-curso { background: var(--warn-soft); color: var(--warn); }
.badge.esperando-cliente { background: var(--danger-soft); color: var(--danger); }
.badge.resuelto { background: var(--ok-soft); color: var(--ok); }
.badge.cerrado { background: var(--surface-2); color: var(--muted); }
.badge.critica { background: var(--danger-soft); color: var(--danger); }
.badge.alta { background: var(--warn-soft); color: var(--warn); }

/* Tickets */
.ticket-head { display: grid; gap: 8px; }
.ticket-id { color: var(--muted); font-weight: 600; letter-spacing: 0.02em; }
.meta-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; overflow-wrap: anywhere; }
.description { white-space: pre-wrap; overflow-wrap: anywhere; }
.layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.event { display: grid; gap: 4px; }
.event .who { font-weight: 600; font-size: 0.9rem; }
.event .when { color: var(--muted); font-size: 0.8rem; margin-left: 8px; font-weight: 400; }
.bubble { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.event.mine .bubble { background: var(--brand-soft); }
.event.internal .bubble { background: var(--warn-soft); border: 1px dashed var(--warn); }
.event.system { color: var(--muted); font-size: 0.85rem; }

.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.file { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.file-name { overflow-wrap: anywhere; font-weight: 500; }
.dropnote { color: var(--muted); font-size: 0.82rem; }
.picked { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 0.88rem; }

/* Tabla del panel */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td .sub { color: var(--muted); font-size: 0.82rem; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.toolbar .field { min-width: 180px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .topbar { flex-wrap: wrap; padding: 8px 16px; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .button { transition: filter 0.15s; }
}
