/* ==========================================================================
   Northlink Soporte — Hoja de estilos
   Mismos tokens que northlink.com.ar: papel cálido, arcilla como acento,
   Newsreader (títulos) + DM Sans (texto), íconos de trazo.
   ========================================================================== */

:root {
  --paper:        #f9f8f4;
  --ivory:        #f0eee6;
  --surface:      #ffffff;
  --ink:          #141413;
  --ink-2:        #3d3d3a;
  --muted:        #6b6a65;
  --line:         #e6e3d9;
  --line-strong:  #d6d2c4;

  --clay:         #d97757;
  --clay-hover:   #c4623f;
  --clay-soft:    #f8e9e1;
  --clay-ink:     #9a4a2f;

  --sage:         #b9c7b0;
  --sage-soft:    #e8ede4;
  --sage-ink:     #3f5a38;

  --ok:           #3f9d5d;
  --ok-soft:      #e3f1e7;
  --warn-soft:    #f6ecd3;
  --warn-ink:     #7a5a12;
  --err-soft:     #fbe4dc;
  --err-ink:      #a33a1f;

  --font-serif: "Newsreader", "Iowan Old Style", "Times New Roman", serif;
  --font-sans:  "DM Sans", "Helvetica Neue", Arial, sans-serif;

  --radius-sm: 10px;
  --radius:    16px;
  --radius-lg: 24px;

  --shadow-sm: 0 1px 2px rgba(20, 20, 19, 0.04), 0 2px 8px rgba(20, 20, 19, 0.04);
  --shadow:    0 2px 4px rgba(20, 20, 19, 0.04), 0 12px 32px rgba(20, 20, 19, 0.08);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur:  0.4s;

  --container: 1140px;
  --gutter:    clamp(16px, 4vw, 40px);
  --header-h:  72px;
}

