* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  background: radial-gradient(circle at top right, color-mix(in srgb, var(--primary) 8%, transparent), transparent 45%), var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--secondary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
code, .mono, pre { font-family: 'IBM Plex Mono', monospace; }
pre { white-space: pre-wrap; margin: 0; }

:root {
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 32px -18px var(--shadow-color);
  --shadow-sm: 0 8px 20px -16px var(--shadow-color);
}

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 1.8rem; line-height: 1.15; }
h2 { font-size: 1.45rem; line-height: 1.2; }
h3 { font-size: 1.1rem; line-height: 1.25; }
small, .small { font-size: .85rem; }
.tiny { font-size: .78rem; }
.muted { color: var(--text-muted); }
.eyebrow {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-muted);
  font-weight: 600;
}
.mt-sm { margin-top: .6rem; }
.mt-md { margin-top: 1rem; }
.gap-lg { gap: 1.1rem; }
.wrap { flex-wrap: wrap; }
.danger { color: var(--danger); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}
.form-card-narrow {
  max-width: 860px;
}
[hidden] { display: none !important; }
.inset-card {
  background: var(--surface-alt);
  border-style: dashed;
}
.subtle-card { background: color-mix(in srgb, var(--surface) 75%, var(--surface-alt)); }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.row-actions {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}
.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: .62rem .9rem;
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  transition: transform .15s ease, background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { transform: translateY(-1px); text-decoration: none; }
.btn:disabled { opacity: .65; cursor: default; }
.btn-primary {
  background: var(--primary);
  color: white;
  border-color: color-mix(in srgb, var(--primary) 75%, black);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); }
.btn-block { width: 100%; }
.icon-btn { min-width: 2.4rem; }

input, textarea, select {
  width: 100%;
  margin-top: .35rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: .68rem .78rem;
  font-size: .95rem;
  outline: none;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
}
label { display: block; font-weight: 500; }
.stack-form { display: flex; flex-direction: column; gap: .85rem; }
.stack-form.compact { gap: .65rem; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .85rem;
}
.form-grid .full { grid-column: 1 / -1; }
.filter-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
}
.filter-actions { align-self: end; }
.inline-check { display: flex; align-items: center; gap: .55rem; font-weight: 500; }
.inline-check input { width: auto; margin: 0; }

.flash {
  border-radius: 12px;
  padding: .8rem .9rem;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}
.flash-success { background: color-mix(in srgb, var(--success) 10%, white); border-color: color-mix(in srgb, var(--success) 28%, var(--border)); }
.flash-error { background: color-mix(in srgb, var(--danger) 10%, white); border-color: color-mix(in srgb, var(--danger) 28%, var(--border)); }
.flash-warning { background: color-mix(in srgb, var(--warning) 11%, white); border-color: color-mix(in srgb, var(--warning) 28%, var(--border)); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: .78rem;
  font-weight: 600;
  background: var(--surface);
  text-transform: capitalize;
}
.badge-ok { background: color-mix(in srgb, var(--success) 8%, white); border-color: color-mix(in srgb, var(--success) 30%, var(--border)); }
.badge-muted { background: var(--surface-alt); }
.badge-priority-baja { background: color-mix(in srgb, var(--secondary) 6%, white); }
.badge-priority-media { background: color-mix(in srgb, var(--warning) 8%, white); }
.badge-priority-alta { background: color-mix(in srgb, var(--danger) 8%, white); }
.badge-priority-critica { background: color-mix(in srgb, var(--danger) 15%, white); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.status-nuevo { background: color-mix(in srgb, var(--secondary) 8%, white); }
.status-en-revision, .status-en_progreso, .status-en-progreso { background: color-mix(in srgb, var(--primary) 8%, white); }
.status-esperando-cliente, .status-esperando_cliente { background: color-mix(in srgb, var(--warning) 10%, white); }
.status-resuelto, .status-cerrado { background: color-mix(in srgb, var(--success) 10%, white); }
.status-cancelado { background: color-mix(in srgb, var(--danger) 9%, white); }
.status-reabierto { background: color-mix(in srgb, var(--secondary) 8%, white); }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  padding: .35rem .65rem;
  font-size: .84rem;
}
.chip.active { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }

.grid { display: grid; gap: 1rem; }
.cols-2 { grid-template-columns: 1.25fr .95fr; }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metrics-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 1rem; }
.compact-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-card h2 { margin-top: .2rem; font-size: 1.65rem; }

