/* ===================== KPI ===================== */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; background: var(--primary);
}
.kpi.accent::before { background: var(--accent); }
.kpi.ok::before { background: var(--ok); }
.kpi.warn::before { background: var(--warn); }
.kpi.high::before { background: var(--high); }
.kpi-label {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text-muted);
  font-weight: 600;
}
.kpi-value {
  font-size: 30px; font-weight: 700;
  margin-top: 6px; letter-spacing: -.5px;
}
.kpi-foot { font-size: 12px; color: var(--text-soft); margin-top: 4px; }

/* ===================== BUTTONS ===================== */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary:hover { background: #243072; }

/* ===================== TABLE ===================== */
table.assets {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.assets th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
}
table.assets th.center { text-align: center; }
table.assets td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.assets tr:hover td { background: #f9fafd; cursor: pointer; }
table.assets tr:last-child td { border-bottom: none; }
.code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
}
.name-cell { display: flex; flex-direction: column; gap: 2px; }
.name-main { font-weight: 600; color: var(--text); }
.name-sub { font-size: 12px; color: var(--text-muted); }

/* ===================== BADGES ===================== */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
}
.badge.type-D   { background: #eaf3fb; color: #0d4d80; }
.badge.type-S   { background: #ecf3ec; color: #1f5f2c; }
.badge.type-SW  { background: #efeaf9; color: #4a2997; }
.badge.type-HW  { background: #fdf0e1; color: #804000; }
.badge.type-COM { background: #e7f3f2; color: #0a5751; }
.badge.type-MED { background: #faecf2; color: #7a1e47; }
.badge.type-AUX { background: #f0f1f4; color: #3b4253; }
.badge.type-L   { background: #fdf6e0; color: #6c5113; }
.badge.type-P   { background: #fbe8eb; color: #861a2c; }

/* ===================== CITAD LEVELS ===================== */
.level {
  position: relative;
  display: inline-block;
  width: 26px; height: 22px;
  border-radius: 5px;
  text-align: center;
  line-height: 22px;
  font-size: 11px;
  font-weight: 700;
}
.level.A  { background: var(--high-soft); color: var(--high); }
.level.M  { background: var(--warn-soft); color: var(--warn); }
.level.B  { background: var(--ok-soft); color: var(--ok); }
.level.NA { background: #f0f1f4; color: var(--text-soft); }

.citad {
  display: inline-grid;
  grid-template-columns: repeat(5, 26px);
  gap: 3px;
}

/* Cabecera CITAD: cajas del mismo tamaño que los .level para alineación exacta */
.citad-head {
  display: inline-grid;
  grid-template-columns: repeat(5, 26px);
  gap: 3px;
}
.citad-hdr {
  position: relative;
  display: inline-block;
  width: 26px; height: 22px;
  border-radius: 5px;
  text-align: center;
  line-height: 22px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: default;
}

/* ===================== TOOLTIPS ===================== */
.has-tip { position: relative; }

.has-tip[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1f36;
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  padding: 5px 9px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 200;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.4;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.has-tip[data-tip]:hover::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1a1f36;
  pointer-events: none;
  z-index: 200;
}

/* ===================== CATEGORY PILLS ===================== */
.cat-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.cat-pill.alta  { background: var(--high-soft); color: var(--high); }
.cat-pill.media { background: var(--warn-soft); color: var(--warn); }
.cat-pill.baja  { background: var(--ok-soft); color: var(--ok); }

/* ===================== DETAIL DRAWER ===================== */
.drawer-mask {
  position: fixed; inset: 0;
  background: rgba(20, 25, 50, .35);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  z-index: 50;
}
.drawer-mask.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 560px; max-width: 92vw;
  background: var(--surface);
  box-shadow: -4px 0 30px rgba(20, 25, 50, .15);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 51;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px;
}
.drawer-head h3 { margin: 4px 0 0; font-size: 17px; }
.drawer-head .x {
  border: none; background: transparent; font-size: 22px;
  cursor: pointer; color: var(--text-soft); line-height: 1;
}
.drawer-body { padding: 20px 28px 40px; overflow-y: auto; flex: 1; }
.drawer-body h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); margin: 22px 0 10px;
}
.drawer-body h4:first-child { margin-top: 0; }

.field {
  display: grid; grid-template-columns: 140px 1fr;
  padding: 8px 0; border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.field:last-child { border-bottom: none; }
.field .k { color: var(--text-muted); }
.field .v { color: var(--text); font-weight: 500; }

/* CITAD grid del drawer — cajas propias, sin depender de .level */
.citad-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  background: var(--surface-2);
  padding: 14px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.citad-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.citad-letter {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .5px;
}
.citad-val {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 38px;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 800;
}
.citad-val.A  { background: var(--high-soft); color: var(--high); }
.citad-val.M  { background: var(--warn-soft); color: var(--warn); }
.citad-val.B  { background: var(--ok-soft);   color: var(--ok);   }
.citad-val.NA { background: #f0f1f4; color: var(--text-soft); font-size: 11px; }
.citad-name {
  font-size: 10px;
  color: var(--text-soft);
  text-align: center;
  line-height: 1.3;
}

ul.deps { list-style: none; padding: 0; margin: 0; }
ul.deps li {
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
  display: flex; justify-content: space-between; align-items: center;
}

.notes-box {
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

/* ===================== TRAZABILIDAD / HISTORIAL ===================== */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.btn-add-entry {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(45, 58, 140, .2);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
}
.btn-add-entry:hover { background: #dde2f5; }

/* Formulario de nueva entrada */
.history-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.hform-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.hform-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.hform-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s;
}
.hform-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.hform-textarea {
  height: 72px;
  resize: vertical;
  margin-top: 0;
}
.hform-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.btn-save-entry {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 7px 16px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-save-entry:hover { background: #243072; }
.btn-cancel-entry {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.btn-cancel-entry:hover { background: var(--surface-2); }

/* Timeline */
.history-timeline {
  position: relative;
  padding-left: 18px;
}
.history-timeline::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
  border-radius: 2px;
}
.history-entry {
  position: relative;
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.history-entry:last-child { margin-bottom: 0; }
.history-dot {
  position: absolute;
  left: -18px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
  flex-shrink: 0;
}
.history-content { flex: 1; min-width: 0; }
.history-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 5px;
}
.history-date {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.history-type-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  white-space: nowrap;
}
.history-author {
  font-size: 11px;
  color: var(--text-muted);
}
.history-desc {
  font-size: 12px;
  color: var(--text);
  line-height: 1.55;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
}
.history-empty {
  color: var(--text-soft);
  font-size: 13px;
  padding: 16px 0;
  text-align: center;
}