/* ─── Base ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font-family: var(--font-sans); font-size: 16px; line-height: 1.6;
  color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
main { flex: 1; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
ul { margin: 0; padding: 0; list-style: none; }
p, h1, h2, h3, h4, dl, dd { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.icon { width: 1.15em; height: 1.15em; flex: 0 0 auto; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.container { width: min(100% - var(--gutter) * 2, var(--container)); margin-inline: auto; }
.page { padding-block: 40px 72px; }
.narrow { max-width: 640px; margin-inline: auto; }

.skip-link {
  position: absolute; left: 16px; top: -60px; padding: 10px 14px;
  background: var(--ink); color: var(--paper); border-radius: var(--radius-sm); z-index: 100;
  transition: top 0.2s var(--ease);
}
.skip-link:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--clay); outline-offset: 3px; }

h1, h2, h3, .page-title {
  font-family: var(--font-serif); font-weight: 400; letter-spacing: -0.015em;
  line-height: 1.12; text-wrap: balance;
}
.page-title { font-size: clamp(1.9rem, 1.5rem + 1.8vw, 2.8rem); }
h3, .card-title { font-size: 1.35rem; line-height: 1.2; }
h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 600; }

.eyebrow {
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--clay-ink); margin-bottom: 12px;
}

/* ─── Botones ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 22px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: 0.96rem; line-height: 1; cursor: pointer; white-space: nowrap;
  transition: transform var(--dur) var(--ease), background-color 0.25s, border-color 0.25s, box-shadow 0.25s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); transition-duration: 0.1s; }
.btn-primary { background: var(--clay); color: #fff; }
.btn-primary:hover { background: var(--clay-hover); box-shadow: 0 8px 24px rgba(217, 119, 87, 0.28); }
.btn-ghost { background: transparent; border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--ivory); border-color: var(--ink); }
.btn-sm { padding: 9px 15px; font-size: 0.88rem; }
.btn-block { width: 100%; }

/* ─── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px); backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 100%; gap: 24px; }

.brand { display: inline-flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--ink); color: var(--paper);
  display: grid; place-items: center; transition: transform var(--dur) var(--ease), background-color 0.3s;
}
.brand-mark svg { width: 22px; height: 22px; }
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.04); background: var(--clay); }
.brand-name { font-family: var(--font-serif); font-size: 1.35rem; letter-spacing: -0.01em; }
.brand-app {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--clay-ink); background: var(--clay-soft); padding: 3px 9px; border-radius: 999px;
}

.site-nav { display: flex; align-items: center; gap: 28px; }
.site-nav ul { display: flex; gap: 26px; }
.site-nav ul a { font-size: 0.95rem; font-weight: 500; color: var(--ink-2); position: relative; padding: 6px 0; }
.site-nav ul a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1.5px; background: var(--ink);
  transform: scaleX(0); transform-origin: left; transition: transform var(--dur) var(--ease);
}
.site-nav ul a:hover::after, .site-nav ul a.is-active::after { transform: scaleX(1); }
.site-nav ul a:hover, .site-nav ul a.is-active { color: var(--ink); }
.nav-user { display: flex; align-items: center; gap: 12px; }
.nav-user form { margin: 0; }
.nav-user-name { display: inline-flex; align-items: center; gap: 8px; font-size: 0.92rem; color: var(--ink-2); }
.nav-user-name:hover { color: var(--clay-ink); }

.nav-toggle {
  display: none; width: 44px; height: 44px; border: 1px solid var(--line-strong);
  background: var(--surface); border-radius: 12px; cursor: pointer; place-items: center;
}

/* ─── Tarjetas, formularios ──────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; box-shadow: var(--shadow-sm);
}
.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 18px; }
.field label { font-size: 0.86rem; font-weight: 500; color: var(--ink-2); }
.field label small { font-weight: 400; color: var(--muted); }
input:not([type=checkbox]):not([type=hidden]), select, textarea {
  width: 100%; padding: 12px 14px; background: var(--paper); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}
textarea { resize: vertical; min-height: 120px; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--clay); background: var(--surface);
  box-shadow: 0 0 0 4px rgba(217, 119, 87, 0.16);
}
.field-error { display: none; font-size: 0.82rem; color: var(--err-ink); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--clay-hover); }
.field.has-error .field-error { display: block; }
.form-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--ink-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--clay); }
.form-inline { margin-bottom: 28px; }
.card-title { margin-bottom: 4px; }

.alert { padding: 14px 18px; border-radius: var(--radius-sm); border: 1px solid; margin-bottom: 20px; font-size: 0.95rem; overflow-wrap: anywhere; }
.alert-ok    { background: var(--ok-soft);   border-color: rgba(63, 157, 93, 0.35); color: #25613a; }
.alert-error { background: var(--err-soft);  border-color: rgba(217, 119, 87, 0.45); color: var(--err-ink); }
.alert-info  { background: var(--clay-soft); border-color: rgba(217, 119, 87, 0.3);  color: var(--clay-ink); }

/* ─── Login ──────────────────────────────────────────────────────────────── */
body.bare { background: var(--ivory); }
.auth { min-height: calc(100vh - 80px); display: grid; place-items: center; padding: 32px var(--gutter); }
.auth-card { width: min(100%, 440px); padding: 36px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.auth-card .brand { margin-bottom: 14px; }
.auth-card .eyebrow { margin: 0; }
.auth-title { font-size: 2rem; }
.auth-card .form { margin-top: 8px; }
.auth-foot { font-size: 0.88rem; color: var(--muted); margin-top: 6px; }
.auth-foot a { color: var(--clay-ink); text-decoration: underline; text-underline-offset: 3px; }

/* ─── Listado ────────────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 26px; }
.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 14px; border-radius: 999px; font-size: 0.86rem; font-weight: 500;
  border: 1px solid var(--line-strong); color: var(--ink-2); background: transparent;
  transition: background-color 0.2s, border-color 0.2s;
}
.chip:hover { background: var(--ivory); border-color: var(--ink); }
.chip.is-on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.org-filter { width: auto; max-width: 220px; padding: 7px 14px; border-radius: 999px; font-size: 0.86rem; }
.org-link { color: var(--clay-ink); }
.org-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.search { position: relative; flex: 1 1 220px; max-width: 340px; margin-left: auto; }
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 40px !important; border-radius: 999px !important; }

.table-wrap { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th {
  text-align: left; padding: 14px 18px; font-size: 0.74rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted); background: var(--ivory); border-bottom: 1px solid var(--line);
}
.table td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color 0.2s; }
.table tbody tr:hover { background: color-mix(in srgb, var(--ivory) 55%, transparent); }
.table tr.is-off { opacity: 0.55; }
.table td small { display: block; font-size: 0.8rem; }
.cell-subject a { font-weight: 500; }
.cell-subject a:hover { color: var(--clay-ink); }
.code { white-space: nowrap; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85rem; font-weight: 600; color: var(--clay-ink); }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions form, .inline-edit { margin: 0; }
.inline-edit { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-edit select { width: auto; padding: 8px 10px; font-size: 0.88rem; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; font-size: 0.9rem; }

.empty { text-align: center; display: grid; justify-items: center; gap: 10px; padding: 56px 24px; color: var(--ink-2); }
.empty .icon { width: 34px; height: 34px; color: var(--clay); }

/* ─── Insignias ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; white-space: nowrap; background: var(--ivory); color: var(--ink-2);
}
.badge-statuses-abierto           { background: var(--clay-soft); color: var(--clay-ink); }
.badge-statuses-en_curso          { background: var(--sage-soft); color: var(--sage-ink); }
.badge-statuses-esperando_cliente { background: var(--warn-soft); color: var(--warn-ink); }
.badge-statuses-resuelto          { background: var(--ok-soft);   color: #25613a; }
.badge-statuses-cerrado           { background: var(--ivory);     color: var(--muted); }
.badge-priorities-baja            { background: var(--ivory);     color: var(--muted); }
.badge-priorities-media           { background: var(--sage-soft); color: var(--sage-ink); }
.badge-priorities-alta            { background: var(--warn-soft); color: var(--warn-ink); }
.badge-priorities-urgente         { background: var(--err-soft);  color: var(--err-ink); }
.badge-internal                   { background: var(--ink); color: var(--paper); margin-left: auto; }

/* ─── Detalle de ticket ──────────────────────────────────────────────────── */
.back-link { display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); margin-bottom: 22px; }
.back-link:hover { color: var(--ink); }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start; }
.ticket-main { display: flex; flex-direction: column; gap: 16px; }
.ticket-main .page-title { margin-bottom: 8px; }
.ticket-side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: calc(var(--header-h) + 20px); }
.side-card { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; font-size: 0.9rem; align-items: center; }
.meta dt { color: var(--muted); }
.meta dd { text-align: right; overflow-wrap: anywhere; }