.card-head { margin-bottom: .85rem; }
.table-wrap { width: 100%; overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 740px; }
.data-table.compact { min-width: 620px; }
.data-table th, .data-table td {
  text-align: left;
  padding: .7rem .65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: .9rem;
}
.data-table th {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.table-sub { color: var(--text-muted); font-size: .78rem; margin-top: .15rem; }
.empty-inline { display: grid; gap: .2rem; padding: .35rem 0; }
.template-preview-cell {
  max-width: 380px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .85rem; }
.timeline li { display: flex; gap: .65rem; align-items: flex-start; }
.timeline-dot {
  width: 10px; height: 10px; border-radius: 50%; margin-top: .35rem;
  background: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 15%, transparent);
}

.centered-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.2rem;
}
.center-card {
  max-width: 560px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.auth-page { min-height: 100vh; }
.auth-shell { display: grid; grid-template-columns: 1fr 1.1fr; min-height: 100vh; }
.auth-panel {
  padding: 2rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
}
.root-auth-shell .auth-panel { max-width: 560px; margin: 0 auto; }
.auth-aside {
  position: relative;
  background: linear-gradient(160deg, color-mix(in srgb, var(--primary) 16%, white), var(--bg));
  border-left: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  padding: 2rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.auth-hero-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(color-mix(in srgb, var(--text) 5%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--text) 5%, transparent) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.8), rgba(0,0,0,.15));
}
.auth-hero-card { position: relative; width: min(480px, 100%); }
.simple-list { margin: .25rem 0 0; padding-left: 1rem; display: grid; gap: .35rem; }
.simple-list li { display: grid; gap: .15rem; }
.simple-list.ordered { display: block; padding-left: 1.1rem; }
.simple-list.ordered li { display: list-item; margin: .3rem 0; }
.separator {
  border: 0;
  border-top: 1px solid var(--border);
  margin: .6rem 0;
}

.workspace-auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr minmax(340px, 460px);
  gap: 1rem;
  padding: 1rem;
}
.workspace-brand-panel,
.workspace-login-panel {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.workspace-brand-panel {
  padding: 1.2rem;
  background:
    radial-gradient(circle at top right, color-mix(in srgb, var(--primary) 10%, transparent), transparent 40%),
    linear-gradient(180deg, color-mix(in srgb, var(--surface) 85%, var(--surface-alt)), var(--surface));
}
.workspace-login-panel { padding: 1.2rem; display:flex; flex-direction:column; justify-content:center; }
.brand-header { display: flex; gap: .9rem; align-items: center; margin-bottom: .8rem; }
.brand-logo { max-height: 56px; width: auto; border-radius: 10px; background: white; border: 1px solid var(--border); padding: .35rem; }
.brand-logo-fallback, .logo-fallback {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--primary) 12%, white);
  color: var(--primary); font-weight: 700;
  border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
}
.feature-tiles { display: grid; gap: .7rem; margin-top: 1rem; }
.tile {
  border-radius: 12px; border: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 70%, var(--surface-alt));
  padding: .8rem;
  display: grid; gap: .25rem;
}
.tile span { color: var(--text-muted); font-size: .88rem; }
.demo-credentials { margin-top: .4rem; }
.demo-credentials summary { cursor: pointer; font-weight: 600; }

.root-page { padding: 1rem; }
.root-layout { max-width: 1200px; margin: 0 auto; display: grid; gap: 1rem; }
.root-layout.narrow { max-width: 720px; }
.root-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.workspace-card { display: grid; gap: .75rem; }
.palette-preview { display: flex; gap: .35rem; }
.palette-preview span { width: 28px; height: 18px; border-radius: 6px; display:block; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}
.sidebar {
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, var(--surface-alt));
  padding: .95rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; gap: .8rem; align-items: center; }
.sidebar-brand-logo img {
  width: 56px; height: 56px; object-fit: contain; border-radius: 12px; background:white; border: 1px solid var(--border); padding:.35rem;
}
.sidebar-nav { display: grid; gap: .35rem; }
.nav-link {
  display: block;
  padding: .65rem .75rem;
  border-radius: 10px;
  color: var(--text);
  border: 1px solid transparent;
}
.nav-link:hover {
  text-decoration: none;
  background: var(--surface);
  border-color: var(--border);
}
.sidebar-footer { margin-top: auto; display: grid; gap: .6rem; }
.user-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: .7rem;
  display: grid;
}
.user-pill small { color: var(--text-muted); }

