/* ============================================================
   MiracleDesk v1.0 — app.css
   White-label: el color de marca vive en --brand (settings).
   ============================================================ */
:root {
  --brand: #3B4FE0;
  --ink: #17203A;
  --ink-soft: #5A6478;
  --line: #E3E7F0;
  --bg: #F4F6FB;
  --panel: #FFFFFF;
  --side: #101A2B;
  --side-ink: #93A0B8;
  --ok: #158A5C; --warn: #C77700; --bad: #C4302B; --hold: #7A6BC4;
  --radius: 10px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.3px; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 700; margin: 0 0 12px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.main { flex: 1; padding: 28px 32px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-soft); margin: 0; }

/* ---------- Sidebar ---------- */
.sidebar { width: 232px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 16px; }
.brand-logo { max-height: 32px; max-width: 150px; }
.brand-icon { width: 34px; height: 34px; border-radius: 8px; }
.brand-name { color: #fff; font-weight: 700; font-size: 15px; letter-spacing: 0.2px; }
.nav { flex: 1; padding: 8px 10px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: var(--side-ink); font-weight: 500; margin-bottom: 2px; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,0.08); display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,0.12); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.user-meta { min-width: 0; display: flex; flex-direction: column; }
.user-meta strong { color: #fff; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { font-size: 11px; }
.logout { color: var(--side-ink); font-size: 12px; font-weight: 600; }
.logout:hover { color: #fff; }

/* ---------- Cards, tablas ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-soft); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #FAFBFE; }
.ticket-no { font-family: var(--mono); font-weight: 600; font-size: 13px; color: var(--brand); white-space: nowrap; }
.muted { color: var(--ink-soft); }
.small { font-size: 12px; }

/* ---------- KPI ---------- */
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .k-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-soft); font-weight: 600; }
.kpi .k-value { font-size: 30px; font-weight: 800; letter-spacing: -1px; margin-top: 4px; }
.kpi .k-hint { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.kpi.accent { border-top: 3px solid var(--brand); }
.kpi.danger .k-value { color: var(--bad); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.st-new { background: #E8ECFF; color: #3346C9; }
.st-assigned { background: #E4F1FF; color: #1268B3; }
.st-in_progress { background: #FFF3DC; color: #9A6700; }
.st-on_hold { background: #EFEAFB; color: var(--hold); }
.st-resolved { background: #DFF5EA; color: var(--ok); }
.st-closed { background: #EDEFF3; color: #5A6478; }
.pr-1 { background: #FBE3E2; color: var(--bad); }
.pr-2 { background: #FFE9D6; color: #B04E00; }
.pr-3 { background: #FFF3DC; color: #9A6700; }
.pr-4 { background: #EDEFF3; color: #5A6478; }
.tp-incident { background: #FBE9F1; color: #B4256E; }
.tp-request { background: #E2F3F5; color: #0E7490; }
.as-in_use { background: #DFF5EA; color: var(--ok); }
.as-in_stock { background: #E8ECFF; color: #3346C9; }
.as-repair { background: #FFF3DC; color: #9A6700; }
.as-retired { background: #EDEFF3; color: #5A6478; }

/* Problemas */
.pb-open { background: #E8ECFF; color: #3346C9; }
.pb-investigating { background: #FFF3DC; color: #9A6700; }
.pb-known_error { background: #EFEAFB; color: var(--hold); }
.pb-resolved { background: #DFF5EA; color: var(--ok); }
.pb-closed { background: #EDEFF3; color: #5A6478; }
/* Cambios */
.ch-draft { background: #EDEFF3; color: #5A6478; }
.ch-pending_approval { background: #FFF3DC; color: #9A6700; }
.ch-approved { background: #DFF5EA; color: var(--ok); }
.ch-rejected { background: #FBE3E2; color: var(--bad); }
.ch-in_progress { background: #E4F1FF; color: #1268B3; }
.ch-completed { background: #DFF5EA; color: var(--ok); }
.ch-failed { background: #FBE3E2; color: var(--bad); }
.ch-cancelled { background: #EDEFF3; color: #5A6478; }
/* Riesgo */
.rk-low { background: #DFF5EA; color: var(--ok); }
.rk-medium { background: #FFF3DC; color: #9A6700; }
.rk-high { background: #FBE3E2; color: var(--bad); }
/* CSAT */
.stars { display: inline-flex; gap: 3px; font-size: 20px; color: #D8DCE6; }
.stars .on { color: #F5A623; }
.survey-stars { display: flex; gap: 8px; justify-content: center; margin: 18px 0; }
.survey-stars label { cursor: pointer; font-size: 34px; color: #D8DCE6; transition: color 0.15s; margin: 0; }
.survey-stars input { display: none; }
.survey-stars label.on, .survey-stars label:hover { color: #F5A623; }
/* Adjuntos */
.attachment { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.attachment:last-child { border-bottom: 0; }
.vote { border-left: 3px solid var(--line); padding: 8px 12px; margin-bottom: 10px; font-size: 13px; }
.vote.approved { border-color: var(--ok); }
.vote.rejected { border-color: var(--bad); }

/* ---------- SLA chip (elemento firma) ---------- */
.sla { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; font-family: var(--mono); white-space: nowrap; }
.sla-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.sla-level { background: rgba(0,0,0,0.09); border-radius: 4px; padding: 1px 5px; margin-right: 2px; font-size: 10px; }
.sla-ok { background: #DFF5EA; color: var(--ok); }
.sla-warning { background: #FFF0DC; color: var(--warn); }
.sla-warning .sla-dot { animation: pulse 1.4s ease-in-out infinite; }
.sla-breached { background: #FBE3E2; color: var(--bad); }
.sla-breached .sla-dot { animation: pulse 0.9s ease-in-out infinite; }
.sla-met { background: #EDEFF3; color: #5A6478; }
.sla-paused { background: #EFEAFB; color: var(--hold); }
.sla-none { background: #EDEFF3; color: #98A1B3; }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .sla-dot { animation: none !important; } }

/* ---------- Formularios ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: var(--ink); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], input[type=color], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea { min-height: 110px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 14px; }
.form-row-3 { grid-template-columns: repeat(3, 1fr); }
.form-field { margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; }
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #F4F6FB; filter: none; }
.btn-danger { background: var(--bad); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .form-field { margin: 0; min-width: 150px; }

/* ---------- Flash ---------- */
.flash { padding: 11px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: #DFF5EA; color: var(--ok); }
.flash-warn { background: #FFF3DC; color: #9A6700; }
.flash-error { background: #FBE3E2; color: var(--bad); }

/* ---------- Ticket detalle ---------- */
.ticket-layout { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.comment { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: #fff; }
.comment.internal { background: #FFFBEB; border-color: #F2E4B6; }
.comment-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 12.5px; }
.comment-body { white-space: pre-wrap; }
.side-info dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-soft); font-weight: 600; margin-top: 12px; }
.side-info dd { margin: 3px 0 0; }
.timeline-item { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 12.5px; }
.timeline-item:last-child { border-bottom: 0; }
.timeline-item .t-when { color: var(--ink-soft); white-space: nowrap; font-family: var(--mono); font-size: 11px; }

/* ---------- Matriz de prioridad ---------- */
.matrix-hint { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12.5px; color: var(--ink-soft); }

/* ---------- Modal ---------- */
.modal { display: none; position: fixed; inset: 0; background: rgba(16,26,43,0.55); z-index: 50; padding: 24px; overflow-y: auto; }
.modal.open { display: grid; place-items: start center; }
.modal-box { background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 640px; margin-top: 4vh; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-close { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--ink-soft); line-height: 1; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--side); }
.login-card { background: #fff; border-radius: 16px; padding: 36px; width: 100%; max-width: 400px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand .brand-mark { width: 42px; height: 42px; font-size: 20px; border-radius: 10px; }
.login-brand h1 { font-size: 20px; }

/* ---------- ACL grid ---------- */
.acl-table td:first-child { font-weight: 500; }
.acl-module { background: #F4F6FB; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-soft); }
.acl-check { text-align: center; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .nav { display: flex; overflow-x: auto; padding: 0 8px 8px; }
  .nav-item span { display: none; }
  .sidebar-foot { border-top: 0; margin-left: auto; }
  .main { padding: 18px 14px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .ticket-layout { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* ---------- Disponibilidad de agentes ---------- */
.avail-wrap { padding: 10px 14px 0; }
.avail-toggle { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 12px; border-radius: 999px; border: 1px solid transparent; font: inherit; font-weight: 700;
  font-size: 12.5px; cursor: pointer; transition: filter 0.15s; }
.avail-toggle:hover { filter: brightness(1.1); }
.avail-toggle .avail-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px rgba(255,255,255,0.18); }
.avail-toggle.is-on { background: #16A34A; color: #fff; }
.avail-toggle.is-off { background: #DC2626; color: #fff; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-on { background: #16A34A; }
.dot-off { background: #DC2626; }

/* ---------- Chat IA ---------- */
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; }
.chat-log { flex: 1; overflow-y: auto; padding: 4px 2px 16px; }
.chat-msg { max-width: 78%; padding: 11px 14px; border-radius: 14px; margin-bottom: 10px; white-space: pre-wrap; line-height: 1.55; }
.chat-user { background: var(--brand); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.chat-ai { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-meta { font-size: 11px; color: var(--ink-soft); margin: 0 4px 4px; }
.chat-form { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 14px; }
.chat-form textarea { min-height: 52px; max-height: 140px; }
.ai-badge { display: inline-flex; align-items: center; gap: 6px; background: linear-gradient(135deg, var(--brand), #7C5CFF);
  color: #fff; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.ai-panel { border: 1px dashed color-mix(in srgb, var(--brand) 45%, transparent); background: color-mix(in srgb, var(--brand) 4%, #fff); }

/* ---------- Portal de servicios ---------- */
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.catalog-card { display: flex; gap: 14px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; color: var(--ink); position: relative; transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s; }
.catalog-card:hover { border-color: var(--brand); box-shadow: 0 4px 14px rgba(20,40,90,0.08); transform: translateY(-1px); }
.catalog-card.inactive { opacity: 0.55; }
.catalog-icon { font-size: 30px; line-height: 1; flex-shrink: 0; }
.catalog-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.catalog-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.catalog-admin { position: absolute; top: 10px; right: 10px; }
.form-hint-box { background: color-mix(in srgb, var(--brand) 6%, #fff); border: 1px dashed color-mix(in srgb, var(--brand) 40%, transparent);
  border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }

/* ---------- RFO / RCA ---------- */
.rfo-required { border-left: 4px solid var(--bad); }
.rfo-card dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-soft); font-weight: 700; margin-top: 12px; }
.rfo-card dd { margin: 4px 0 0; white-space: pre-wrap; }