.msg { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.msg.is-staff { background: var(--clay-soft); border-color: rgba(217, 119, 87, 0.25); box-shadow: none; }
.msg.is-internal { background: var(--ivory); border-style: dashed; border-color: var(--line-strong); box-shadow: none; }
.msg-head { display: flex; align-items: center; gap: 12px; }
.msg-head small { display: block; font-size: 0.8rem; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--ink); color: var(--paper); font-family: var(--font-serif); font-size: 1.1rem;
}
.is-staff .avatar { background: var(--clay); color: #fff; }
.msg-body { overflow-wrap: anywhere; color: var(--ink-2); }
.event { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.86rem; color: var(--muted); padding-left: 6px; }
.event small { font-size: inherit; }
.reply { margin-top: 8px; }

/* ─── Pie ────────────────────────────────────────────────────────────────── */
.site-footer { border-top: 1px solid var(--line); padding: 22px 0; font-size: 0.85rem; color: var(--muted); }
.site-footer .container { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.site-footer a:hover { color: var(--clay-ink); }
body.bare .site-footer { border: 0; text-align: center; }
body.bare .site-footer .container { justify-content: center; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .ticket-layout { grid-template-columns: 1fr; }
  .ticket-side { position: static; }
}
@media (max-width: 860px) {
  .nav-toggle { display: grid; }
  .site-nav {
    position: fixed; inset: var(--header-h) 0 auto 0; flex-direction: column; align-items: stretch; gap: 20px;
    padding: 20px var(--gutter) 28px; background: var(--paper); border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow); transform: translateY(-12px); opacity: 0; visibility: hidden;
    transition: transform var(--dur) var(--ease), opacity 0.25s, visibility 0.25s;
  }
  .site-nav.is-open { transform: none; opacity: 1; visibility: visible; }
  .site-nav ul { flex-direction: column; gap: 4px; }
  .site-nav ul a { display: block; padding: 12px 0; font-size: 1.05rem; }
  .nav-user { justify-content: space-between; padding-top: 16px; border-top: 1px solid var(--line); }
}
@media (max-width: 700px) {
  .field-row { grid-template-columns: 1fr; }
  .card { padding: 22px; }
  .search { max-width: none; margin-left: 0; flex-basis: 100%; }
  .brand-app { display: none; }

  /* Tablas como tarjetas apiladas */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 14px 18px; border-bottom: 1px solid var(--line); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td { padding: 5px 0; border: 0; display: flex; justify-content: space-between; gap: 16px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; text-align: left; }
  .table td.cell-subject { display: block; text-align: left; }
  .table td.cell-subject::before { display: none; }
  .table td.actions { justify-content: flex-start; padding-top: 10px; }
  .table td.actions::before { display: none; }
  .inline-edit { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