.app-main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: .8rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--bg) 82%, white);
}
.topbar h1 { font-size: 1.25rem; }
.topbar-sub { font-size: .84rem; color: var(--text-muted); margin-top: .1rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.app-content { padding: 1rem; display: grid; gap: 1rem; }

.ticket-grid { grid-template-columns: 1.3fr .95fr; align-items: start; }
.stack-col { display: grid; gap: 1rem; align-content: start; }
.ticket-hero { display: grid; gap: .95rem; }
.ticket-summary-box {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: .6rem;
}
.ticket-summary-box > div {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  padding: .65rem;
  display: grid;
  gap: .15rem;
}
.ticket-summary-box strong { font-size: .92rem; }
.ticket-description p { white-space: pre-wrap; }
.message-list { display: grid; gap: .7rem; }
.message-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .75rem;
  background: var(--surface);
  display: grid;
  gap: .25rem;
}
.message-card.internal { background: color-mix(in srgb, var(--warning) 6%, white); }
.attachment-list { display: grid; gap: .45rem; margin-top: .35rem; }
.attachment-item {
  display: flex;
  gap: .65rem;
  align-items: flex-start;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 10px;
  padding: .55rem .65rem;
  color: var(--text);
}
.attachment-item:hover {
  text-decoration: none;
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: color-mix(in srgb, var(--primary) 4%, var(--surface-alt));
}
.attachment-item span { display: grid; gap: .1rem; }
.attachment-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: color-mix(in srgb, var(--primary) 10%, white);
  flex-shrink: 0;
}
.template-picker {
  display: grid;
  gap: .55rem;
  padding: .7rem;
}
.template-picker .eyebrow { margin-bottom: .1rem; }
.template-picker-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .65rem;
  align-items: end;
}
.template-picker-grid .row-actions {
  display: flex;
  gap: .45rem;
  align-items: center;
}
.ai-drafts { display: grid; gap: .75rem; margin-top: .85rem; }
.ai-draft-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .75rem;
  background: var(--surface-alt);
  display: grid;
  gap: .35rem;
}
.ai-draft-card pre {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: .55rem;
  background: var(--surface);
  font-size: .8rem;
}
.sticky-card { position: sticky; top: 88px; }
.csat-box {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 12px;
  padding: .75rem;
  display: grid;
  gap: .35rem;
}
.csat-rating {
  letter-spacing: .08em;
  color: color-mix(in srgb, var(--warning) 85%, black);
  font-size: 1.1rem;
}
.audit-meta {
  font-size: .75rem;
  border: 1px dashed var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  padding: .45rem;
  margin-top: .35rem;
}

.branding-grid { align-items: start; }
.palette-grid { display: grid; gap: .65rem; margin-top: .45rem; }
.palette-option { display: block; }
.palette-option input { display: none; }
.palette-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .65rem;
  background: var(--surface);
  display: grid;
  gap: .35rem;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.palette-option input:checked + .palette-card {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 10%, transparent);
}
.palette-card:hover { transform: translateY(-1px); }
.palette-swatches { display: flex; gap: .3rem; }
.palette-swatches span { width: 24px; height: 16px; border-radius: 999px; border: 1px solid rgba(0,0,0,.04); }
.login-preview-card {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 85%, var(--surface-alt)), var(--surface));
  padding: 1rem;
  display: grid;
  gap: .8rem;
}
.preview-top { display: flex; gap: .75rem; align-items: center; }
.preview-logo { max-height: 50px; width: auto; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: .2rem; }
.fake-form { display: grid; gap: .55rem; }
.fake-form input { background: var(--surface-alt); }
.fake-form button { pointer-events: none; }

.preset-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .75rem;
  background: var(--surface-alt);
  display: grid;
  gap: .35rem;
}
.quick-ticket-grid { align-items: start; }
.selectable-chips { margin-top: .25rem; }

.mobile-fab {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
}

@media (max-width: 1100px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-2, .ticket-grid { grid-template-columns: 1fr; }
  .sidebar { width: 280px; position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; z-index: 50; box-shadow: 0 20px 50px -30px rgba(0,0,0,.25); }
  .sidebar.open { transform: translateX(0); }
  .app-shell { grid-template-columns: 1fr; }
  .topbar { padding-left: .8rem; }
  .topbar-actions { margin-left: auto; }
}

@media (min-width: 1101px) {
  [data-sidebar-toggle] { display: none; }
}

@media (max-width: 860px) {
  .auth-shell, .workspace-auth-shell { grid-template-columns: 1fr; }
  .auth-aside { min-height: 260px; }
  .form-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .ticket-summary-box { grid-template-columns: 1fr; }
  .template-picker-grid { grid-template-columns: 1fr; }
  .compact-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-inline { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 640px) {
  .app-content, .root-page { padding: .75rem; }
  .card { padding: .85rem; border-radius: 12px; }
  .topbar h1 { font-size: 1.08rem; }
  .topbar-actions .btn { padding: .55rem .75rem; }
  .metrics-grid, .compact-metrics { grid-template-columns: 1fr; }
  .mobile-hide { display: none; }
  .workspace-brand-panel { order: 2; }
  .workspace-login-panel { order: 1; }
  .data-table { min-width: 560px; }
}
