:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --primary: #111827;
  --primary-hover: #1f2937;
  --accent: #4f46e5;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot, .loading { padding: 48px; text-align: center; color: var(--muted); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 18px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

label { display: block; font-weight: 500; font-size: 13px; color: #374151; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(79,70,229,.25); border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
input[type=checkbox] { display: inline-block; width: auto; margin: 0 6px 0 0; vertical-align: middle; }
input[type=color] { padding: 2px; height: 38px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.form-error { color: var(--danger); min-height: 1em; margin: 8px 0 0; font-size: 13px; }
.req { display: flex; flex-wrap: wrap; align-items: baseline; }
.req::after { content: "*"; color: var(--danger); margin-left: 3px; }
.req > input, .req > select, .req > textarea { order: 1; flex-basis: 100%; }

/* ---------- Login ---------- */
body.login-page { background: linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #312e81 100%); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); padding: 32px; border-radius: 16px; box-shadow: var(--shadow-lg); display: grid; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; background: var(--primary); color: #fff; font-weight: 800; font-size: 12px; letter-spacing: .5px; }
.brand strong { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }
.brand.big { margin-bottom: 8px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 0 8px 18px; }
.sidebar .brand .logo { background: #fff; color: var(--sidebar); }
.sidebar .brand strong { color: #fff; }
.sidebar .brand small { color: #94a3b8; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--sidebar-text); font-weight: 500; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.nav a .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; color: #fff; flex: 1; min-width: 0; text-decoration: none !important; padding: 4px; border-radius: 8px; }
.user-chip:hover { background: rgba(255,255,255,.06); }
.user-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .btn { color: var(--sidebar-text); }
.side-foot .btn:hover { background: rgba(255,255,255,.06); }
.avatar { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #6366f1; color: #fff; font-size: 11px; font-weight: 700; }

main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: rgba(244,245,247,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions input { margin: 0; width: 240px; height: 36px; }
.menu-btn { display: none; }
#view { padding: 20px 24px 48px; }

/* ---------- Tarjetas / paneles ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel-head h3 { font-size: 15px; }
.panel-body { padding: 16px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 500; font-size: 13px; text-decoration: none !important; }
.pill:hover { background: var(--surface-2); }
.pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pill .sw { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-nuevo { background: #e0e7ff; color: #3730a3; }
.st-en_curso { background: #dbeafe; color: #1d4ed8; }
.st-en_espera { background: #fef3c7; color: #92400e; }
.st-revision { background: #ede9fe; color: #6d28d9; }
.st-cerrado { background: #d1fae5; color: #065f46; }
.prio { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.prio::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.pr-baja { color: #6b7280; }
.pr-normal { color: #2563eb; }
.pr-alta { color: #ea580c; }
.pr-urgente { color: #dc2626; }
.tno { white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); font-weight: 600; }
.overdue { color: var(--danger); font-weight: 600; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none !important; color: var(--text); }
.kpi small { color: var(--muted); font-weight: 500; }
.kpi strong { display: block; font-size: 26px; margin-top: 4px; }
.kpi.warn strong { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.bars .bar i { display: block; width: 100%; max-width: 26px; background: #6366f1; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar span { font-size: 10px; color: var(--muted); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafc; }
td .title { font-weight: 600; color: var(--text); }
tr.inactive td { opacity: .5; }
.num { text-align: right; white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 10px; padding: 14px 16px; }
.filters label { font-size: 12px; color: var(--muted); }
.filters .row2 { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.filters .row2 label { width: 150px; }

/* ---------- Pipeline (kanban) ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(215px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: #eceef2; border-radius: 12px; display: flex; flex-direction: column; max-height: calc(100vh - 190px); min-height: 200px; }
.col-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px; }
.col-head h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.col-head .count { font-size: 12px; font-weight: 700; color: var(--muted); background: #fff; border-radius: 999px; padding: 1px 8px; }
.col-body { padding: 4px 8px 10px; overflow-y: auto; display: grid; gap: 8px; align-content: start; flex: 1; border-radius: 0 0 12px 12px; transition: background .15s; }
.col.drag-over .col-body { background: rgba(99,102,241,.12); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; box-shadow: var(--shadow); cursor: pointer; display: grid; gap: 6px; border-left: 3px solid var(--c, var(--border)); }
.card:hover { border-color: var(--border-strong); border-left-color: var(--c); }
.card.dragging { opacity: .4; }
.card h4 { font-size: 14px; font-weight: 600; word-break: break-word; }
.card-top, .card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; }
.card-foot { font-size: 12px; color: var(--muted); }

/* ---------- Detalle ticket ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.detail-head { display: grid; gap: 8px; }
.detail-head h2 { font-size: 22px; word-break: break-word; }
.detail-head .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.desc { white-space: pre-wrap; word-break: break-word; }
.resolution { background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 8px; padding: 12px; margin-top: 12px; }
.resolution strong { display: block; color: #065f46; margin-bottom: 4px; }
.side-form { display: grid; gap: 12px; }
.side-actions { display: grid; gap: 8px; margin-top: 4px; }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; }
.info-list dt { color: var(--muted); font-size: 13px; }
.info-list dd { margin: 0; font-weight: 500; }

.timeline { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 32px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.tl-item:last-child { border-bottom: 0; }
.tl-item .tl-icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.tl-head { font-size: 13px; color: var(--muted); }
.tl-head b { color: var(--text); }
.tl-body { margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.tl-item.comment .tl-body { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.tl-item.time .tl-icon { background: #ecfdf5; color: var(--success); border-color: #a7f3d0; }
.comment-form { display: grid; gap: 8px; margin-top: 12px; }
.comment-form .row { display: flex; justify-content: flex-end; }
.time-list { display: grid; gap: 6px; margin-top: 8px; }
.time-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; padding: 6px 8px; background: var(--surface-2); border-radius: 6px; }

/* ---------- Modal y toasts ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(15,23,42,.45); display: grid; place-items: center; padding: 16px; animation: fade .12s ease-out; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; }
@keyframes fade { from { opacity: 0; } }

#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: grid; gap: 8px; }
.toast { background: var(--primary); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 360px; animation: fade .15s ease-out; }
.toast.error { background: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .detail, .grid-2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters > label:first-child { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .shell.menu-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-block; }
  .topbar { padding: 10px 16px; }
  .top-actions form { display: none; }
  #view { padding: 16px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .board { grid-auto-columns: 82vw; }
}
