:root {
  --indigo: #4f46e5;
  --indigo-600: #4338ca;
  --indigo-50: #eef2ff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --ok: #10b981;
  --warn: #f59e0b;
  --crit: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all .15s ease;
  background: var(--surface); color: var(--ink); border-color: var(--line);
}
.btn:hover { background: #fafafa; }
.btn-primary { background: var(--indigo); color: #fff; border-color: var(--indigo); }
.btn-primary:hover { background: var(--indigo-600); }
.btn-block { width: 100%; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -200px, var(--indigo-50), transparent),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 40px 32px; text-align: center;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; margin-bottom: 22px;
}
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px; background: var(--indigo);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 16px;
  letter-spacing: .5px;
}
.brand-name { font-weight: 700; font-size: 16px; }
.login-title { font-size: 22px; font-weight: 700; margin: 8px 0 4px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 28px; }
.feishu-logo { width: 18px; height: 18px; }
.login-foot { margin-top: 22px; font-size: 12px; color: var(--muted); }

/* ---------- Shell ---------- */
.layout { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.sidebar {
  background: #0f1222; color: #cbd2e0; padding: 20px 14px; display: flex; flex-direction: column;
}
.sidebar .brand { color: #fff; margin: 4px 6px 24px; }
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: #6b7394; margin: 18px 10px 8px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
  color: #cbd2e0; font-size: 14px; font-weight: 500; cursor: pointer;
}
.nav-item:hover { background: #1a1f36; color: #fff; }
.nav-item.active { background: var(--indigo); color: #fff; }
.nav-spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 62px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.lang-toggle {
  display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.lang-toggle button {
  border: 0; background: #fff; padding: 6px 10px; font-size: 12px; cursor: pointer; color: var(--muted);
}
.lang-toggle button.active { background: var(--indigo-50); color: var(--indigo); font-weight: 700; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--indigo-50);
  display: grid; place-items: center; color: var(--indigo); font-weight: 700; font-size: 13px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-meta { line-height: 1.2; }
.user-meta .u-name { font-size: 13px; font-weight: 600; }
.user-meta .u-role { font-size: 11px; color: var(--muted); }

.content { padding: 28px 24px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.welcome-title { font-size: 20px; font-weight: 700; margin: 0 0 6px; }
.welcome-sub { color: var(--muted); margin: 0 0 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 14px; }
.stat {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: #fff;
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.badge { display:inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* Accesibilidad: foco visible */
:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ==================== Fase 3: vistas de tickets ==================== */
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.divider { height: 1px; background: var(--line); margin: 20px 0; }

/* Estado vacío */
.empty { text-align: center; padding: 40px 22px; }
.empty .btn { margin-top: 14px; }
.soon-badge {
  display: inline-block; background: var(--indigo-50); color: var(--indigo);
  font-weight: 700; font-size: 12px; padding: 6px 12px; border-radius: 999px; margin-bottom: 10px;
}

/* Tabla */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600; padding: 0 12px 10px; border-bottom: 1px solid var(--line);
}
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.row-click { cursor: pointer; }
.row-click:hover td { background: var(--indigo-50); }

/* Formulario */
.form-card { max-width: 760px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .req { color: var(--crit); }
.field .opt { color: var(--muted); font-weight: 400; font-size: 12px; }
.fld {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  font: inherit; font-size: 14px; background: #fff; color: var(--ink);
}
.fld:focus { border-color: var(--indigo); outline: none; box-shadow: 0 0 0 3px var(--indigo-50); }
textarea.fld { resize: vertical; }
select.fld { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.hint.inline { display: inline; margin-left: 6px; }
.hint.adj { background: #fafafa; border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; }
.chk-group { display: flex; flex-wrap: wrap; gap: 12px; }
.chk { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--indigo); }
.sel-hint { padding: 8px 0; }
.form-actions { margin-top: 8px; }
.form-msg { padding: 10px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; }
.form-msg.err { background: #fef2f2; color: var(--crit); border: 1px solid #fecaca; }

/* Detalle */
.back-link { display: inline-block; color: var(--indigo); font-size: 13px; font-weight: 600; margin-bottom: 14px; }
.detail-head { margin-bottom: 18px; }
.folio-big { color: var(--muted); }
.dt-title { font-size: 20px; font-weight: 700; margin: 4px 0 0; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 24px; }
.meta-row { min-width: 0; }
.meta-k { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.meta-v { font-size: 14px; word-break: break-word; }
.sect-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 12px; }
.desc { white-space: pre-wrap; margin: 0; font-size: 14px; line-height: 1.55; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 4px 0 14px; position: relative; font-size: 14px; }
.timeline li .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--indigo); margin-top: 4px; flex: none; }
.timeline li:not(:last-child) .dot::after {
  content: ''; position: absolute; left: 4px; top: 14px; bottom: 0; width: 2px; background: var(--line);
}

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ==================== Fase 4A: bandeja, gestión, comentarios ==================== */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filter-bar .fld { width: auto; min-width: 130px; flex: 0 1 auto; }
.filter-bar #fq { flex: 1 1 220px; min-width: 200px; }

.manage-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.manage-grid .field { margin-bottom: 0; }
@media (max-width: 720px) { .manage-grid { grid-template-columns: 1fr; } }

.hist-chg { color: var(--ink); font-weight: 600; }

/* Comentarios */
.com-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.com { display: flex; gap: 12px; }
.com-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--indigo-50); color: var(--indigo);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; overflow: hidden; flex: none;
}
.com-avatar img { width: 100%; height: 100%; object-fit: cover; }
.com-body { flex: 1; min-width: 0; }
.com-head { font-size: 13px; margin-bottom: 3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.com-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.com-internal .com-body {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 8px 12px;
}
.badge-int {
  background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .4px;
}
.com-form { margin-top: 6px; }
.com-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 12px; }

/* ==================== Fase 4B: adjuntos ==================== */
.adj-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.adj-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; color: var(--ink); }
.adj-item:hover { background: var(--indigo-50); border-color: var(--indigo); }
.adj-ic { flex: none; }
.adj-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adj-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.adj-input { font-size: 13px; max-width: 100%; }

/* ==================== Previsualización de adjuntos ==================== */
.adj-card { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.adj-side { width: 46px; display: grid; place-items: center; background: #fafafa; border: 0; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; text-decoration: none; }
.adj-side:hover { background: var(--indigo-50); color: var(--indigo); }
.adj-side.left { border-right: 1px solid var(--line); }
.adj-side.right { border-left: 1px solid var(--line); }
.adj-preview { flex: 1; display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-width: 0; cursor: pointer; }
.adj-thumb-img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #f3f4f6; flex: none; }
.adj-fileicon { width: 48px; height: 48px; border-radius: 8px; display: grid; place-items: center; background: var(--indigo-50); color: var(--indigo); font-weight: 700; font-size: 11px; flex: none; }
.adj-info { min-width: 0; }
.adj-info .n { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Lightbox */
.lb-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 24px; }
.lb-overlay.open { display: flex; }
.lb-box { background: #fff; border-radius: 12px; max-width: 94vw; max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.lb-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.lb-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.lb-close { background: none; border: 0; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; padding: 0 4px; }
.lb-close:hover { color: var(--ink); }
.lb-body { overflow: auto; display: flex; align-items: center; justify-content: center; background: #f3f4f6; }
.lb-body img { max-width: 90vw; max-height: 80vh; display: block; }
.lb-body iframe { width: 90vw; height: 82vh; border: 0; background: #fff; }
.lb-msg { padding: 48px; color: var(--muted); }
